def __init__(self, args):
        """ Initialize configuration object, typically reading from wclfile """

        WCL.__init__(self)

        # data which needs to be kept across programs must go in self
        # data which needs to be searched also must go in self
        self.set_search_order(PFW_SEARCH_ORDER)

        wclobj = WCL()
        if 'wclfile' in args:
            if miscutils.fwdebug_check(3, 'PFWCONFIG_DEBUG'):
                miscutils.fwdebug_print("Reading wclfile: %s" % (args['wclfile']))
            try:
                starttime = time.time()
                print "\tReading submit wcl...",
                with open(args['wclfile'], "r") as wclfh:
                    wclobj.read(wclfh, filename=args['wclfile'])
                print "DONE (%0.2f secs)" % (time.time()-starttime)
                #wclobj['wclfile'] = args['wclfile']
            except IOError as err:
                miscutils.fwdie("Error: Problem reading wcl file '%s' : %s" % \
                                (args['wclfile'], err), pfwdefs.PF_EXIT_FAILURE)

        # location of des services file
        if 'submit_des_services' in args and args['submit_des_services'] is not None:
            wclobj['submit_des_services'] = args['submit_des_services']
        elif 'submit_des_services' not in wclobj:
            if 'DES_SERVICES' in os.environ:
                wclobj['submit_des_services'] = os.environ['DES_SERVICES']
            else:
                # let it default to $HOME/.desservices.init
                wclobj['submit_des_services'] = None

        # which section to use in des services file
        if 'submit_des_db_section' in args and args['submit_des_db_section'] is not None:
            wclobj['submit_des_db_section'] = args['submit_des_db_section']
        elif 'submit_des_db_section' not in wclobj:
            if 'DES_DB_SECTION' in os.environ:
                wclobj['submit_des_db_section'] = os.environ['DES_DB_SECTION']
            else:
                # let DB connection code print error message
                wclobj['submit_des_db_section'] = None

        # for values passed in on command line, set top-level config
        for var in (pfwdefs.PF_DRYRUN, pfwdefs.PF_VERIFY_FILES):
            if var in args and args[var] is not None:
                wclobj[var] = args[var]

        if 'usePFWconfig' in args:
            pfwconfig = os.environ['PROCESSINGFW_DIR'] + '/etc/pfwconfig.des'
            if miscutils.fwdebug_check(3, 'PFWCONFIG_DEBUG'):
                miscutils.fwdebug_print("Reading pfwconfig: %s" % (pfwconfig))
            starttime = time.time()
            print "\tReading config from software install...",
            pfwcfg_wcl = WCL()
            with open(pfwconfig, "r") as wclfh:
                pfwcfg_wcl.read(wclfh, filename=pfwconfig)
            self.update(pfwcfg_wcl)
            print "DONE (%0.2f secs)" % (time.time()-starttime)

        # wclfile overrides all, so must be added last
        if 'wclfile' in args:
            if miscutils.fwdebug_check(3, 'PFWCONFIG_DEBUG'):
                miscutils.fwdebug_print("Reading wclfile: %s" % (args['wclfile']))
            self.update(wclobj)

        self.set_names()

        # store the file name of the top-level submitwcl in dict:
        if 'submitwcl' not in self and 'wclfile' in args:
            self['submitwcl'] = args['wclfile']

        if 'processingfw_dir' not in self and \
           'PROCESSINGFW_DIR' in os.environ:
            self['processingfw_dir'] = os.environ['PROCESSINGFW_DIR']

        if 'current' not in self:
            self['current'] = OrderedDict({'curr_block': '',
                                           'curr_archive': '',
                                           #'curr_software': '',
                                           'curr_site' : ''})
            self[pfwdefs.PF_WRAPNUM] = '0'
            self[pfwdefs.PF_TASKNUM] = '0'
            self[pfwdefs.PF_JOBNUM] = '0'

        self.set_block_info()
Exemple #2
0
    def __init__(self, args):
        """ Initialize configuration object, typically reading from wclfile """

        WCL.__init__(self)

        # data which needs to be kept across programs must go in self
        # data which needs to be searched also must go in self
        self.set_search_order(PFW_SEARCH_ORDER)

        wclobj = WCL()
        if 'wclfile' in args:
            if miscutils.fwdebug_check(3, 'PFWCONFIG_DEBUG'):
                miscutils.fwdebug_print(f"Reading wclfile: {args['wclfile']}")
            try:
                starttime = time.time()
                print("\tReading submit wcl...", )
                with open(args['wclfile'], "r") as wclfh:
                    wclobj.read(wclfh, filename=args['wclfile'])
                print(f"DONE ({time.time()-starttime:0.2f} secs)")
                #wclobj['wclfile'] = args['wclfile']
            except IOError as err:
                miscutils.fwdie(
                    f"Error: Problem reading wcl file '{args['wclfile']}' : {err}",
                    pfwdefs.PF_EXIT_FAILURE)

        # location of des services file
        if 'submit_des_services' in args and args[
                'submit_des_services'] is not None:
            wclobj['submit_des_services'] = args['submit_des_services']
        elif 'submit_des_services' not in wclobj:
            if 'DES_SERVICES' in os.environ:
                wclobj['submit_des_services'] = os.environ['DES_SERVICES']
            else:
                # let it default to $HOME/.desservices.init
                wclobj['submit_des_services'] = None

        # which section to use in des services file
        if 'submit_des_db_section' in args and args[
                'submit_des_db_section'] is not None:
            wclobj['submit_des_db_section'] = args['submit_des_db_section']
        elif 'submit_des_db_section' not in wclobj:
            if 'DES_DB_SECTION' in os.environ:
                wclobj['submit_des_db_section'] = os.environ['DES_DB_SECTION']
            else:
                # let DB connection code print error message
                wclobj['submit_des_db_section'] = None

        # for values passed in on command line, set top-level config
        for var in (pfwdefs.PF_DRYRUN, pfwdefs.PF_USE_DB_IN,
                    pfwdefs.PF_USE_DB_OUT, pfwdefs.PF_USE_QCF,
                    pfwdefs.PF_VERIFY_FILES):
            if var in args and args[var] is not None:
                wclobj[var] = args[var]

        if 'usePFWconfig' in args:
            pfwconfig = os.environ['PROCESSINGFW_DIR'] + '/etc/pfwconfig.des'
            if miscutils.fwdebug_check(3, 'PFWCONFIG_DEBUG'):
                miscutils.fwdebug_print(f"Reading pfwconfig: {pfwconfig}")
            starttime = time.time()
            print("\tReading config from software install...")
            pfwcfg_wcl = WCL()
            with open(pfwconfig, "r") as wclfh:
                pfwcfg_wcl.read(wclfh, filename=pfwconfig)
            self.update(pfwcfg_wcl)
            print(f"DONE ({time.time()-starttime:0.2f} secs)")

        self.use_db_in = None
        if pfwdefs.PF_USE_DB_IN in wclobj:
            self.use_db_in = miscutils.convertBool(
                wclobj[pfwdefs.PF_USE_DB_IN])
        elif pfwdefs.PF_USE_DB_IN in self:
            self.use_db_in = miscutils.convertBool(self[pfwdefs.PF_USE_DB_IN])

        if self.use_db_in and 'get_db_config' in args and args['get_db_config']:
            print("\tGetting defaults from DB...")
            sys.stdout.flush()
            starttime = time.time()
            self.dbh = pfwdb.PFWDB(wclobj['submit_des_services'],
                                   wclobj['submit_des_db_section'])
            print(f"DONE ({time.time()-starttime:0.2f} secs)")
            self.update(self.dbh.get_database_defaults())
        else:
            self.dbh = None

        # wclfile overrides all, so must be added last
        if 'wclfile' in args:
            if miscutils.fwdebug_check(3, 'PFWCONFIG_DEBUG'):
                miscutils.fwdebug_print(f"Reading wclfile: {args['wclfile']}")
            self.update(wclobj)

        self.set_names()

        # store the file name of the top-level submitwcl in dict:
        if 'submitwcl' not in self and 'wclfile' in args:
            self['submitwcl'] = args['wclfile']

        if 'processingfw_dir' not in self and \
           'PROCESSINGFW_DIR' in os.environ:
            self['processingfw_dir'] = os.environ['PROCESSINGFW_DIR']

        if 'current' not in self:
            self['current'] = collections.OrderedDict({
                'curr_block': '',
                'curr_archive': '',
                #'curr_software': '',
                'curr_site': ''
            })
            self[pfwdefs.PF_WRAPNUM] = '0'
            self[pfwdefs.PF_BLKNUM] = '1'
            self[pfwdefs.PF_TASKNUM] = '0'
            self[pfwdefs.PF_JOBNUM] = '0'

        if pfwdefs.SW_BLOCKLIST in self:
            block_array = miscutils.fwsplit(self[pfwdefs.SW_BLOCKLIST])
            if int(self[pfwdefs.PF_BLKNUM]) <= len(block_array):
                self.set_block_info()