def setup(self, app_args): # basic arguments for every node basic_args = [Argument(Keys.INPUT, KeyHelp.INPUT, default=''), Argument(Keys.OUTPUT, KeyHelp.OUTPUT, default=''), Argument(Keys.MODULE, KeyHelp.MODULE, default=''), Argument(Keys.LOG_LEVEL, KeyHelp.LOG_LEVEL, default="DEBUG")] # Fixme: Prettify WORKDIR creation system # WORKDIR: if WORKDIR is defined add related args for i, arg in enumerate(app_args): if arg.name == Keys.WORKDIR: app_args.insert(i + 1, Argument(Keys.BASEDIR, KeyHelp.BASEDIR, default='.')) app_args.insert(i + 2, Argument(Keys.JOB_ID, KeyHelp.JOB_ID, default='')) app_args.insert(i + 3, Argument(Keys.SUBJOBLIST, KeyHelp.SUBJOBLIST, default='')) app_args.insert(i + 4, Argument(Keys.NAME, KeyHelp.NAME, default=self.__class__.__name__)) break defaults, cliargs = parse_sysargs(basic_args + app_args) # construct info from defaults < info < commandlineargs ih = get_handler(cliargs.get(Keys.INPUT, None)) fileinfo = ih.read(cliargs.get(Keys.INPUT, None)) info = dicts.merge(cliargs, dicts.merge(fileinfo, defaults)) # setup logging log = Logger.create(info[Keys.LOG_LEVEL]) # request by malars: show dataset prominent in logger if Keys.DATASET_CODE in info: if not isinstance(info[Keys.DATASET_CODE], list): if Keys.MZXML in info and not isinstance(info[Keys.MZXML], list): log.info("Dataset is %s (%s)" % (info[Keys.DATASET_CODE], os.path.basename(info[Keys.MZXML]))) else: log.info("Dataset is %s" % info[Keys.DATASET_CODE]) else: log.debug("Datasets are %s" % info[Keys.DATASET_CODE]) # WORKDIR: create WORKDIR (only after mk log) info = dirs.create_workdir(log, info) # filter to requested args if Keys.ALL_ARGS in info: # if ALL_ARGS is set give whole info to app... req_info = info else: req_info = {} # ...otherwise copy only explicitly requested args to app for key in [arg.name for arg in basic_args + app_args]: if key in info: req_info[key] = info[key] log.debug("info for app: %s" % req_info) return log, req_info, info
def test1_arg_priority(self): """Test the argument priorities. Disabled.""" sys.argv = ['--INPUT', 'fcuk.ini', '--OUTPUT', 'kufc.ini'] # basic arguments for every node basic_args = [ Argument(Keys.INPUT, KeyHelp.INPUT, default=''), Argument(Keys.OUTPUT, KeyHelp.OUTPUT, default=''), Argument(Keys.MODULE, KeyHelp.MODULE, default=''), Argument(Keys.LOG_LEVEL, KeyHelp.LOG_LEVEL, default="DEBUG") ] # WORKDIR: if WORKDIR is defined add related args app_args = [] for i, arg in enumerate(app_args): if arg.name == Keys.WORKDIR: app_args.insert( i + 1, Argument(Keys.BASEDIR, KeyHelp.BASEDIR, default='.')) app_args.insert( i + 2, Argument(Keys.JOB_ID, KeyHelp.JOB_ID, default='')) app_args.insert( i + 3, Argument(Keys.SUBJOBLIST, KeyHelp.SUBJOBLIST, default='')) app_args.insert( i + 4, Argument(Keys.NAME, KeyHelp.NAME, default=self.__class__.__name__)) break blub = basic_args + app_args defaults, cliargs = parse_sysargs(blub) # construct info from defaults < info < commandlineargs inifile = cliargs.get(Keys.INPUT, None) info_fh = get_handler(inifile) fileinfo = info_fh.read(inifile) info = dicts.merge(cliargs, dicts.merge(fileinfo, defaults)) # request by malars: show dataset prominent in logger if Keys.DATASET_CODE in info: if not isinstance(info[Keys.DATASET_CODE], list): if Keys.MZXML in info and not isinstance( info[Keys.MZXML], list): logging.info("Dataset is %s (%s)", info[Keys.DATASET_CODE], os.path.basename(info[Keys.MZXML])) else: logging.info("Dataset is %s", info[Keys.DATASET_CODE]) else: logging.debug("Datasets are %s", info[Keys.DATASET_CODE])
def test1_arg_priority(self): return sys.argv = [ '--INPUT', 'fcuk.ini', '--OUTPUT', 'kufc.ini'] # basic arguments for every node basic_args = [Argument(Keys.INPUT, KeyHelp.INPUT, default=''), Argument(Keys.OUTPUT, KeyHelp.OUTPUT, default=''), Argument(Keys.MODULE, KeyHelp.MODULE, default=''), Argument(Keys.LOG_LEVEL, KeyHelp.LOG_LEVEL, default="DEBUG")] # Fixme: Prettify WORKDIR creation system # WORKDIR: if WORKDIR is defined add related args app_args = [] for i, arg in enumerate(app_args): if arg.name == Keys.WORKDIR: app_args.insert(i + 1, Argument(Keys.BASEDIR, KeyHelp.BASEDIR, default='.')) app_args.insert(i + 2, Argument(Keys.JOB_ID, KeyHelp.JOB_ID, default='')) app_args.insert(i + 3, Argument(Keys.SUBJOBLIST, KeyHelp.SUBJOBLIST, default='')) app_args.insert(i + 4, Argument(Keys.NAME, KeyHelp.NAME, default=self.__class__.__name__)) break blub = basic_args + app_args defaults, cliargs = parse_sysargs(blub) # construct info from defaults < info < commandlineargs inifile = cliargs.get(Keys.INPUT, None) ih = get_handler(inifile) fileinfo = ih.read(inifile) info = dicts.merge(cliargs, dicts.merge(fileinfo, defaults)) # setup logging log = Logger.create(info[Keys.LOG_LEVEL]) # request by malars: show dataset prominent in logger if Keys.DATASET_CODE in info: if not isinstance(info[Keys.DATASET_CODE], list): if Keys.MZXML in info and not isinstance(info[Keys.MZXML], list): log.info("Dataset is %s (%s)" % (info[Keys.DATASET_CODE], os.path.basename(info[Keys.MZXML]))) else: log.info("Dataset is %s" % info[Keys.DATASET_CODE]) else: log.debug("Datasets are %s" % info[Keys.DATASET_CODE])
def setup(self, app_args): # basic arguments for every node basic_args = [ Argument(Keys.INPUT, KeyHelp.INPUT, default=''), Argument(Keys.OUTPUT, KeyHelp.OUTPUT, default=''), Argument(Keys.MODULE, KeyHelp.MODULE, default=''), Argument(Keys.LOG_LEVEL, KeyHelp.LOG_LEVEL, default="INFO") ] # WORKDIR: if WORKDIR is defined add related args for i, arg in enumerate(app_args): if arg.name == Keys.WORKDIR: app_args.insert( i + 1, Argument(Keys.BASEDIR, KeyHelp.BASEDIR, default='.')) app_args.insert( i + 2, Argument(Keys.JOB_ID, KeyHelp.JOB_ID, default='')) app_args.insert( i + 3, Argument(Keys.SUBJOBLIST, KeyHelp.SUBJOBLIST, default='')) app_args.insert( i + 4, Argument(Keys.NAME, KeyHelp.NAME, default=self.__class__.__name__)) break defaults, cliargs = parse_sysargs(basic_args + app_args) # construct info from defaults < info < commandlineargs infh = get_handler(cliargs.get(Keys.INPUT, None)) fileinfo = infh.read(cliargs.get(Keys.INPUT, None)) info = dicts.merge(cliargs, dicts.merge(fileinfo, defaults)) # request by malars: show dataset prominent in logger if Keys.DATASET_CODE in info: if not isinstance(info[Keys.DATASET_CODE], list): if Keys.MZXML in info and not isinstance( info[Keys.MZXML], list): logging.info("Dataset is %s (%s)", info[Keys.DATASET_CODE], os.path.basename(info[Keys.MZXML])) else: logging.info("Dataset is %s", info[Keys.DATASET_CODE]) else: logging.debug("Datasets are %s", info[Keys.DATASET_CODE]) # WORKDIR: create WORKDIR (only after mk) info = dirs.create_workdir(info) # filter to requested args if Keys.ALL_ARGS in info: # if ALL_ARGS is set give whole info to app... req_info = info else: req_info = {} # ...otherwise copy only explicitly requested args to app for key in [arg.name for arg in basic_args + app_args]: if key in info: req_info[key] = info[key] logging.debug("info for app: %s", req_info) return req_info, info
def test_parse_args(cls): """Test to parse arguments.""" sys.argv = ['--INPUT', 'fcuk.ini', '--OUTPUT', 'kufc.ini'] defaults, cliargs = parse_sysargs([]) print(defaults) print(cliargs)
def test_parseArgs(self): sys.argv = [ '--INPUT', 'fcuk.ini', '--OUTPUT', 'kufc.ini'] defaults, cliargs = parse_sysargs([]) print cliargs;