예제 #1
0
    def __init__(self, autostud, logger, cfg_file=None, debug=0):
        self.debug = debug
        self.autostud = autostud
        self._logger = logger
        self._errors = []
        self.group_defs = {}
        self.default_values = {}
        self.profiles = []
        self.profilename2profile = {}
        self.required_spread_order = []
        self.lookup_helper = LookupHelper(autostud.db, logger,
                                          autostud.ou_perspective)

        try:
            sp = StudconfigParser(self, cfg_file)
        except:
            if self._errors:
                logger.fatal("Got the following errors, and a stack trace: \n"
                             "{}".format("\n".join(self._errors)))
            raise
        self.spread_defs = [
            int(autostud.co.Spread(x)) for x in sp.legal_spreads.keys()
        ]
        self._post_process_config()
        self.autostud.disk_tool.post_process()
예제 #2
0
    def __init__(self, autostud, logger, cfg_file=None, debug=0):
        self.debug = debug
        self.autostud = autostud
        self._logger = logger
        self._errors = []
        self.group_defs = {}
        self.default_values = {}
        self.profiles = []
        self.profilename2profile = {}
        self.required_spread_order = []
        self.lookup_helper = LookupHelper(autostud.db, logger, autostud.ou_perspective)

        try:
            sp = StudconfigParser(self, cfg_file)
        except:
            if self._errors:
                logger.fatal("Got the following errors, and a stack trace: \n"
                             "{}".format("\n".join(self._errors)))
            raise
        self.spread_defs = [int(autostud.co.Spread(x)) for x in sp.legal_spreads.keys()]
        self._post_process_config()
        self.autostud.disk_tool.post_process()
예제 #3
0
class Config(object):
    def __init__(self, autostud, logger, cfg_file=None, debug=0):
        self.debug = debug
        self.autostud = autostud
        self._logger = logger
        self._errors = []
        self.group_defs = {}
        self.default_values = {}
        self.profiles = []
        self.profilename2profile = {}
        self.required_spread_order = []
        self.lookup_helper = LookupHelper(autostud.db, logger, autostud.ou_perspective)

        try:
            sp = StudconfigParser(self, cfg_file)
        except:
            if self._errors:
                logger.fatal("Got the following errors, and a stack trace: \n"
                             "{}".format("\n".join(self._errors)))
            raise
        self.spread_defs = [int(autostud.co.Spread(x)) for x in sp.legal_spreads.keys()]
        self._post_process_config()
        self.autostud.disk_tool.post_process()

    def _post_process_config(self):
        # Config parsing complete.  Convert config-settings to
        # database references etc.
        profilename2profile = {}
        self.using_priority = False
        for p in self.profiles:
            if profilename2profile.has_key(p.name):
                self.add_error("Duplicate profile-name {}".format(p.name))
            profilename2profile[p.name] = p
            p.post_config(self.lookup_helper, self)
            if p.priority is not None:
                self.using_priority = True
            self.profilename2profile[p.name] = p
        for p in self.profiles:
            p.expand_super(profilename2profile)
            if self.using_priority and p.priority is None:
                self.add_error("Priority used, but not defined for {}".format(
                               p.name))

        self.select_tool = SelectTool(self.profiles, self._logger, self)
        # Change keys in group_defs from name to entity_id
        pg = PosixGroup.PosixGroup(self.autostud.db)
        tmp = {}
        for k in self.group_defs.keys():
            id = self.lookup_helper.get_group(k)
            t = self.group_defs[k]
            try:
                pg.clear()
                pg.find(id)
                t['is_posix'] = True
            except Errors.NotFoundError:
                t['is_posix'] = False
            tmp[id] = t
        self.group_defs = tmp
        if self._errors:
            self._logger.fatal(
                "The configuration file has errors, refusing to "
                "continue: \n{}".format("\n".join(self._errors)))
            sys.exit(1)

    def debug_dump(self):
        ret = "Profile definitions:"
        for p in self.profiles:
            ret += p.debug_dump() + "\n"
        ret += "Select mappings:\n"
        for tag, sm in self.select_tool.select_map_defs.items():
            ret += "  {}\n".format(tag)
            ret += "".join(
                ["    {}\n".format(line for line in repr(sm).split("\n"))]
            )
        return ret

    def add_error(self, msg):
        self._errors.append(msg)
예제 #4
0
class Config(object):
    def __init__(self, autostud, logger, cfg_file=None, debug=0):
        self.debug = debug
        self.autostud = autostud
        self._logger = logger
        self._errors = []
        self.group_defs = {}
        self.default_values = {}
        self.profiles = []
        self.profilename2profile = {}
        self.required_spread_order = []
        self.lookup_helper = LookupHelper(autostud.db, logger, autostud.ou_perspective)

        try:
            sp = StudconfigParser(self, cfg_file)
        except:
            if self._errors:
                logger.fatal("Got the following errors, and a stack trace: \n"
                             "%s" % "\n".join(self._errors))
            raise
        self.spread_defs = [int(autostud.co.Spread(x)) for x in sp.legal_spreads.keys()]
        self._post_process_config()
        self.autostud.disk_tool.post_process()

    def _post_process_config(self):
        # Config parsing complete.  Convert config-settings to
        # database references etc.
        profilename2profile = {}
        self.using_priority = False
        for p in self.profiles:
            if profilename2profile.has_key(p.name):
                self.add_error("Duplicate profile-name %s" % p.name)
            profilename2profile[p.name] = p
            p.post_config(self.lookup_helper, self)
            if p.priority is not None:
                self.using_priority=True
            self.profilename2profile[p.name] = p
        for p in self.profiles:
            p.expand_super(profilename2profile)
            if self.using_priority and p.priority is None:
                self.add_error("Priority used, but not defined for %s" % \
                               p.name)
            
        self.select_tool = SelectTool(self.profiles, self._logger, self)
        # Change keys in group_defs from name to entity_id
        pg = PosixGroup.PosixGroup(self.autostud.db)
        tmp = {}
        for k in self.group_defs.keys():
            id = self.lookup_helper.get_group(k)
            t = self.group_defs[k]
            try:
                pg.clear()
                pg.find(id)
                t['is_posix'] = True
            except Errors.NotFoundError:
                t['is_posix'] = False
            tmp[id] = t
        self.group_defs = tmp
        if self._errors:
            self._logger.fatal("The configuration file has errors, refusing to "
                               "continue: \n%s" % "\n".join(self._errors))
            sys.exit(1)

    def debug_dump(self):
        ret = "Profile definitions:"
        for p in self.profiles:
            ret += p.debug_dump()+"\n"
        ret += "Select mappings:\n"
        for tag, sm in self.select_tool.select_map_defs.items():
            ret += "  %s\n" % tag
            ret += "".join(["    %s\n" % line for line in str(sm).split("\n")])
        return ret

    def add_error(self, msg):
        self._errors.append(msg)