我们从Python开源项目中,提取了以下28个代码示例,用于说明如何使用dateutil.parser.add_argument()。
def __init__(self, profilePath, driverPath): options = webdriver.ChromeOptions() prefs = {"profile.managed_default_content_settings.images":2} options.add_argument("user-data-dir=" + profilePath) options.add_argument("headless") options.add_argument('window-size=1920x1080') options.add_experimental_option("prefs", prefs) try: self.driver = webdriver.Chrome(executable_path=driverPath, chrome_options=options) except WebDriverException: print("failed to start driver at " + driverPath) self.inUse = True #scraper with no driver is not ready to handle new job #traceback.print_exc() self.inUse = False #if False, is ready to handle new job self.bannerClosed = False #email banner only needs to be closed on first load self.timeLimit = datetime.now() + timedelta(minutes=TIMEOUT_MINUTES)
def input_Options(): """ Creates the parse options """ parser = argparse.ArgumentParser(description='Directory that contains Json files.') parser.add_argument('-d', '--test-directory', help='Directory that contains the json metadata files') parser.add_argument('-u', '--skip-uuid-directory', help='Directory that contains files with file uuids (bundle uuids, one per line, file ending with .redacted) that represent databundles that should be skipped, useful for redacting content (but not deleting it)') parser.add_argument('-m', '--metadata-schema', help='File that contains the metadata schema') parser.add_argument('-s', '--skip-program', help='Lets user skip certain json files that contain a specific program test') parser.add_argument('-o', '--only-program', help='Lets user include certain json files that contain a specific program test') parser.add_argument('-r', '--skip-project', help='Lets user skip certain json files that contain a specific program test') parser.add_argument('-t', '--only-project', help='Lets user include certain json files that contain a specific program test') parser.add_argument('-a', '--storage-access-token', default="NA", help='Storage access token to download the metadata.json files') parser.add_argument('-n', '--server-host', default="redwood.io", help='hostname for the storage service') parser.add_argument('-p', '--max-pages', default=None, type=int, help='Specify maximum number of pages to download') parser.add_argument('-preserve-version',action='store_true', default=False, help='Keep all copies of analysis events') args = parser.parse_args() return args
def input_Options(): """ Creates the parse options """ parser = argparse.ArgumentParser(description='Directory that contains Json files.') parser.add_argument('-d', '--test-directory', help='Directory that contains the json metadata files') parser.add_argument('-u', '--skip-uuid-directory', help='Directory that contains files with file uuids (bundle uuids, one per line, file ending with .redacted) that represent databundles that should be skipped, useful for redacting content (but not deleting it)') parser.add_argument('-m', '--metadata-schema', help='File that contains the metadata schema') parser.add_argument('-s', '--skip-program', help='Lets user skip certain json files that contain a specific program test') parser.add_argument('-o', '--only-program', help='Lets user include certain json files that contain a specific program test') parser.add_argument('-r', '--skip-project', help='Lets user skip certain json files that contain a specific program test') parser.add_argument('-t', '--only-project', help='Lets user include certain json files that contain a specific program test') parser.add_argument('-a', '--storage-access-token', default="NA", help='Storage access token to download the metadata.json files') parser.add_argument('-c', '--client-path', default="ucsc-storage-client/", help='Path to access the ucsc-storage-client tool') parser.add_argument('-n', '--server-host', default="storage.ucsc-cgl.org", help='hostname for the storage service') parser.add_argument('-p', '--max-pages', default=None, type=int, help='Specify maximum number of pages to download') parser.add_argument('-preserve-version',action='store_true', default=False, help='Keep all copies of analysis events') args = parser.parse_args() return args
def cmdLineParse(): parser = argparse.ArgumentParser(description='Download GPS data over SAR coverage.',\ formatter_class=argparse.RawTextHelpFormatter,\ epilog=INTRODUCTION+'\n'+EXAMPLE) parser.add_argument('RefDate',help='Reference date of differential InSAR') parser.add_argument('-d', dest = 'date', help='date for estimation.') parser.add_argument('--datetxt', dest = 'datetxt', help='text file of date.') parser.add_argument('--Atm',action="store_true", default=False, help='Geting SAR LOS tropospheric delay.') parser.add_argument('--Def', action="store_true", default=False, help='Getting SAR LOS deformation.') inps = parser.parse_args() if not inps.date and not inps.datetxt: parser.print_usage() sys.exit(os.path.basename(sys.argv[0])+': error: date and date_txt File, at least one is needed.') return inps ####################################################################################################
def cmdLineParse(): parser = argparse.ArgumentParser(description='Download GPS data over SAR coverage.',\ formatter_class=argparse.RawTextHelpFormatter,\ epilog=INTRODUCTION+'\n'+EXAMPLE) parser.add_argument('projectName',help='Name of project.') parser.add_argument('--Atm',action="store_true", default=False, help='Geting SAR LOS tropospheric delay.') parser.add_argument('--Def', action="store_true", default=False, help='Getting SAR LOS deformation.') inps = parser.parse_args() return inps ####################################################################################################
def main(): parser = argparse.ArgumentParser() # parser.add_argument("-v", "--verbose", help="verbose output", action="store_true") parser.add_argument("-t", "--test", help="shell test, no browser", action="store_true") options = parser.parse_args() if not os.path.exists('slipsomat.cfg'): print('No slipsomat.cfg file found in this directory. Exiting.') return browser = Browser('slipsomat.cfg') if not options.test: # test mode without driver browser.connect() atexit.register(browser.close) Shell(browser).cmdloop()
def get_parser(self, prog_name): parser = super().get_parser(prog_name) parser.add_argument('tenant_id', help='Tenant ID') parser.add_argument('start', help='Start Date') parser.add_argument('end', help='End Date') return parser
def get_parser(self, prog_name): parser = super().get_parser(prog_name) parser.add_argument('tenant_id', help='Tenant ID') parser.add_argument('start', help='Start Date') parser.add_argument('--end', help='End Date') return parser
def get_parser(self, prog_name): parser = super().get_parser(prog_name) parser.add_argument('instance_id', help='Instance ID') parser.add_argument('--start', help='Start Date') parser.add_argument('--end', help='End Date') parser.add_argument('--flavor', help='Flavor') parser.add_argument('--name', help='Instance Name') return parser
def __init__(self): parser = argparse.ArgumentParser(description='Downloads data files for the various bundles.') parser.add_argument('--input-dir', default='.', required=True) # get args args = parser.parse_args() self.input_dir = args.input_dir # run self.run()
def create_config_parser(self): config_parser = argparse.ArgumentParser(add_help=False) config_parser.add_argument("-f", "--config-file", dest="config_file", help="Config file from which to pick credentials") return config_parser
def add_arguments(self, parser): parser.add_argument('user_id', type=int) parser.add_argument('path', help='Evernote path to the exported files')
def cmdLineParse(): parser = argparse.ArgumentParser(description='Download GPS data over SAR coverage.',\ formatter_class=argparse.RawTextHelpFormatter,\ epilog=INTRODUCTION+'\n'+EXAMPLE) parser.add_argument('gps_txt',help='Available GPS station information.') parser.add_argument('-d', dest='time', help='SAR acquisition time.') parser.add_argument('--datetxt', dest='datetxt', help='text file of date for downloading.') inps = parser.parse_args() return inps ####################################################################################################
def cmdLineParse(): parser = argparse.ArgumentParser(description='Download GPS data over SAR coverage.',\ formatter_class=argparse.RawTextHelpFormatter,\ epilog=INTRODUCTION+'\n'+EXAMPLE) parser.add_argument('projectName',help='Project name.') inps = parser.parse_args() return inps ####################################################################################################
def cmdLineParse(): parser = argparse.ArgumentParser(description='Compare InSAR results and GPS results both for APS and deformation.',\ formatter_class=argparse.RawTextHelpFormatter,\ epilog=INTRODUCTION+'\n'+EXAMPLE) parser.add_argument('projectName',help='Name of project.') parser.add_argument('--noramp',action="store_true", default=False,help='Interferograms does has no ramp.') parser.add_argument('--width',dest='width',help='width of unwrapped image.') inps = parser.parse_args() return inps ####################################################################################################
def main(): parser = argparse.ArgumentParser(description='Find latest RHEL AMI') parser.add_argument('-v', dest="version",metavar="VERSION",required = True, help='RHEL Version') parser.add_argument('-r', dest="region",metavar="REGION",required = True, help='REGION to query AMI') parser.add_argument('-t', dest="type",metavar="AMI_TYPE",required = True, help='AMI Type (hvm)') args = parser.parse_args() version = args.version region = args.region ami_type = args.type ami_name = 'RHEL-'+ version + "*" + "-x86_64*"; cmd = aws_cmd + " ec2 describe-images --filters \"Name=name,Values=AMI-PLACEHOLDER\" \"Name=virtualization-type,Values=VTYPE-PLACEHOLDER\" --owners 309956199498 --region REGION-PLACEHOLDER" cmd = cmd.replace('AMI-PLACEHOLDER',ami_name) cmd = cmd.replace('VTYPE-PLACEHOLDER',ami_type) cmd = cmd.replace('REGION-PLACEHOLDER',region) output = exe_cmd(cmd) images = output['out'] val = json.loads(images) images = val['Images'] sorted_images = sorted(images,key = get_creationdate,reverse=True) print sorted_images[0]['ImageId']
def main(): parser = argparse.ArgumentParser() parser.add_argument('out_dir') parser.add_argument('start', type=int) parser.add_argument('end', type=int) parser.add_argument('--limit', type=int) parser.add_argument('--skip', help='file path to URLs to skip') args = parser.parse_args() urls = make_urls(args.start, args.end, limit=args.limit, skip=args.skip) fetch_all(urls, args.out_dir)
def parse_args(): parser = argparse.ArgumentParser(description='Manager Arch Linux security ' 'update tracking') parser.add_argument('--download', action='store_true', help='Download new update announcemets') args = parser.parse_args() return args
def add_arguments(self, parser): # Limit max number of dataposts to process parser.add_argument('--limit', action='store', dest='limit', default=None, help=u'Limit the number of dataposts to handle') # Limit dataposts to one idcode parser.add_argument('--idcode', action='store', dest='idcode', default=None, help=u'Handle only dataposts of "idcode"') # Limit processing time parser.add_argument('--maxprocessingtime', action='store', dest='maxprocessingtime', default=None, help=u'Stop processing after "maxprocessingtime" ' u'seconds is reached') parser.add_argument('--pk', action='store', dest='pk', type=int, default=None, help=u'Process only Datapost which has "pk"')
def main(): parser = argparse.ArgumentParser(description="Yo database utils") parser.add_argument('db_url', type=str) subparsers = parser.add_subparsers(help='sub-command help') init_sub = subparsers.add_parser('init') init_sub.set_defaults(func=init_db) reset_sub = subparsers.add_parser('reset') reset_sub.set_defaults(func=reset_db) args = parser.parse_args() args.func(args=args)
def main(): import sys import argparse parser = argparse.ArgumentParser(description="command line mail user agent") parser.add_argument('--config', help='custom configuration file') parser.add_argument('--account','-A', help='run account command after config file is read') args = parser.parse_args() interact(args)
def parse_command_line_arguments(logger): """ Parse command line arguments received, if any Print example if invalid arguments are passed :param logger: the logger :return: config_filename passed as argument if any, else DEFAULT_CONFIG_FILENAME export_formats passed as argument if any, else 'pdf' list_export_profiles if passed as argument, else None do_loop False if passed as argument, else True """ parser = argparse.ArgumentParser() parser.add_argument('--config', help='config file to use, defaults to ' + DEFAULT_CONFIG_FILENAME) parser.add_argument('--format', nargs='*', help='formats to download, valid options are pdf, ' 'json, docx, csv, media, web-report-link, actions') parser.add_argument('--list_export_profiles', nargs='*', help='display all export profiles, or restrict to specific' ' template_id if supplied as additional argument') parser.add_argument('--loop', nargs='*', help='execute continuously until interrupted') parser.add_argument('--setup', action='store_true', help='Automatically create new directory containing the ' 'necessary config file.' 'Directory will be named iAuditor Audit Exports, and will be placed in your current directory') args = parser.parse_args() config_filename = DEFAULT_CONFIG_FILENAME if args.setup: initial_setup(logger) exit() if args.config is not None: if os.path.isfile(args.config): config_filename = args.config logger.debug(config_filename + ' passed as config argument') else: logger.error(config_filename + ' is not a valid config file') sys.exit(1) export_formats = ['pdf'] if args.format is not None and len(args.format) > 0: valid_export_formats = ['json', 'docx', 'pdf', 'csv', 'media', 'web-report-link', 'actions'] export_formats = [] for option in args.format: if option not in valid_export_formats: print('{0} is not a valid export format. Valid options are pdf, json, docx, csv, web-report-link, ' 'media, or actions'.format(option)) logger.info('invalid export format argument: {0}'.format(option)) else: export_formats.append(option) loop_enabled = True if args.loop is not None else False return config_filename, export_formats, args.list_export_profiles, loop_enabled
def parse_command_line(argv): me = os.path.basename(argv[0]) format_from_filename, from_, to = filename2format(me) parser = argparse.ArgumentParser(description='Convert between TOML, YAML ' 'and JSON.') group = parser.add_mutually_exclusive_group() group.add_argument('-i', '--input', dest='input_flag', metavar='INPUT', default=None, help='input file') group.add_argument('inputfile', nargs='?', default='-', help='input file') parser.add_argument('-o', '--output', dest='output', default='-', help='output file') if not format_from_filename: parser.add_argument('-if', '--input-format', dest='input_format', required=True, help="input format", choices=FORMATS) parser.add_argument('-of', '--output-format', dest='output_format', required=True, help="output format", choices=FORMATS) if not format_from_filename or to == 'json': parser.add_argument('--indent-json', dest='indent_json', action='store_const', const=2, default=None, help='indent JSON output') if not format_from_filename or to == 'yaml': parser.add_argument('--yaml-style', dest='yaml_style', default=None, help='YAML formatting style', choices=['', '\'', '"', '|', '>']) parser.add_argument('--wrap', dest='wrap', default=None, help='wrap the data in a map type with the given key') parser.add_argument('--unwrap', dest='unwrap', default=None, help='only output the data stored under the given key') parser.add_argument('-v', '--version', action='version', version=__version__) args = parser.parse_args(args=argv[1:]) if args.input_flag is not None: args.input = args.input_flag else: args.input = args.inputfile if format_from_filename: args.input_format = from_ args.output_format = to if to != 'json': args.__dict__['indent_json'] = None if to != 'yaml': args.__dict__['yaml_style'] = None args.__dict__['yaml_options'] = {'default_style': args.yaml_style} del args.__dict__['yaml_style'] return args
def create_command_parser(self, config_parser): parser = argparse.ArgumentParser( parents=[config_parser], description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter, ) default_options = {} default_options.update(self.default_report_options) default_options.update(self.default_controller_options) parser.set_defaults(**default_options) parser.add_argument("-s", "--start-time", dest="start_time", required=True, metavar="yyyy-mm-dd", help="Start date(UTC) in iso format: yyyy-mm-dd") parser.add_argument("-e", "--end-time", dest="end_time", required=True, metavar="yyyy-mm-dd", help="End date(UTC) in iso format: yyyy-mm-dd") parser.add_argument("-g", "--granularity", dest="granularity", choices=['hourly', 'daily'], help="Granularity of the license units consumed " "either hourly or daily") parser.add_argument("-t", "--tabs", dest="tabs", type=str, help="Tabs to include in excel sheet generated (for each tab a seperate" " csv is generated for csv output format)") parser.add_argument("--report-file-prefix", dest="report_file_prefix", type=str, help="Report file prefix") parser.add_argument("--generate-csv", dest="generate_csv", choices=['yes', 'no'], help="Generate CSV file for each sheet in generated excel file") parser.add_argument("--skip-tiers", dest="skip_tiers", choices=['yes', 'no'], help="Skip generating tier information for the application summary tab. " "This will only affect the application summary sheet.") parser.add_argument("--skip-applications", dest="skip_applications", choices=['yes', 'no'], help="Skip generating application information for the application summary tab. " "This will only affect the application summary sheet.") parser.add_argument("--sheet-per-app", dest="sheet_per_app", choices=['yes', 'no'], help="Have one sheet for each application") parser.add_argument("--include-non-npm-agent-summary", choices=['yes', 'no'], dest="include_non_npm_agent_summary", help="Include non apm agent summary") parser.add_argument("--show-hours-in-column", dest="show_hours_in_column", choices=['yes', 'no'], help="Show hours in column instead of horizontal row") return parser
def __call__(self, args=None): sys.excepthook = terminal.error_handler parser = terminal.configure_parser(""" The piw-slave script is intended to be run on a standalone machine to build packages on behalf of the piw-master script. It is intended to be run as an unprivileged user with a clean home-directory. Any build dependencies you wish to use must already be installed. The script will run until it is explicitly terminated, either by Ctrl+C, SIGTERM, or by the remote piw-master script. """) parser.add_argument( '-m', '--master', env_var='PIW_MASTER', metavar='HOST', default='localhost', help="The IP address or hostname of the master server " "(default: %(default)s)") parser.add_argument( '-t', '--timeout', env_var='PIW_TIMEOUT', metavar='DURATION', default='3h', type=duration, help="The time to wait before assuming a build has failed; " "(default: %(default)s)") self.config = parser.parse_args(args) terminal.configure_logging(self.config.log_level, self.config.log_file) self.logger.info('PiWheels Slave version %s', __version__) ctx = zmq.Context.instance() queue = ctx.socket(zmq.REQ) queue.hwm = 1 queue.ipv6 = True queue.connect('tcp://{master}:5555'.format( master=self.config.master)) try: request = ['HELLO', self.config.timeout, pep425tags.get_impl_ver(), pep425tags.get_abi_tag(), pep425tags.get_platform()] while request is not None: queue.send_pyobj(request) reply, *args = queue.recv_pyobj() request = self.handle_reply(reply, *args) finally: queue.send_pyobj(['BYE']) ctx.destroy(linger=1000) ctx.term() # A general note about the design of the slave: the build slave is # deliberately designed to be "brittle". In other words to fall over and # die loudly in the event anything happens to go wrong (other than utterly # expected failures like wheels occasionally failing to build and file # transfers occasionally needing a retry). Hence all the apparently silly # asserts littering the functions below. # This is in stark constrast to the master which is expected to stay up and # carry on running even if a build slave goes bat-shit crazy and starts # sending nonsense (in which case it should calmly ignore it and/or attempt # to kill said slave with a "BYE" message).