def main(argv): """ Main routine for the command-line interface to audfprint """ # Other globals set from command line args = docopt.docopt(USAGE, version=__version__, argv=argv[1:]) # Figure which command was chosen poss_cmds = [ 'new', 'add', 'precompute', 'merge', 'newmerge', 'match', 'list', 'remove' ] cmdlist = [cmdname for cmdname in poss_cmds if args[cmdname]] if len(cmdlist) != 1: raise ValueError("must specify exactly one command") # The actual command as a str cmd = cmdlist[0] # Setup output function report = setup_reporter(args) # Keep track of wall time initticks = time.clock() # Command line sanity. if args["--maxtimebits"]: args["--maxtimebits"] = int(args["--maxtimebits"]) else: args["--maxtimebits"] = hash_table._bitsfor(int(args["--maxtime"])) # Setup the analyzer if we're using one (i.e., unless "merge") analyzer = setup_analyzer(args) if not (cmd is "merge" or cmd is "newmerge" or cmd is "list" or cmd is "remove") else None precomp_type = 'hashes' # Set up the hash table, if we're using one (i.e., unless "precompute") if cmd is not "precompute": # For everything other than precompute, we need a database name # Check we have one dbasename = args['--dbase'] if not dbasename: raise ValueError("dbase name must be provided if not precompute") if cmd == "new" or cmd == "newmerge": # Check that the output directory can be created before we start ensure_dir(os.path.split(dbasename)[0]) # Create a new hash table hash_tab = hash_table.HashTable( hashbits=int(args['--hashbits']), depth=int(args['--bucketsize']), maxtime=(1 << int(args['--maxtimebits']))) # Set its samplerate param if analyzer: hash_tab.params['samplerate'] = analyzer.target_sr else: # Load existing hash table file (add, match, merge) if args['--verbose']: report([time.ctime() + " Reading hash table " + dbasename]) hash_tab = hash_table.HashTable(dbasename) if analyzer and 'samplerate' in hash_tab.params \ and hash_tab.params['samplerate'] != analyzer.target_sr: # analyzer.target_sr = hash_tab.params['samplerate'] print("db samplerate overridden to ", analyzer.target_sr) else: # The command IS precompute # dummy empty hash table hash_tab = None if args['--precompute-peaks']: precomp_type = 'peaks' # Create a matcher matcher = setup_matcher(args) if cmd == 'match' else None filename_iter = filename_list_iterator(args['<file>'], args['--wavdir'], args['--wavext'], args['--list']) ####################### # Run the main commmand ####################### # How many processors to use (multiprocessing) ncores = int(args['--ncores']) if ncores > 1 and not (cmd == "merge" or cmd == "newmerge" or cmd == "list" or cmd == "remove"): # merge/newmerge/list/remove are always single-thread processes do_cmd_multiproc(cmd, analyzer, hash_tab, filename_iter, matcher, args['--precompdir'], precomp_type, report, skip_existing=args['--skip-existing'], ncores=ncores) else: do_cmd(cmd, analyzer, hash_tab, filename_iter, matcher, args['--precompdir'], precomp_type, report, skip_existing=args['--skip-existing']) elapsedtime = time.clock() - initticks if analyzer and analyzer.soundfiletotaldur > 0.: print("Processed " + "%d files (%.1f s total dur) in %.1f s sec = %.3f x RT" \ % (analyzer.soundfilecount, analyzer.soundfiletotaldur, elapsedtime, (elapsedtime/analyzer.soundfiletotaldur))) # Save the hash table file if it has been modified if hash_tab and hash_tab.dirty: # We already created the directory, if "new". hash_tab.save(dbasename)
def main(argv): """ Main routine for the command-line interface to audfprint """ # Other globals set from command line args = docopt.docopt(USAGE, version=__version__, argv=argv[1:]) # Figure which command was chosen poss_cmds = ['new', 'add', 'precompute', 'merge', 'newmerge', 'match', 'list', 'remove'] cmdlist = [cmdname for cmdname in poss_cmds if args[cmdname]] if len(cmdlist) != 1: raise ValueError("must specify exactly one command") # The actual command as a str cmd = cmdlist[0] # Setup output function report = setup_reporter(args) # Keep track of wall time initticks = time.clock() # Command line sanity. if args["--maxtimebits"]: args["--maxtimebits"] = int(args["--maxtimebits"]) else: args["--maxtimebits"] = hash_table._bitsfor(int(args["--maxtime"])) # Setup the analyzer if we're using one (i.e., unless "merge") analyzer = setup_analyzer(args) if not ( cmd is "merge" or cmd is "newmerge" or cmd is "list" or cmd is "remove") else None precomp_type = 'hashes' # Set up the hash table, if we're using one (i.e., unless "precompute") if cmd is not "precompute": # For everything other than precompute, we need a database name # Check we have one dbasename = args['--dbase'] if not dbasename: raise ValueError("dbase name must be provided if not precompute") if cmd == "new" or cmd == "newmerge": # Check that the output directory can be created before we start ensure_dir(os.path.split(dbasename)[0]) # Create a new hash table hash_tab = hash_table.HashTable( hashbits=int(args['--hashbits']), depth=int(args['--bucketsize']), maxtime=(1 << int(args['--maxtimebits']))) # Set its samplerate param if analyzer: hash_tab.params['samplerate'] = analyzer.target_sr else: # Load existing hash table file (add, match, merge) if args['--verbose']: report([time.ctime() + " Reading hash table " + dbasename]) hash_tab = hash_table.HashTable(dbasename) if analyzer and 'samplerate' in hash_tab.params \ and hash_tab.params['samplerate'] != analyzer.target_sr: # analyzer.target_sr = hash_tab.params['samplerate'] print("db samplerate overridden to ", analyzer.target_sr) else: # The command IS precompute # dummy empty hash table hash_tab = None if args['--precompute-peaks']: precomp_type = 'peaks' # Create a matcher matcher = setup_matcher(args) if cmd == 'match' else None filename_iter = filename_list_iterator( args['<file>'], args['--wavdir'], args['--wavext'], args['--list']) ####################### # Run the main commmand ####################### # How many processors to use (multiprocessing) ncores = int(args['--ncores']) if ncores > 1 and not (cmd == "merge" or cmd == "newmerge" or cmd == "list" or cmd == "remove"): # merge/newmerge/list/remove are always single-thread processes do_cmd_multiproc(cmd, analyzer, hash_tab, filename_iter, matcher, args['--precompdir'], precomp_type, report, skip_existing=args['--skip-existing'], ncores=ncores) else: do_cmd(cmd, analyzer, hash_tab, filename_iter, matcher, args['--precompdir'], precomp_type, report, skip_existing=args['--skip-existing']) elapsedtime = time.clock() - initticks if analyzer and analyzer.soundfiletotaldur > 0.: print("Processed " + "%d files (%.1f s total dur) in %.1f s sec = %.3f x RT" \ % (analyzer.soundfilecount, analyzer.soundfiletotaldur, elapsedtime, (elapsedtime/analyzer.soundfiletotaldur))) # Save the hash table file if it has been modified if hash_tab and hash_tab.dirty: # We already created the directory, if "new". hash_tab.save(dbasename)