listservs/index.py

43 lines
1.2 KiB
Python
Raw Normal View History

2019-12-21 15:58:22 +01:00
import os, logging, argparse
from glob import glob
import archive.archive as archive
import config
2019-12-22 14:40:23 +01:00
import terminal.util as util
2019-12-21 15:58:22 +01:00
logging.basicConfig(level=logging.DEBUG)
def list_archives(archives_dir):
return [d for d in os.listdir(archives_dir) if os.path.isdir(os.path.join(archives_dir, d))]
def run(lists, archives):
logging.debug("indexing: " + str(lists) + " from " + archives)
2019-12-22 14:40:23 +01:00
lists_db = archive.list_tables_db_config(config.db)
2019-12-21 15:58:22 +01:00
2019-12-22 08:21:55 +01:00
for a in lists:
ar = archive.Archive(a, archives)
2019-12-22 14:40:23 +01:00
if a not in lists_db:
if util.y_n_question("Archive " + a + " db table does not exist. Create it?"):
ar.create_db(config.db)
else:
logging.info("Table not created. Aborting.")
return
2019-12-22 08:21:55 +01:00
ar.insert_db(config.db)
2019-12-21 15:58:22 +01:00
if __name__ == "__main__":
2019-12-22 14:40:23 +01:00
p = argparse.ArgumentParser(description='Mailinglists are dead. Long live mailinglists!')
p.add_argument('list', metavar="list", help="list(s) to index", nargs="+")
p.add_argument('--archives', '-a', help="path to archives directory (default='archives')", default=config.archives)
2019-12-21 15:58:22 +01:00
2019-12-22 14:40:23 +01:00
args = p.parse_args()
2019-12-21 15:58:22 +01:00
2019-12-22 14:40:23 +01:00
if not args.archives:
args.archives = config.archives
2019-12-21 15:58:22 +01:00
2019-12-22 14:40:23 +01:00
if len(args.list) == 1 and args.list[0] == "all":
args.list = list_archives(args.archives)
2019-12-21 15:58:22 +01:00
2019-12-22 14:40:23 +01:00
run(args.list, args.archives)
2019-12-21 15:58:22 +01:00