def main(): """Parses command line arguments, displays errors from tvnamer in terminal """ opter = OptionParser() opter.add_option( "-c", "--config", dest="config", help = "Override the config file path") opter.add_option( "-s", "--save", dest="saveconfig", help = "Save (default) config to file") opter.add_option( "-v", "--verbose", default=False, dest="verbose", action="store_true", help="show debugging information") opter.add_option( "-r", "--recursive", default = False, dest="recursive", action="store_true", help="Descend more than one level directories supplied as arguments") opter.add_option( "-a", "--always", default = False, dest="alwaysrename", action="store_true", help="always renames files (but still prompts for correct series). Can be set at runtime with the 'a' prompt-option") opter.add_option( "-f", "--selectfirst", default = False, dest="selectfirst", action="store_true", help="select first series search result (instead of showing the select-series interface") opter.add_option( "-b", "--batch", default = False, dest="batch", action="store_true", help="rename without human intervention, selects first series and always renames, same as --always and --selectfirst") opts, args = opter.parse_args() if opts.config is not None: print "Loading config from: %s" % (opts.config) try: Config.loadConfig(opts.config) except InvalidConfigFile: warn("Invalid config file %s - using default configuration" % ( opts.config)) Config.useDefaultConfig() if opts.saveconfig is not None: print "Saving current config to %s" % (opts.saveconfig) try: Config.saveConfig(opts.saveconfig) except InvalidConfigFile: opter.error("Could not save config to %s" % opts.saveconfig) else: print "Done, exiting" opter.exit(0) if opts.batch: opts.selectfirst = True opts.alwaysrename = True if not Config['verbose']: Config['verbose'] = opts.verbose if not Config['recursive']: Config['recursive'] = opts.recursive if not Config['alwaysrename']: Config['alwaysrename'] = opts.alwaysrename if not Config['selectfirst']: Config['selectfirst'] = opts.selectfirst if len(args) == 0: opter.error("No filenames or directories supplied") try: tvnamer(paths = sorted(args)) except NoValidFilesFoundError: opter.error("No valid files were supplied") except UserAbort, errormsg: opter.error(errormsg)