44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
import os, logging, argparse
|
|
from glob import glob
|
|
import archive.archive as archive
|
|
import config
|
|
import terminal.util as util
|
|
|
|
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, file=None):
|
|
logging.debug("indexing: " + str(lists) + " from " + archives)
|
|
lists_db = archive.list_tables_db_config(config.db)
|
|
|
|
for a in lists:
|
|
ar = archive.Archive(a, archives)
|
|
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
|
|
ar.insert_db(config.db, file=file)
|
|
|
|
if __name__ == "__main__":
|
|
|
|
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('--file', metavar="file", help="archive file to index")
|
|
p.add_argument('--archives', '-a', help="path to archives directory (default='archives')", default=config.archives)
|
|
|
|
args = p.parse_args()
|
|
|
|
if not args.archives:
|
|
args.archives = config.archives
|
|
|
|
if len(args.list) == 1 and args.list[0] == "all":
|
|
args.list = list_archives(args.archives)
|
|
|
|
run(args.list, args.archives, args.file)
|
|
|
|
|