def ask_for_dir(message, default=None, error=None, required=False, level=1): """ Ask user for a directory location """ f = Files({}) folder = input(message) if folder == '': if default != None: folder = default elif required: if level < max_tries: folder = ask_for_dir(message, default=default, error=error, required=required, level=level+1) else: exit(error) else: return folder = abspath(f.clean_path(folder)) return folder
def parse_args(): """ Setup argument parsing and parse the arguments """ username = os.environ.get('USER') # Setup parser and groups parser = argparse.ArgumentParser(description='ARM Processing Manager') ui_flags = parser.add_mutually_exclusive_group() stage_type = parser.add_mutually_exclusive_group() # Setup positional arguments parser.add_argument('command', help='Which of the APM stages to run: stage, rename, process, review, remove, archive, cleanup') # Demo options parser.add_argument('--demo', help='Prep for different stages of a demo, available options include: remove, archive, cleanup') # Date parser.add_argument('-b', '--begin', type=int, default=0, help='Format: YYYYMMDD - date to start processing data') parser.add_argument('-e', '--end', type=int, default=0, help='Format:YYYYMMDD - date to stop processing data') # SIF/Datastreams parser.add_argument('-s', '--site', help='The site the data is from') parser.add_argument('-i', '--instrument', help='The instrument used to collect the data') parser.add_argument('-f', '--facility', help='The facility where the instrument is located') parser.add_argument('-d', '--datastream', nargs='+', help='One or more datastream patterns. "%%" and "*" can be used as wildcards.') # Job parser.add_argument('-j', '--job', required=True, help='DQR # for job') # Alias parser.add_argument('-a', '--alias', help='An alias for the Ingest to use to connect to the database. Def: apm') # Flow control flags parser.add_argument('--stage', help='Specify a staging directory') parser.add_argument('--source', help='Specify a source directory') parser.add_argument('--no-rename', action='store_false', help='Do not strip the ARM prefix from the files') parser.add_argument('--no-db-up', action='store_false', help='Do not update the config database') parser.add_argument('--no-compare', action='store_false', help='Do not compare the ingest output for re-archiving') # Other parser.add_argument('--ingest-flags', nargs='+', help='Flags you want APM to pass to the INGEST. Ex. --ingest-flags F (Do not use "-F" APM will add the "-") (Will apply to all ingests if running for multiple datastreams)') # Ingest Vs Vap stage_type.add_argument('--ingest', action='store_true', help='Ingest vs. VAP (default)') stage_type.add_argument('--vap', action='store_true', help='VAP vs. Ingest') # UI Flags ui_flags.add_argument('-I', '--interactive', action='store_true', help='Prompt for various inputs') ui_flags.add_argument('-q', '--quiet', action='store_true', help='Suppresses prompts and exits gracefully if unable to run') ui_flags.add_argument('-D', '--devel', action='store_true', help='Run APM in development mode') # Parse the args arguments = parser.parse_args() if (arguments.ingest == False) and (arguments.vap == False): arguments.ingest = True args = { 'command': arguments.command, 'demo': arguments.demo, 'begin': arguments.begin, 'end': arguments.end, 'site': arguments.site, 'instrument': arguments.instrument, 'facility': arguments.facility, 'datastream': arguments.datastream, 'duplicates': False, 'job': arguments.job, 'alias': arguments.alias, 'stage': arguments.stage, 'source': arguments.source, 'rename': arguments.no_rename, 'db_up': arguments.no_db_up, 'compare': arguments.no_compare, 'iflags': arguments.ingest_flags, 'ingest': arguments.ingest, 'vap': arguments.vap, 'interactive': arguments.interactive, 'quiet': arguments.quiet, 'devel': arguments.devel, 'username': username, 'exit': False, "cleanup_status": { "review": { "status": True, }, "remove": { "status": False, "deletion_list": False, "archive_list": False, "files_bundled": False, }, "archive": { "status": False, "files_deleted": False, "move_files": False, "files_released": False, }, "cleanup": { "status": False, "files_archived": False, "files_cleaned_up": False, }, } } f = Files(args) if args['stage'] != None: temp = f.clean_path(args['stage']) args['stage'] = abspath(temp) if args['source'] != None: temp = f.clean_path(args['source']) args['source'] = abspath(temp) return args