2 from __future__ import print_function
7 from m_librarian.config import get_config
8 from m_librarian.db import open_db, init_db, update_counters
9 from m_librarian.glst import import_glst
10 from m_librarian.inp import import_inpx
11 from m_librarian.pbar import ttyProgressBar
13 from m_librarian.pbar import ml_ttyProgressBar
15 if __name__ == '__main__':
16 parser = argparse.ArgumentParser(description='Import')
17 parser.add_argument('-C', '--config', help='configuration file')
18 parser.add_argument('-D', '--database', help='database URI')
19 parser.add_argument('-P', '--no-pbar', action='store_true',
20 help='inhibit progress bar')
21 parser.add_argument('inpx', nargs='+', help='INPX files to import')
22 args = parser.parse_args()
25 get_config(args.config) # Get and cache config file
27 open_db(args.database)
30 count_old, count_new = import_glst()
32 print("Imported %d genres (ignored %d existing)" % (
33 count_new, count_old))
35 print("Imported %d genres" % count_new)
37 use_pbar = ttyProgressBar and not args.no_pbar and sys.stdout.isatty()
38 for inpx in args.inpx:
41 pbar_fname = inpx[:22] + '...'
44 print(pbar_fname.ljust(20), end=': ')
46 pbar = ml_ttyProgressBar()
47 import_inpx(inpx, pbar_cb=pbar)
52 print("Updating counters", end=': ')
54 pbar = ml_ttyProgressBar()
55 update_counters(pbar_cb=pbar)