Exemple #1
0
    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):
        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])