def handle_args(args, usage): """ Parse and load all of the basic arguments. Also passes any needed arguments on to pywikibot and sets any defaults. :param args: arguments to be handled :return: dict of options """ expected_args = ('mapping_log_file', 'harvest_file', 'settings_file', 'mappings_dir', 'wiki_mapping_root', 'intro_texts_keyword', 'intro_texts_people', 'intro_texts_places', 'glam_code') options = {'intro_texts': {}} for arg in pywikibot.handle_args(args): option, sep, value = arg.partition(':') if option.startswith('-') and option[1:] in expected_args: if option.startswith('-intro_texts_'): sub = option[len('-intro_texts_'):] options['intro_texts'][sub] = common.convert_from_commandline( value) else: options[option[1:]] = common.convert_from_commandline(value) else: exit() # remove if not used so as to not block loading from settings file if not options['intro_texts']: del options['intro_texts'] return options
def handle_args(args): """ Parse and load all of the basic arguments. Redefined from parent so that categories don't have to be passed manually. Also passes any needed arguments on to pywikibot and sets any defaults. @param args: arguments to be handled @type args: list of strings @return: list of options @rtype: dict """ options = { 'in_file': None, 'base_name': None, 'update_mappings': True, 'batch_settings': None } for arg in pywikibot.handle_args(args): option, sep, value = arg.partition(':') if option == '-in_file': options['in_file'] = common.convert_from_commandline(value) elif option == '-base_name': options['base_name'] = common.convert_from_commandline(value) elif option == '-update_mappings': options['update_mappings'] = common.interpret_bool(value) elif option == '-batch_settings': options['batch_settings'] = common.convert_from_commandline( value) return options
def main(*args): """Command line entry-point.""" usage = \ 'Usage:\tpython prepUpload.py '\ '-in_path:PATH -out_path:PATH -data_path:PATH\n' \ '\tExamples:\n' \ '\tpython prepUpload.py -in_path:../diskkopia -out_path:./toUpload ' \ '-data_path:./datafile.json \n' in_path = None out_path = None data_path = None # Load pywikibot args and handle local args for arg in pywikibot.handle_args(args): option, sep, value = arg.partition(':') if option == '-in_path': in_path = common.convert_from_commandline(value) elif option == '-out_path': out_path = common.convert_from_commandline(value) elif option == '-data_path': data_path = common.convert_from_commandline(value) elif option == '-usage': pywikibot.output(usage) return if in_path and out_path and data_path: run(in_path, out_path, data_path) else: pywikibot.output(usage)
def handle_args(args): """Parse and load all of the basic arguments. Need to override the basic argument handler since we want two input files. Also construct a base_name fallback option from these. @param args: arguments to be handled @type args: list of strings @return: list of options @rtype: dict """ options = { 'in_file': None, 'base_name': None, 'update_mappings': True, 'base_meta_cat': None, 'batch_label': None } smvk_options = { 'metadata_file': None, 'archive_file': None, } for arg in pywikibot.handle_args(args): option, sep, value = arg.partition(':') if option == '-metadata_file': smvk_options['metadata_file'] = \ common.convert_from_commandline(value) elif option == '-archive_file': smvk_options['archive_file'] = common.convert_from_commandline( value) elif option == '-base_name': options['base_name'] = common.convert_from_commandline(value) elif option == '-update_mappings': options['update_mappings'] = common.interpret_bool(value) elif option == '-base_meta_cat': options['base_meta_cat'] = common.convert_from_commandline( value) elif option == '-batch_label': options['batch_label'] = common.convert_from_commandline(value) if smvk_options['metadata_file'] and smvk_options['archive_file']: options['in_file'] = \ (smvk_options['metadata_file'], smvk_options['archive_file']) options['base_name'] = options.get('base_name') or path.join( path.split(smvk_options['metadata_file'])[0], BASE_NAME) # main handles the case of missing in_files return options
def handle_args(args, usage): """ Parse and load all of the basic arguments. Also passes any needed arguments on to pywikibot and sets any defaults. :param args: arguments to be handled :return: dict of options """ expected_args = ('api_key', 'all_slides', 'glam_code', 'harvest_log_file', 'harvest_file', 'settings_file', 'verbose', 'cutoff', 'folder_id', 'cache') options = {} for arg in pywikibot.handle_args(args): option, sep, value = arg.partition(':') if option == '-verbose': options['verbose'] = common.interpret_bool(value) elif option == '-cutoff': options['cutoff'] = int(value) elif option == '-cache': options['cache'] = common.interpret_bool(value) elif option.startswith('-') and option[1:] in expected_args: options[option[1:]] = common.convert_from_commandline(value) else: pywikibot.output(usage) exit() return options
def handle_args(args, usage): """ Parse and load all of the basic arguments. Also passes any needed arguments on to pywikibot and sets any defaults. :param args: arguments to be handled :return: dict of options """ options = {} arg_counter = 0 arg_map = [ 'orig_data_file', 'orig_archive_file', 'dupe_data_file', 'dupe_archive_file' ] for arg in pywikibot.handle_args(args): option, sep, value = arg.partition(':') if not sep: # unlabeled argument. options[arg_map[arg_counter]] = option arg_counter += 1 elif option.startswith('-') and option[1:] in DEFAULT_OPTIONS.keys(): options[option[1:]] = common.convert_from_commandline(value) else: pywikibot.output(usage) exit() if arg_counter not in (0, 4): pywikibot.error( 'Either all filenames are passed as unlabeled arguments or none.') return options
def convertFromCommandline(s): """ Convert a string read from the commandline to a standard unicode format. @param s: string to convert @return: str """ return common.convert_from_commandline(s)
def main(*args): """Command line entry-point.""" usage = u'Usage:\n' \ u'\tpython py_Uploader.py -path:<1> -cutoff:<2> -chunked:<3> -verbose:<4>\n' \ u'\tpath: the relative path to the directory containing ' \ u'images and descriptions.\n' \ u'\tcutoff is optional and allows the upload to stop after ' \ u'the specified number of files.\n' \ u'\tchunked is optional and allows the upload to be run without ' \ u'chunked uploading if given "False" or "F".\n' \ u'\tchatty is optional and allows the upload to be more chatty ' \ u'if given "True" or "T".' path = None cutoff = None chunked = True verbose = False # Load pywikibot args and handle local args for arg in pywikibot.handle_args(args): option, sep, value = arg.partition(':') if option == '-path': path = common.convert_from_commandline(value) elif option == '-cutoff': cutoff = int(value) elif option == '-chunked': if value.lower() in ('false', 'f'): chunked = False elif value.lower() not in ('true', 't'): pywikibot.output(usage) elif option == '-chatty': if value.lower() in ('true', 't'): verbose = True elif value.lower() not in ('false', 'f'): pywikibot.output(usage) elif option == '-usage': pywikibot.output(usage) return if path: uploader.up_all(path, cutoff=cutoff, chunked=chunked, verbose=verbose) else: pywikibot.output(usage)
def handle_args(args, usage): """ Parse and load all of the basic arguments. Also passes any needed arguments on to pywikibot and sets any defaults. :param args: arguments to be handled :return: dict of options """ options = {} for arg in pywikibot.handle_args(args): option, sep, value = arg.partition(':') if option.startswith('-') and option[1:] in DEFAULT_OPTIONS.keys(): options[option[1:]] = common.convert_from_commandline(value) else: pywikibot.output(usage) exit() return options