Python argparse.ArgumentParser() Examples
The following are 30
code examples of argparse.ArgumentParser().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
argparse
, or try the search function
.
Example #1
Source File: reval_discovery.py From Collaborative-Learning-for-Weakly-Supervised-Object-Detection with MIT License | 11 votes |
def parse_args(): """ Parse input arguments """ parser = argparse.ArgumentParser(description='Re-evaluate results') parser.add_argument('output_dir', nargs=1, help='results directory', type=str) parser.add_argument('--imdb', dest='imdb_name', help='dataset to re-evaluate', default='voc_2007_test', type=str) parser.add_argument('--comp', dest='comp_mode', help='competition mode', action='store_true') if len(sys.argv) == 1: parser.print_help() sys.exit(1) args = parser.parse_args() return args
Example #2
Source File: cmdline.py From BASS with GNU General Public License v2.0 | 9 votes |
def parse_args(): parser = argparse.ArgumentParser(description = "Bass") parser.add_argument("-v", "--verbose", action = "count", default = 0, help = "Increase verbosity") parser.add_argument("samples", metavar = "sample", nargs = "+", help = "Sample path") args = parser.parse_args() try: loglevel = { 0: logging.ERROR, 1: logging.WARN, 2: logging.INFO }[args.verbose] except KeyError: loglevel = logging.DEBUG logging.basicConfig(level = loglevel) logging.getLogger().setLevel(loglevel) return args
Example #3
Source File: client.py From BASS with GNU General Public License v2.0 | 9 votes |
def parse_args(): parser = argparse.ArgumentParser(description = "Find common ngrams in binary files") parser.add_argument("-v", "--verbose", action = "count", default = 0, help = "Increase verbosity") parser.add_argument("--output", type = str, default = None, help = "Output to file instead of stdout") parser.add_argument("--url", type = str, default = "http://localhost:5000", help = "URL of BASS server") parser.add_argument("samples", metavar = "sample", nargs = "+", help = "Cluster samples") args = parser.parse_args() try: loglevel = { 0: logging.ERROR, 1: logging.WARN, 2: logging.INFO}[args.verbose] except KeyError: loglevel = logging.DEBUG logging.basicConfig(level = loglevel) logging.getLogger().setLevel(loglevel) return args
Example #4
Source File: whitelist.py From BASS with GNU General Public License v2.0 | 8 votes |
def parse_args(): parser = argparse.ArgumentParser(description = "Add samples to BASS whitelist") parser.add_argument("-v", "--verbose", action = "count", default = 0, help = "Increase verbosity") parser.add_argument("--url", type = str, default = "http://localhost:5000", help = "URL of BASS server") parser.add_argument("sample", help = "Whitelist sample") args = parser.parse_args() try: loglevel = { 0: logging.ERROR, 1: logging.WARN, 2: logging.INFO}[args.verbose] except KeyError: loglevel = logging.DEBUG logging.basicConfig(level = loglevel) logging.getLogger().setLevel(loglevel) return args
Example #5
Source File: worker.py From incubator-spot with Apache License 2.0 | 7 votes |
def main(): # input parameters parser = argparse.ArgumentParser(description="Worker Ingest Framework") parser.add_argument('-t', '--type', dest='type', required=True, help='Type of data that will be ingested (Pipeline Configuration)', metavar='') parser.add_argument('-i', '--id', dest='id', required=True, help='Worker Id, this is needed to sync Kafka and Ingest framework (Partition Number)', metavar='') parser.add_argument('-top', '--topic', dest='topic', required=True, help='Topic to read from.', metavar="") parser.add_argument('-p', '--processingParallelism', dest='processes', required=False, help='Processing Parallelism', metavar="") args = parser.parse_args() # start worker based on the type. start_worker(args.type, args.topic, args.id, args.processes)
Example #6
Source File: bluecoat.py From incubator-spot with Apache License 2.0 | 7 votes |
def main(): """ Handle commandline arguments and start the collector. """ # input Parameters parser = argparse.ArgumentParser(description="Bluecoat Parser") parser.add_argument('-zk', '--zookeeper', dest='zk', required=True, help='Zookeeper IP and port (i.e. 10.0.0.1:2181)', metavar='') parser.add_argument('-t', '--topic', dest='topic', required=True, help='Topic to listen for Spark Streaming', metavar='') parser.add_argument('-db', '--database', dest='db', required=True, help='Hive database whete the data will be ingested', metavar='') parser.add_argument('-dt', '--db-table', dest='db_table', required=True, help='Hive table whete the data will be ingested', metavar='') parser.add_argument('-w', '--num_of_workers', dest='num_of_workers', required=True, help='Num of workers for Parallelism in Data Processing', metavar='') parser.add_argument('-bs', '--batch-size', dest='batch_size', required=True, help='Batch Size (Milliseconds)', metavar='') args = parser.parse_args() # start collector based on data source type. bluecoat_parse(args.zk, args.topic, args.db, args.db_table, args.num_of_workers, args.batch_size)
Example #7
Source File: benchmark_filter.py From mmdetection with Apache License 2.0 | 6 votes |
def parse_args(): parser = argparse.ArgumentParser(description='Filter configs to train') parser.add_argument( '--basic-arch', action='store_true', help='to train models in basic arch') parser.add_argument( '--datasets', action='store_true', help='to train models in dataset') parser.add_argument( '--data-pipeline', action='store_true', help='to train models related to data pipeline, e.g. augmentations') parser.add_argument( '--nn-module', action='store_true', help='to train models related to neural network modules') args = parser.parse_args() return args
Example #8
Source File: create_metadata.py From CAMISIM with Apache License 2.0 | 6 votes |
def parse_options(): """ parse command line options """ parser = argparse.ArgumentParser() helptext="Root path of input run for which metadata should be created, should contain metadata.tsv and genome_to_id.tsv" parser.add_argument("-i", "--input-run", type=str, help=helptext) helptext="output file to write metadata to" parser.add_argument("-o", "--output", type=str, help=helptext) helptext="Name of the data set" parser.add_argument("-n", "--name", type=str, help=helptext) if not len(sys.argv) > 1: parser.print_help() return None args = parser.parse_args() return args
Example #9
Source File: master_collector.py From incubator-spot with Apache License 2.0 | 6 votes |
def main(): # input Parameters parser = argparse.ArgumentParser(description="Master Collector Ingest Daemon") parser.add_argument('-t', '--type', dest='type', required=True, help='Type of data that will be ingested (Pipeline Configuration)', metavar='') parser.add_argument('-w', '--workers', dest='workers_num', required=True, help='Number of workers for the ingest process', metavar='') parser.add_argument('-id', '--ingestId', dest='ingest_id', required=False, help='Ingest ID', metavar='') args = parser.parse_args() # start collector based on data source type. start_collector(args.type, args.workers_num, args.ingest_id)
Example #10
Source File: __init__.py From aegea with Apache License 2.0 | 6 votes |
def initialize(): global config, parser from .util.printing import BOLD, RED, ENDC config = AegeaConfig(__name__, use_yaml=True, save_on_exit=False) if not os.path.exists(config.config_files[2]): config_dir = os.path.dirname(os.path.abspath(config.config_files[2])) try: os.makedirs(config_dir) except OSError as e: if not (e.errno == errno.EEXIST and os.path.isdir(config_dir)): raise shutil.copy(os.path.join(os.path.dirname(__file__), "user_config.yml"), config.config_files[2]) logger.info("Wrote new config file %s with default values", config.config_files[2]) config = AegeaConfig(__name__, use_yaml=True, save_on_exit=False) parser = argparse.ArgumentParser( description="{}: {}".format(BOLD() + RED() + __name__.capitalize() + ENDC(), fill(__doc__.strip())), formatter_class=AegeaHelpFormatter ) parser.add_argument("--version", action="version", version="%(prog)s {}\n{} {}\n{}".format( __version__, platform.python_implementation(), platform.python_version(), platform.platform() )) def help(args): parser.print_help() register_parser(help)
Example #11
Source File: cmd_utils.py From godot-mono-builds with MIT License | 6 votes |
def build_arg_parser(description, env_vars={}): from argparse import ArgumentParser, RawDescriptionHelpFormatter from textwrap import dedent base_env_vars = { 'MONO_SOURCE_ROOT': 'Overrides default value for --mono-sources', } env_vars_text = '\n'.join([' %s: %s' % (var, desc) for var, desc in env_vars.items()]) base_env_vars_text = '\n'.join([' %s: %s' % (var, desc) for var, desc in base_env_vars.items()]) epilog=dedent('''\ environment variables: %s %s ''' % (env_vars_text, base_env_vars_text)) return ArgumentParser( description=description, formatter_class=RawDescriptionHelpFormatter, epilog=epilog )
Example #12
Source File: __init__.py From twstock with MIT License | 6 votes |
def run(): parser = argparse.ArgumentParser() parser.add_argument('-b', '--bfp', nargs='+') parser.add_argument('-s', '--stock', nargs='+') parser.add_argument('-r', '--realtime', nargs='+') parser.add_argument('-U', '--upgrade-codes', action='store_true', help='Update entites codes') args = parser.parse_args() if args.bfp: best_four_point.run(args.bfp) elif args.stock: stock.run(args.stock) elif args.realtime: realtime.run(args.realtime) elif args.upgrade_codes: print('Start to update codes') __update_codes() print('Done!') else: parser.print_help()
Example #13
Source File: eapi_2_acl.py From Mastering-Python-Networking-Second-Edition with MIT License | 6 votes |
def main(): parser = argparse.ArgumentParser(description="Edit Arista ACLs using your local editor") parser.add_argument("acl", metavar="ACL", help="Name of the access list to modify") parser.add_argument("switches", metavar="SWITCH", nargs="+", help="Hostname or IP of the switch to query") parser.add_argument("--username", help="Name of the user to connect as", default="admin") parser.add_argument("--password", help="The user's password") parser.add_argument("--https", help="Use HTTPS instead of HTTP", action="store_const", const="https", default="http") args = parser.parse_args() aclName = args.acl tmpfile = "/tmp/AclEditor-%s" % aclName apiEndpoints = getEndpoints(args.switches, args.https, args.username, args.password) prepopulateAclFile(tmpfile, aclName, apiEndpoints) edits = getEdits(tmpfile) applyChanges(aclName, apiEndpoints, edits) print print "Done!"
Example #14
Source File: reval.py From Collaborative-Learning-for-Weakly-Supervised-Object-Detection with MIT License | 6 votes |
def parse_args(): """ Parse input arguments """ parser = argparse.ArgumentParser(description='Re-evaluate results') parser.add_argument('output_dir', nargs=1, help='results directory', type=str) parser.add_argument('--imdb', dest='imdb_name', help='dataset to re-evaluate', default='voc_2007_test', type=str) parser.add_argument('--matlab', dest='matlab_eval', help='use matlab for evaluation', action='store_true') parser.add_argument('--comp', dest='comp_mode', help='competition mode', action='store_true') parser.add_argument('--nms', dest='apply_nms', help='apply nms', action='store_true') if len(sys.argv) == 1: parser.print_help() sys.exit(1) args = parser.parse_args() return args
Example #15
Source File: image_demo.py From mmdetection with Apache License 2.0 | 6 votes |
def main(): parser = ArgumentParser() parser.add_argument('img', help='Image file') parser.add_argument('config', help='Config file') parser.add_argument('checkpoint', help='Checkpoint file') parser.add_argument( '--device', default='cuda:0', help='Device used for inference') parser.add_argument( '--score-thr', type=float, default=0.3, help='bbox score threshold') args = parser.parse_args() # build the model from a config file and a checkpoint file model = init_detector(args.config, args.checkpoint, device=args.device) # test a single image result = inference_detector(model, args.img) # show the results show_result_pyplot(model, args.img, result, score_thr=args.score_thr)
Example #16
Source File: download_glue.py From BERT-Classification-Tutorial with Apache License 2.0 | 6 votes |
def main(arguments): parser = argparse.ArgumentParser() parser.add_argument('--data_dir', help='directory to save data to', type=str, default='glue_data') parser.add_argument('--tasks', help='tasks to download data for as a comma separated string', type=str, default='all') parser.add_argument('--path_to_mrpc', help='path to directory containing extracted MRPC data, msr_paraphrase_train.txt and msr_paraphrase_text.txt', type=str, default='') args = parser.parse_args(arguments) if not os.path.isdir(args.data_dir): os.mkdir(args.data_dir) tasks = get_tasks(args.tasks) for task in tasks: if task == 'MRPC': format_mrpc(args.data_dir, args.path_to_mrpc) elif task == 'diagnostic': download_diagnostic(args.data_dir) else: download_and_extract(task, args.data_dir)
Example #17
Source File: __init__.py From python-panavatar with MIT License | 6 votes |
def cmdline(): import argparse parser = argparse.ArgumentParser(description='Generate an svg wallpaper') parser.add_argument('--width', type=int, default=1024, help='The width of the wallpaper') parser.add_argument('--height', type=int, default=786, help='The height of the wallpaper') parser.add_argument('--seed', help='Seed for the randomizer') parser.add_argument('--log-choices', help='Log the choices made', action='store_true') parser.add_argument('--output', type=argparse.FileType('w'), default='-') args = parser.parse_args() for element in get_svg_iter(args.width, args.height, {"seed": args.seed}, log_choices=args.log_choices): args.output.write(element)
Example #18
Source File: learn.py From flappybird-qlearning-bot with MIT License | 6 votes |
def main(): global HITMASKS, ITERATIONS, VERBOSE, bot parser = argparse.ArgumentParser("learn.py") parser.add_argument("--iter", type=int, default=1000, help="number of iterations to run") parser.add_argument( "--verbose", action="store_true", help="output [iteration | score] to stdout" ) args = parser.parse_args() ITERATIONS = args.iter VERBOSE = args.verbose # load dumped HITMASKS with open("data/hitmasks_data.pkl", "rb") as input: HITMASKS = pickle.load(input) while True: movementInfo = showWelcomeAnimation() crashInfo = mainGame(movementInfo) showGameOverScreen(crashInfo)
Example #19
Source File: arproxy.py From iSDX with Apache License 2.0 | 6 votes |
def main(): global arpListener, config parser = argparse.ArgumentParser() parser.add_argument('dir', help='the directory of the example') args = parser.parse_args() # locate config file config_file = os.path.join(os.path.dirname(os.path.realpath(__file__)),"..","examples",args.dir,"config","sdx_global.cfg") logger.info("Reading config file %s", config_file) config = parse_config(config_file) logger.info("Starting ARP Listener") arpListener = ArpListener() ap_thread = Thread(target=arpListener.start) ap_thread.start() # start pctrl listener in foreground logger.info("Starting PCTRL Listener") pctrlListener = PctrlListener() pctrlListener.start()
Example #20
Source File: pytorch2onnx.py From mmdetection with Apache License 2.0 | 6 votes |
def parse_args(): parser = argparse.ArgumentParser( description='MMDet pytorch model conversion to ONNX') parser.add_argument('config', help='test config file path') parser.add_argument('checkpoint', help='checkpoint file') parser.add_argument( '--out', type=str, required=True, help='output ONNX filename') parser.add_argument( '--shape', type=int, nargs='+', default=[1280, 800], help='input image size') parser.add_argument( '--passes', type=str, nargs='+', help='ONNX optimization passes') args = parser.parse_args() return args
Example #21
Source File: browse_dataset.py From mmdetection with Apache License 2.0 | 6 votes |
def parse_args(): parser = argparse.ArgumentParser(description='Browse a dataset') parser.add_argument('config', help='train config file path') parser.add_argument( '--skip-type', type=str, nargs='+', default=['DefaultFormatBundle', 'Normalize', 'Collect'], help='skip some useless pipeline') parser.add_argument( '--output-dir', default=None, type=str, help='If there is no display interface, you can save it') parser.add_argument('--not-show', default=False, action='store_true') parser.add_argument( '--show-interval', type=int, default=999, help='the interval of show (ms)') args = parser.parse_args() return args
Example #22
Source File: twitter-export-image-fill.py From twitter-export-image-fill with The Unlicense | 6 votes |
def parse_arguments(): parser = argparse.ArgumentParser(description = 'Downloads all the images to your Twitter archive .') parser.add_argument('--include-videos', dest='PATH_TO_YOUTUBE_DL', help = 'use youtube_dl to download videos (and animated GIFs) in addition to images') parser.add_argument('--continue-after-failure', action='store_true', help = 'continue the process when one of the downloads fail (creates incomplete archive)') parser.add_argument('--backfill-from', dest='EARLIER_ARCHIVE_PATH', help = 'copy images downloaded into an earlier archive instead of downloading them again (useful for incremental backups)') parser.add_argument('--skip-retweets', action='store_true', help = 'do not download images or videos from retweets') parser.add_argument('--skip-images', action='store_true', help = 'do not download images in general') parser.add_argument('--skip-videos', action='store_true', help = 'do not download videos (and animated GIFs) in general') parser.add_argument('--skip-avatars', action='store_true', help = 'do not download avatar images') parser.add_argument('--verbose', action='store_true', help = 'show additional debugging info') parser.add_argument('--force-redownload', action='store_true', help = 'force to re-download images and videos that were already downloaded') return parser.parse_args()
Example #23
Source File: export_binexport_pickle.py From BASS with GNU General Public License v2.0 | 6 votes |
def parse_args(): parser = argparse.ArgumentParser(description = "IDA Pro script: Dump bindiff database file") subparsers = parser.add_subparsers(help = "subcommand") parser_pickle = subparsers.add_parser("pickle", help = "Dump pickled database") parser_pickle.add_argument("pickle_output", type = str, help = "Output pickle database file") parser_pickle.set_defaults(handler = handle_pickle) parser_bindiff = subparsers.add_parser("binexport", help = "Dump bindiff database") parser_bindiff.add_argument("bindiff_output", type = str, help = "Output BinExport database file") parser_bindiff.set_defaults(handler = handle_binexport) parser_bindiff_pickle = subparsers.add_parser("binexport_pickle", help = "Dump bindiff database and pickled database") parser_bindiff_pickle.add_argument("bindiff_output", type = str, help = "Output BinDiff database file") parser_bindiff_pickle.add_argument("pickle_output", type = str, help = "Output pickle database file") parser_bindiff_pickle.set_defaults(handler = handle_binexport_pickle) args = parser.parse_args(idc.ARGV[1:]) return args
Example #24
Source File: download_images.py From neural-fingerprinting with BSD 3-Clause "New" or "Revised" License | 5 votes |
def parse_args(): """Parses command line arguments.""" parser = argparse.ArgumentParser( description='Tool to download dataset images.') parser.add_argument('--input_file', required=True, help='Location of dataset.csv') parser.add_argument('--output_dir', required=True, help='Output path to download images') parser.add_argument('--threads', default=multiprocessing.cpu_count() + 1, help='Number of threads to use') args = parser.parse_args() return args.input_file, args.output_dir, int(args.threads)
Example #25
Source File: analyze_logs.py From mmdetection with Apache License 2.0 | 5 votes |
def parse_args(): parser = argparse.ArgumentParser(description='Analyze Json Log') # currently only support plot curve and calculate average train time subparsers = parser.add_subparsers(dest='task', help='task parser') add_plot_parser(subparsers) add_time_parser(subparsers) args = parser.parse_args() return args
Example #26
Source File: split.py From subword-qac with MIT License | 5 votes |
def get_args(): parser = argparse.ArgumentParser() parser.add_argument('--tag', type=str, default='full') parser.add_argument('--train_start', type=str, default='2006-03-01 00:00:00') parser.add_argument('--train_end', type=str, default='2006-05-18 00:00:00') parser.add_argument('--valid_start', type=str, default='2006-05-18 00:00:00') parser.add_argument('--valid_end', type=str, default='2006-05-25 00:00:00') parser.add_argument('--test_start', type=str, default='2006-05-25 00:00:00') parser.add_argument('--test_end', type=str, default='2006-06-01 00:00:00') args = parser.parse_args() return args
Example #27
Source File: __main__.py From anishot with MIT License | 5 votes |
def parse_arguments(): parser = argparse.ArgumentParser( description='Animates a long screenshot into a GIF') parser.add_argument('input', type=argparse.FileType(), help='Input screenshot image') parser.add_argument('output', type=str, help='Output animated GIF') parser.add_argument('height', type=int, help='Window height') parser.add_argument('--pad', default=0, type=int, help='Padding on sides') parser.add_argument('--maxspeed', default=200, type=int, help='Max speed on scroll px/frame') parser.add_argument('--stops', nargs='*', default=[], help='Stops between scrolls, px') parser.add_argument('--zoom-steps', default=7, type=int, help='Number of steps on initial zoom in') parser.add_argument('--start-scale', default=.7, type=float, help='Start scale') parser.add_argument('--zoom-to', default=0, type=int, help='Point to zoom to') parser.add_argument('--shadow-size', default=0, type=int, help='Shadow size') parser.add_argument('--rgb-outline', default='#e1e4e8', type=str, help='Screenshot outline color') parser.add_argument('--rgb-background', default='#ffffff', type=str, help='Background color') parser.add_argument('--rgb-shadow', default='#999999', type=str, help='Screenshot shadow color') parser.add_argument('--rgb-window', default='#e1e4e8', type=str, help='Window outline color') global ARGS ARGS = parser.parse_args()
Example #28
Source File: run_attacks_and_defenses.py From neural-fingerprinting with BSD 3-Clause "New" or "Revised" License | 5 votes |
def parse_args(): """Parses command line arguments.""" parser = argparse.ArgumentParser( description='Tool to run attacks and defenses.') parser.add_argument('--attacks_dir', required=True, help='Location of all attacks.') parser.add_argument('--targeted_attacks_dir', required=True, help='Location of all targeted attacks.') parser.add_argument('--defenses_dir', required=True, help='Location of all defenses.') parser.add_argument('--dataset_dir', required=True, help='Location of the dataset.') parser.add_argument('--dataset_metadata', required=True, help='Location of the dataset metadata.') parser.add_argument('--intermediate_results_dir', required=True, help='Directory to store intermediate results.') parser.add_argument('--output_dir', required=True, help=('Output directory.')) parser.add_argument('--epsilon', required=False, type=int, default=16, help='Maximum allowed size of adversarial perturbation') parser.add_argument('--gpu', dest='use_gpu', action='store_true') parser.add_argument('--nogpu', dest='use_gpu', action='store_false') parser.set_defaults(use_gpu=False) parser.add_argument('--save_all_classification', dest='save_all_classification', action='store_true') parser.add_argument('--nosave_all_classification', dest='save_all_classification', action='store_false') parser.set_defaults(save_all_classification=False) return parser.parse_args()
Example #29
Source File: route_server.py From iSDX with Apache License 2.0 | 5 votes |
def main(): global bgpListener, pctrlListener, config parser = argparse.ArgumentParser() parser.add_argument('dir', help='the directory of the example') args = parser.parse_args() # locate config file config_file = os.path.join(os.path.dirname(os.path.realpath(__file__)),"..","examples",args.dir,"config","sdx_global.cfg") logger.info("Reading config file %s", config_file) config = parse_config(config_file) bgpListener = BGPListener() bp_thread = Thread(target=bgpListener.start) bp_thread.start() pctrlListener = PctrlListener() pp_thread = Thread(target=pctrlListener.start) pp_thread.start() while bp_thread.is_alive(): try: time.sleep(5) except KeyboardInterrupt: bgpListener.stop() bp_thread.join() pctrlListener.stop() pp_thread.join()
Example #30
Source File: enjoy-adv.py From neural-fingerprinting with BSD 3-Clause "New" or "Revised" License | 5 votes |
def parse_args(): parser = argparse.ArgumentParser("Run an already learned DQN model.") # Environment parser.add_argument("--env", type=str, required=True, help="name of the game") parser.add_argument("--model-dir", type=str, default=None, help="load model from this directory. ") parser.add_argument("--video", type=str, default=None, help="Path to mp4 file where the \ video of first episode will be recorded.") boolean_flag(parser, "stochastic", default=True, help="whether or not to use stochastic \ actions according to models eps value") boolean_flag(parser, "dueling", default=False, help="whether or not to use dueling model") # V: Attack Arguments# parser.add_argument("--model-dir2", type=str, default=None, help="load adversarial model from \ this directory (blackbox attacks). ") parser.add_argument("--attack", type=str, default=None, help="Method to attack the model.") boolean_flag(parser, "noisy", default=False, help="whether or not to NoisyNetwork") boolean_flag(parser, "noisy2", default=False, help="whether or not to NoisyNetwork") boolean_flag(parser, "blackbox", default=False, help="whether or not to NoisyNetwork") return parser.parse_args()