我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用docopt.docopt()。
def __init__(self, home_dir=os.path.join(os.path.expanduser(path='~'), '.poco'), argv=sys.argv[1:]): """Fill state""" StateHolder.home_dir = home_dir StateHolder.config_file = os.path.join(StateHolder.home_dir, 'config') StateHolder.args = docopt(__doc__, version=__version__, argv=argv) ColorPrint.set_log_level(StateHolder.args) if StateHolder.args.get('<project>') is None: StateHolder.args['<project>'] = FileUtils.get_directory_name() StateHolder.name = StateHolder.args.get('<project>') StateHolder.offline = StateHolder.args.get("--offline") if StateHolder.args.get("--developer"): StateHolder.developer_mode = StateHolder.args.get("--developer") self.config_handler = ConfigHandler() """Parse config if exists """ if ConfigHandler.exists(): self.config_handler.read() else: StateHolder.work_dir = os.getcwd() StateHolder.developer_mode = True
def main(): args = docopt(""" Usage: analogy_eval.py [options] <representation> <representation_path> <task_path> Options: --neg NUM Number of negative samples; subtracts its log from PMI (only applicable to PPMI) [default: 1] --w+c Use ensemble of word and context vectors (not applicable to PPMI) --eig NUM Weighted exponent of the eigenvalue matrix (only applicable to SVD) [default: 0.5] """) data = read_test_set(args['<task_path>']) xi, ix = get_vocab(data) representation = create_representation(args) accuracy_add, accuracy_mul = evaluate(representation, data, xi, ix) print args['<representation>'], args['<representation_path>'], '\t%0.3f' % accuracy_add, '\t%0.3f' % accuracy_mul
def main(): args = docopt(""" Usage: text2numpy.py <path> """) path = args['<path>'] matrix = read_vectors(path) iw = sorted(matrix.keys()) new_matrix = np.zeros(shape=(len(iw), len(matrix[iw[0]])), dtype=np.float32) for i, word in enumerate(iw): if word in matrix: new_matrix[i, :] = matrix[word] np.save(path + '.npy', new_matrix) save_vocabulary(path + '.vocab', iw)
def main(): args = docopt(""" Usage: pmi2svd.py [options] <pmi_path> <output_path> Options: --dim NUM Dimensionality of eigenvectors [default: 500] --neg NUM Number of negative samples; subtracts its log from PMI [default: 1] """) pmi_path = args['<pmi_path>'] output_path = args['<output_path>'] dim = int(args['--dim']) neg = int(args['--neg']) explicit = PositiveExplicit(pmi_path, normalize=False, neg=neg) ut, s, vt = sparsesvd(explicit.m.tocsc(), dim) np.save(output_path + '.ut.npy', ut) np.save(output_path + '.s.npy', s) np.save(output_path + '.vt.npy', vt) save_vocabulary(output_path + '.words.vocab', explicit.iw) save_vocabulary(output_path + '.contexts.vocab', explicit.ic)
def main(): args = docopt(""" Usage: sgns2text.py [options] <sgns_path> <output_path> Options: --w+c Use ensemble of word and context vectors """) sgns_path = args['<sgns_path>'] output_path = args['<output_path>'] w_c = args['--w+c'] if w_c: sgns = EnsembleEmbedding(Embedding(sgns_path + '.words', False), Embedding(sgns_path + '.contexts', False), True) else: sgns = Embedding(sgns_path + '.words', True) with open(output_path, 'w') as f: for i, w in enumerate(sgns.iw): print >>f, w, ' '.join([str(x) for x in sgns.m[i]])
def main(): args = docopt(""" Usage: counts2pmi.py [options] <counts> <output_path> Options: --cds NUM Context distribution smoothing [default: 1.0] """) counts_path = args['<counts>'] vectors_path = args['<output_path>'] cds = float(args['--cds']) counts, iw, ic = read_counts_matrix(counts_path) pmi = calc_pmi(counts, cds) save_matrix(vectors_path, pmi) save_vocabulary(vectors_path + '.words.vocab', iw) save_vocabulary(vectors_path + '.contexts.vocab', ic)
def main(): args = docopt(""" Usage: counts2pmi.py <counts> """) counts_path = args['<counts>'] words = Counter() contexts = Counter() with open(counts_path) as f: for line in f: count, word, context = line.strip().split() count = int(count) words[word] += count contexts[context] += count words = sorted(words.items(), key=lambda (x, y): y, reverse=True) contexts = sorted(contexts.items(), key=lambda (x, y): y, reverse=True) save_count_vocabulary(counts_path + '.words.vocab', words) save_count_vocabulary(counts_path + '.contexts.vocab', contexts)
def main(): args = docopt(""" Usage: svd2text.py [options] <svd_path> <output_path> Options: --w+c Use ensemble of word and context vectors --eig NUM Weighted exponent of the eigenvalue matrix [default: 0.5] """) svd_path = args['<svd_path>'] output_path = args['<output_path>'] w_c = args['--w+c'] eig = float(args['--eig']) if w_c: svd = EnsembleEmbedding(SVDEmbedding(svd_path, False, eig, False), SVDEmbedding(svd_path, False, eig, True), True) else: svd = SVDEmbedding(svd_path, True, eig) with open(output_path, 'w') as f: for i, w in enumerate(svd.iw): print >>f, w, ' '.join([str(x) for x in svd.m[i]])
def main(argv=None): args = docopt(__doc__, argv=argv, version='1.0.3') assert 'config.toml' in (p.name for p in Path().iterdir()), "config.toml not found in directory. Are you sure you're in the project's root?" if args['--init']: notebooks_dir = Path('./notebooks/') notebooks_dir.mkdir(exist_ok=True) with open(resource_filename('hugo_jupyter', '__fabfile.py')) as fp: fabfile = Path('fabfile.py') fabfile.write_text(fp.read()) print(dedent(""" Successfully initialized. From this directory, the following commands are available. Just remember to prepend them with `fab` """)) run(('fab', '-l'))
def main(): """Run the release.""" options = docopt(HELP) for index, step in enumerate([ensure_not_dirty, ensure_master, git_pull, ensure_passing_tests, bump_mdk_versions, ]): print("Step {}: {}".format(index + 1, step.__name__)) step(options) print("""\ The release has been committed and tagged locally. You can now push it upstream by running: git push origin master --tags """)
def main(): # run <shape_start> <shape_end> [<iters>][<decimals>] arguments = docopt(__doc__, version='Same Stats 1.0') if arguments['run']: with plot_settings(): it = 100000 de = 2 frames = 100 if arguments['<iters>']: it = int(arguments['<iters>']) if arguments['<decimals>']: de = int(arguments['<decimals>']) if arguments['<decimals>']: frames = int(arguments['<frames>']) shape_start = arguments['<shape_start>'] shape_end = arguments['<shape_end>'] if shape_start in INITIAL_DATASETS and shape_end in ALL_TARGETS: do_single_run(shape_start, shape_end, iterations=it, decimals=de, num_frames=frames) else: print("************* One of those shapes isn't correct:") print("shape_start must be one of ", INITIAL_DATASETS) print("shape_end must be one of ", ALL_TARGETS)
def command(): arguments = docopt(__doc__) #print(arguments) from_sta = stations.get(arguments['<from>']) to_sta = stations.get(arguments['<to>']) date = arguments['<date>'] url = 'https://kyfw.12306.cn/otn/leftTicket/query?leftTicketDTO.train_date={}&leftTicketDTO.from_station={}&leftTicketDTO.to_station={}&purpose_codes=ADULT'.format(date, from_sta, to_sta) resp = requests.get(url, verify=False) #print(resp.json()) options = ''.join([ key for key, value in arguments.items() if value is True ]) available_trains = resp.json()['data'] TrainsResult(available_trains, options).pretty_print()
def __init__(self, docstring=None): if docstring is not None: self.options = docopt.docopt(docstring) else: self.options = {} self.umap_class_dict = { 'audio': ('audio', 'Headset'), 'billboard': ('billboard', 'A billboard, requires USB 2.1 and higher'), 'cdc_acm': ('cdc_acm', 'Abstract Control Model device (like serial modem)'), 'cdc_dl': ('cdc_dl', 'Direct Line Control device (like modem)'), 'ftdi': ('ftdi', 'USB<->RS232 FTDI chip'), 'hub': ('hub', 'USB hub'), 'keyboard': ('keyboard', 'Keyboard'), 'mass_storage': ('mass_storage', 'Disk on key'), 'mtp': ('mtp', 'Android phone'), 'printer': ('printer', 'Printer'), 'smartcard': ('smartcard', 'USB<->smart card interface'), } self.umap_classes = sorted(self.umap_class_dict.keys()) self.logger = self.get_logger() self.num_processed = 0 self.fuzzer = None self.setup_packet_received = False
def main(): # type: () -> typing.Any """Parse the command line options and launch the requested command. If the command is 'help' then print the help message for the subcommand; if no subcommand is given, print the standard help message. """ colorama.init(wrap=six.PY3) doc = usage.get_primary_command_usage() allow_subcommands = '<command>' in doc args = docopt(doc, version=settings.version, options_first=allow_subcommands) if sys.excepthook is sys.__excepthook__: sys.excepthook = log.excepthook try: log.enable_logging(log.get_log_level(args)) default_args = sys.argv[2 if args.get('<command>') else 1:] if (args.get('<command>') == 'help' and None not in settings.subcommands): subcommand = next(iter(args.get('<args>', default_args)), None) return usage.get_help_usage(subcommand) argv = [args.get('<command>')] + args.get('<args>', default_args) return _run_command(argv) except exc.InvalidCliValueError as e: return str(e)
def _run_command(argv): # type: (typing.List[str]) -> typing.Any """Run the command with the given CLI options and exit. Command functions are expected to have a __doc__ string that is parseable by docopt. Args: argv: The list of command line arguments supplied for a command. The first argument is expected to be the name of the command to be run. Note that this is different than the full arguments parsed by docopt for the entire program. Raises: ValueError: Raised if the user attempted to run an invalid command. """ command_name, argv = _get_command_and_argv(argv) _LOGGER.info('Running command "%s %s" with args: %s', settings.command, command_name, argv) subcommand = _get_subcommand(command_name) func = call.get_callable(subcommand) doc = usage.format_usage(subcommand.__doc__) args = _get_parsed_args(command_name, doc, argv) return call.call(func, args) or 0
def _get_command_and_argv(argv): # type: (typing.List[str]) -> typing.Tuple[str, typing.List[str]] """Extract the command name and arguments to pass to docopt. Args: argv: The argument list being used to run the command. Returns: A tuple containing the name of the command and the arguments to pass to docopt. """ command_name = argv[0] if not command_name: argv = argv[1:] elif command_name == settings.command: argv.remove(command_name) return command_name, argv
def _get_parsed_args(command_name, doc, argv): # type: (str, str, typing.List[str]) -> typing.Dict[str, typing.Any] """Parse the docstring with docopt. Args: command_name: The name of the subcommand to parse. doc: A docopt-parseable string. argv: The list of arguments to pass to docopt during parsing. Returns: The docopt results dictionary. If the subcommand has the same name as the primary command, the subcommand value will be added to the dictionary. """ _LOGGER.debug('Parsing docstring: """%s""" with arguments %s.', doc, argv) args = docopt(doc, argv=argv) if command_name == settings.command: args[command_name] = True return args
def main(): arguments = docopt(__doc__, version='BIC clustering') db_yml = expanduser(arguments['--database']) protocol_name = arguments['<database.task.protocol>'] subset = arguments['--subset'] if arguments['tune']: experiment_dir = arguments['<experiment_dir>'] if subset is None: subset = 'development' application = BICClustering(experiment_dir, db_yml=db_yml) application.tune(protocol_name, subset=subset) # if arguments['apply']: # tune_dir = arguments['<tune_dir>'] # if subset is None: # subset = 'test' # application = BICClustering.from_tune_dir( # tune_dir, db_yml=db_yml) # application.apply(protocol_name, subset=subset)
def cmd(): try: main(docopt(__doc__, version=__version__)) except ImportError as e: # lxml or html5lib not found print(e.msg) print('After installing one of them, please try again by using `mpsign update [user]`') except UserNotFound as e: print('User not found.') except InvalidBDUSSException as e: raise e print('BDUSS not valid') except KeyboardInterrupt: print('Operation cancelled by user.') except Exception as e: raise e db.close()
def cli(): """command-line interface""" args = docopt(__doc__) if args["-q"] == True: pprint_user_ask(args["<user>"], int(args["--depth"])) elif args["-r"] == True: pprint_user_answer(args["<user>"], int(args["--depth"])) elif args["-a"] == True: pprint_user_article(args["<user>"], int(args["--depth"])) elif args["post"] == True: pprint_post(args['<url>']) elif args["question"] == True: pprint_question(args['<url>']) elif args["column"] == True: pprint_column(args['<url>']) elif args["answer"] == True: pprint_answer(args['<url>']) elif args["collection"] == True: pprint_collection(args['<url>']) else: pprint_user_base(args['<user>'])
def _main(): print('kitty version: %s' % get_distribution('kittyfuzzer').version) opts = docopt.docopt(__doc__) files = opts['<FILE>'] fast = opts['--fast'] verbose = opts['--verbose'] if opts['--tree']: processor = TemplateTreePrinter() else: processor = TemplateTester(fast) processor.verbose = verbose try: validate_files(files) for f in files: process_file(f, processor) except Exception as e: print(e)
def main(argv=None): arguments = docopt(__doc__) inputfilename = arguments["INPUT"] if not inputfilename.endswith('.tcx'): print ("input file %s has no .tcx extention" % inputfilename) exit(-1) if arguments['--lever']: lever = int(arguments['--lever']) assert (lever > 0 and lever <11) sys.stderr.write('Handlebar resistance lever position = %d \n' % lever) sys.stderr.flush() else: lever = 5 sys.stderr.write('Assuming default handlebar resistance lever postion at 5\n') sys.stderr.flush() process_file(inputfilename, lever)
def cli(): """Command-line interface""" arguments = docopt(__doc__) from_station = stations.get(arguments['<from>']) to_station = stations.get(arguments['<to>']) date = arguments['<date>'] url = ('https://kyfw.12306.cn/otn/leftTicket/query?' 'leftTicketDTO.train_date={}&' 'leftTicketDTO.from_station={}&leftTicketDTO.to_station={}&purpose_codes=ADULT').format( date, from_station, to_station ) options = ''.join([ key for key, value in arguments.items() if value is True ]) r = requests.get(url, verify=False) res = r.json() if 'data' in res.keys(): available_trains = res['data'] TrainsCollection(available_trains, options).pretty_print() else: print('????')
def _process_cmd_line(argv): """Memory graph diffing. Usage: graph_diffing.py [--verbose] <dump>... [-n <neg_dump>] graph_diffing.py (--help | --version) Options: <dump> The list of positive memory dumps. -n <neg_dump> The negative memory dump. -h --help Shows this message. -v --verbose Shows details. --version Shows the current version. """ # initializing the parser object args = docopt(_process_cmd_line.__doc__, argv=argv, version=__version__) # checking arguments if args['--verbose']: print(args) return args['<dump>'], args['-n'], args['--verbose']
def _process_cmd_line(argv): '''Minidump parser. By David I. Urbina based on Brendan Dolan-Gavitt 'minidump.py' parser. Usage: minidump.py <minidump> minidump.py (-h | --help | --version) Options: <minidump> The minidump file. -h --help Shows this help. --version Shows the current version. ''' # initializing the parser object args = docopt(_process_cmd_line.__doc__, argv=argv, version=__version__) return args['<minidump>']
def _process_cmd_line(argv): '''Minidump converter. Usage: minidump_convert.py [options] <dump> minidump_convert.py (-h | --help | --version) Options: <dump> The minidump file. -m Extract non-standard modules. -M Extract all modules. -s Extract segments. -c Extract core. -v --verbose Verbose. -h --help Shows this help. --version Shows the current version. ''' # initializing the parser object args = docopt(_process_cmd_line.__doc__, argv=argv, version=__version__) return (args['<dump>'], args['-m'], args['-M'], args['-s'], args['-c'], args['--verbose'])
def _process_cmd_line(argv): """Memory graph generator. Usage: graph_generator.py [--verbose] <dump> graph_generator.py (--help | --version) Options: <dump> The memory dump file. -h --help Shows this message. -v --verbose Shows details. --version Shows the current version. """ # initializing the parser object args = docopt(_process_cmd_line.__doc__, argv=argv, version=__version__) # checking arguments if args['--verbose']: print(args) return args['<dump>'], args['--verbose']
def main(): """Translating KITTI data into RecordIO""" arguments = docopt.docopt(__doc__) data_root = arguments['--data'] out_root = arguments['--out'] X_train, Y_train = grab_images_labels(data_root, 'train') X_val, Y_val = grab_images_labels(data_root, 'val') train_writer = Writer(os.path.join(out_root, 'train.brick')) train_writer.write(X_train, Y_train) train_writer.close() print(' * Finished writing train.') val_writer = Writer(os.path.join(out_root, 'val.brick')) val_writer.write(X_val, Y_val) val_writer.close() print(' * Finished writing val.')
def query_by_command(self): """command-line interface""" arguments = docopt(__doc__) from stations import stations from_station = stations.get(arguments['<from>']) to_station = stations.get(arguments['<to>']) train_type = [] all_train_type = ['-d', '-g', '-t', '-k', '-z'] for key in all_train_type: if arguments[key]: train_type.append(key[1:].upper()) if len(train_type) == 0: train_type = [x[1:].upper() for x in all_train_type] date = arguments['<date>'] # ??URL url = 'https://kyfw.12306.cn/otn/lcxxcx/query?purpose_codes=ADULT&queryDate={}&from_station={}&to_station={}'.format(date,from_station, to_station) import requests requests.packages.urllib3.disable_warnings() r = requests.get(url, verify = False) rows = r.json()['data']['datas'] from ticketSearch import TrainCollection t = TrainCollection(rows, train_type) t.print_pretty()
def parse_arguments(self): self.arguments = docopt(__doc__) self.parguments = self.get_provided_arguments() if not self.parguments: format_help(__doc__, None) exit(0) elif '--version' in self.parguments: print(__version__) exit(0) elif '--get-list' in self.parguments: [print(module) for module in list_wg_modules()] exit(0) elif '--list' in self.parguments or '--search' in self.parguments: if '--target' in self.parguments: self.we_get_run = 1 if self.we_get_run != 1: format_help(__doc__, "Use --search/--list with --target.") exit(1)
def main(): opts = docopt.docopt(__doc__) radius = float(opts['<RADIUS>']) nlines = int(opts['<NUM_LINES>'], 0) npoints = int(opts['<NUM_POINTS>'], 0) outfilename = opts['<OUTFILE>'] if not outfilename: outfilename = 'os_%f_%d_%d.ngc' % (radius, nlines, npoints) logging.getLogger('MainApp').info('Gcode file name: %s' % (outfilename)) p = OldSchoolPattern(radius=radius, nlines=nlines, npoints=npoints) s = PathSimplifier() comment = '''Generated by oldschool.py with parameters: Radius: %f Number of lines: %d Number of points/line: %d''' % (radius, nlines, npoints) g = GCodeGenerator(open(outfilename, 'w'), comment) p.giterate(s.add_vector) vectors = s.simplify() # # adjust all vectors to be negative only # vectors = add_to_vectors(vectors, -Point(radius, radius)) g.generate(vectors)
def _main(argv): """The main function for the 'task' subcommand""" # We must special case the 'dcos task exec' subcommand in order to # allow us to pass arguments to docopt in a more user-friendly # manner. Specifically, we need to be able to to pass arguments # beginning with "-" to the command we are trying to launch with # 'exec' without docopt trying to match them to a named parameter # for the 'dcos' command itself. if len(argv) > 1 and argv[1] == "exec": args = docopt_wrapper( default_doc("task_exec"), default_doc("task"), argv=argv[2:], version="dcos-task version {}".format(dcoscli.version), options_first=True, base_subcommand="task", subcommand="exec") else: args = docopt.docopt( default_doc("task"), argv=argv, version="dcos-task version {}".format(dcoscli.version)) return cmds.execute(_cmds(), args)
def main(): """Main CLI entrypoint.""" options = docopt(__doc__, version=VERSION) setup_logger(options.get('--verbose', False)) priority_order = ["cycle", "asg", "instances", "deploy", "patch", "toggle", "upstream", "publish", "verify", "service"] cmd_opts = options.copy() if cmd_opts["<service>"] is not None: cmd_opts["service"] = True for cmd in priority_order: if cmd_opts[cmd]: logging.info('Running {0} command'.format(cmd)) CommandClass = commands[cmd] command = CommandClass(options) return command.run() print("Unknown command") # Allow local execution for debugging
def main(): arguments = docopt(__doc__,version = '1.0.0') target = arguments['<target>'] timeout = int(arguments['--timeout']) thread_num = int(arguments['<thread_num>']) process_num = int(arguments['<process_num>']) print('{} {} {} {}'.format(target,timeout,thread_num,process_num)) validator = Validator(target,timeout,process_num,thread_num) ip_all=[] logging.info("Load proxy ip, total: %s", len(ip_all)) result_tmp = validator.run(ip_all) result=[] for one in result_tmp: if one["speed"] > 8: pass else: result.append(one) logging.info("validator run finished") logging.info(len(result)) result = sorted(result, key=lambda x: x["speed"]) return result
def _main(): args = docopt(__doc__, version="1") print("Loading courses...") courses = json.load(open(args['--file']), object_pairs_hook=OrderedDict) college = args['<college>'] course_number = args['<course_number>'] for matching_course in get_course_instances(courses, college, course_number): print(get_term(matching_course)) print(matching_course['title']) max_teach_len = max(map(len, (x['Instructor'] for x in matching_course['sections'].values() if 'Instructor' in x))) for section_number, section in matching_course['sections'].items(): if 'Instructor' in section: print("Section {} - {:<{}s} ({}/{})" .format(section_number, section['Instructor'], max_teach_len, section['Enrolled'], section['Class Max'])) print("")
def render(_argv=None, _path=None, _print=print): args = docopt.docopt(__doc__, argv=_argv, version='git-literate-render {}'.format(__version__)) repo_path = _path or os.getcwd() repo = repo_for_path(repo_path) sections = literategit.list_from_range(repo, args['<begin-commit>'], args['<end-commit>']) import_name, obj_name = args['<create-url>'].rsplit('.', 1) try: create_url_module = importlib.import_module(import_name) except ImportError: import sys sys.path.append(repo_path) create_url_module = importlib.import_module(import_name) create_url = getattr(create_url_module, obj_name) _print(literategit.render(sections, create_url, args['<title>']))
def decrypt_secret_cmd(): arguments = docopt(__doc__, options_first=True) secret = StrictSecret(arguments['<secret>']) print(secret.decrypt().decode('utf-8'))
def encrypt_secret_cmd(): arguments = docopt(__doc__, options_first=True) encrypt_params = dict() if arguments['kms']: from secretcrypt import kms encrypt_params = dict( region=arguments['--region'], key_id=arguments['<key_id>'], ) module = kms elif arguments['local']: from secretcrypt import local module = local elif arguments['plain']: from secretcrypt import plain module = plain elif arguments['password']: from secretcrypt import password module = password if arguments['--multiline']: plaintext = sys.stdin.read() else: # do not print prompt if input is being piped if sys.stdin.isatty(): print('Enter plaintext: ', end="", file=sys.stderr), sys.stderr.flush() stdin = os.fdopen(sys.stdin.fileno(), 'rb', 0) plaintext = stdin.readline().rstrip(b'\n') secret = encrypt_secret(module, plaintext, encrypt_params) print(secret)
def main(): args = docopt(__doc__) # Parse args inp = args['--in'] out = args['--out'] include_id = args["--id"] is not None logging.info("Loading spaCy...") pe = prop_extraction(include_id) # Differentiate between single input file and directories if os.path.isdir(inp): logging.debug('Running on directories:') num_of_lines = num_of_extractions = 0 for input_fn in glob(os.path.join(inp, '*.txt')): output_fn = os.path.join(out, path_leaf(input_fn).replace('.txt', '.prop')) logging.debug('input file: {}\noutput file:{}'.format(input_fn, output_fn)) cur_line_counter, cur_extractions_counter = run_single_file(input_fn, output_fn, pe) num_of_lines += cur_line_counter num_of_extractions += cur_extractions_counter else: logging.debug('Running on single files:') num_of_lines, num_of_extractions = run_single_file(inp, out, pe) logging.info('# Sentences: {} \t #Extractions: {} \t Extractions/sentence Ratio: {}'. format(num_of_lines, num_of_extractions, float(num_of_extractions) / num_of_lines))
def start(self, override_docopt=None) : try : self._install_signal_handlers() options = docopt(__doc__, version=shift_detect.__version__) self._front_matter(options) except Exception as e : print("ERROR: Caught {} : {}".format(type(e), e), file=sys.stderr) sys.exit(1)
def main(): arguments = docopt.docopt(__doc__) # Run training seed = 0 # Use a seed of zero (you may want to randomize the seed!) env = get_env(arguments['--envid'], seed) with get_session() as session: model = arguments['--model'].lower() num_filters = int(arguments['--num-filters']) batch_size = int(arguments['--batch-size']) print(' * [INFO] %s model (Filters: %d, Batch Size: %d)' % ( model, num_filters, batch_size)) save_path = atari_learn( env, session, num_timesteps=int(arguments['--timesteps']), num_filters=num_filters, model=model, batch_size=batch_size, restore=arguments['--restore'], checkpoint_dir=arguments['--ckpt-dir'], learning_starts=arguments['--learning-starts']) reader = tf.train.NewCheckpointReader(save_path) W = reader.get_tensor('q_func/action_value/fully_connected/weights') print('Largest entry:', np.linalg.norm(W, ord=np.inf)) print('Frobenius norm:', np.linalg.norm(W, ord='fro'))
def main(): args = docopt(__doc__, version='flashcard 0.0.4') if args['<flashcard>'].startswith("https://docs.google.com/spreadsheets/"): flashcard = fetch_google_spreadsheet(args['<flashcard>']) else: print("<flashcard> should be URL of Google Spreadsheet (other sources are TBA)") exit(1) hint_rate = None if args['--hint'] is not None: hint_rate = float(args['--hint']) assert 0.0 <= hint_rate <= 1.0, "hint rate should satisfy 0.0 <= hint_rate <= 1.0" run(flashcard, hint_rate)
def main(): opt = docopt.docopt(__opt__ % {'prog': os.path.basename(sys.argv[0])}) verbose = opt['--verbose'] logging.getLogger().setLevel(getattr(logging, ( 'ERROR', 'WARNING', 'INFO', 'DEBUG', )[min(verbose, 3)])) logging.debug(opt) sys.exit(entry(opt))
def main(): try: args = docopt(__doc__, version='Wurst CLI 0.1.dev') if args['cleanup']: cleanup_data_directory() elif args['show']: pass else: raise ValueError except KeyboardInterrupt: sys.exit(1)
def cliparser(func): """ This decorator is used to simplify the try/except block and pass the result of the docopt parsing to the called action. """ def fn(self, arg): try: opt = docopt(fn.__doc__, arg) except DocoptExit as e: # The DocoptExit is thrown when the args do not match. # We print a message to the user and the usage block. print('Invalid Command!') print(e) return except SystemExit: # The SystemExit exception prints the usage for --help # We do not need to do the print here. return return func(self, opt) fn.__name__ = func.__name__ fn.__doc__ = func.__doc__ fn.__dict__.update(func.__dict__) return fn
def main(): args = docopt(__doc__, version='0.1') debug = args["--debug"] verbose = args["--verbose"] if not os.path.exists("log"): os.makedirs("log") configure_logging("log/lama_api.log", debug=debug, verbose=verbose) cmd_line = "COMMAND : "+" ".join(sys.argv) logging.info(cmd_line) try: Lamadb.create_db() LamaFtp.create_ftp() run_api(debug=debug) except KeyboardInterrupt: Analyzer.stop_analyzer()
def main(): args = docopt(__doc__, version='0.1') debug = args["--debug"] verbose = args["--verbose"] if not os.path.exists("log"): os.makedirs("log") configure_logging("log/lama_analyzer.log", debug=debug, verbose=verbose) cmd_line = "COMMAND : "+" ".join(sys.argv) logging.info(cmd_line) try: Lamadb.create_db() LamaFtp.create_ftp() Analyzer.run_analyzer() except KeyboardInterrupt: Analyzer.stop_analyzer()
def main(): args = docopt(__doc__, version='0.1') debug = args["--debug"] verbose = args["--verbose"] if not os.path.exists("log"): os.makedirs("log") configure_logging("log/lama_dispatcher.log", debug=debug, verbose=verbose) cmd_line = "COMMAND : "+" ".join(sys.argv) logging.info(cmd_line) try: Lamadb.create_db() LamaFtp.create_ftp() Dispatcher.dispatch() except KeyboardInterrupt: Dispatcher.stop_dispatch()
def main(): args = docopt(__doc__, version='0.1') debug = args["--debug"] verbose = args["--verbose"] if not os.path.exists("log"): os.makedirs("log") configure_logging("log/lama_mail.log", debug=debug, verbose=verbose) cmd_line = "COMMAND : "+" ".join(sys.argv) logging.info(cmd_line) config = configparser.ConfigParser() config.read('lama/conf/project.conf') try: user = config["MAIL_INPUT"]["user"] password = config["MAIL_INPUT"]["password"] server = config["MAIL_INPUT"]["server"] port = config["MAIL_INPUT"]["port"] except KeyError as e: logging.error("Error project.conf[MAIL] : {} missing.".format(str(e))) exit(1) # overide params if args["--user"]: user = args["--user"] if args["--server"]: server = args["--server"] if args["--port"]: port = args["--port"] if args["--password"]: password = getpass.getpass("Enter password please : ") print(user, password, server, port) mail = Mail(user, password, server, port) mail.run()