Esempio n. 1
0
    def __init__(self, argv, logger):
        # Get argv into variables and make am object for all of it
        pp = ABCFactory.get('PreParser')(argv, logger)
        self.settings = pp.get_settings()
        self._populate_settings()
        self.logger = logger

        proc = ABCFactory.get('Processor')(self.settings, self.logger)
        # Make calls into the Processor. This is where magic happens...
        logger.debug("parse_settings()")
        proc.parse_settings()

        logger.debug("parse_orgs()")
        proc.parse_orgs(self.iter_orgs())

        logger.debug("parse_persons()")
        proc.parse_persons(self.iter_persons())

        logger.debug("parse_groups()")
        proc.parse_groups(self.iter_groups())

        logger.debug("parse_relations()")
        proc.parse_relations(self.iter_relations())

        logger.debug("close()")
        proc.close()
Esempio n. 2
0
 def get_groups_from_xml(self, abc_filename):
     xmliter = ABCFactory.get('EntityIterator')(abc_filename, 'group')
     g_parser = ABCFactory.get('GroupParser')(xmliter)
     ret = []
     tmp_name = school = year = fk = nk = ""
     for group in g_parser:
         nk = group._ids.values()[0]
         fk = group._ids.keys()[0]
         school, year, tmp_name = nk.split(':', 2)
         if tmp_name == "":
             logger.warn("Invalid name for group (%s):%s" % (fk, school))
             continue
         if fk == 'GRP_ID_FGOM':
             logger.debug("Skipping, group %s not relevant for Fronter",
                          tmp_name)
             continue
         if re.search('pupil', tmp_name) or re.search('employee', tmp_name):
             logger.debug("Pupil/employee group (%s):%s, skipping",
                          fk, school)
             continue
         write_name = school + ':' + tmp_name
         tmp = {'g_type': fk,
                'g_name': write_name}
         ret.append(tmp)
     return ret
Esempio n. 3
0
 def get_groups_from_xml(self, abc_filename):
     xmliter = ABCFactory.get('EntityIterator')(abc_filename, 'group')
     g_parser = ABCFactory.get('GroupParser')(xmliter)
     ret = []
     tmp_name = school = year = fk = nk = ""
     for group in g_parser:
         nk = group._ids.values()[0]
         fk = group._ids.keys()[0]
         school, year, tmp_name = nk.split(':', 2)
         if tmp_name == "":
             logger.warn("Invalid name for group (%s):%s" % (fk, school))
             continue
         if fk == 'GRP_ID_FGOM':
             logger.debug("Skipping, group %s not relevant for Fronter",
                          tmp_name)
             continue
         if re.search('pupil', tmp_name) or re.search('employee', tmp_name):
             logger.debug("Pupil/employee group (%s):%s, skipping",
                          fk, school)
             continue
         write_name = school + ':' + tmp_name
         tmp = {'g_type': fk,
                'g_name': write_name}
         ret.append(tmp)
     return ret
Esempio n. 4
0
 def __init__(self, settings, logger):
     self.sett = settings
     self.db = Factory.get('Database')()
     self.co = Factory.get('Constants')(self.db)
     self._o2c = ABCFactory.get('Object2Cerebrum')(
         abcconf.SOURCE['source_system'], logger)
     self.logger = logger
Esempio n. 5
0
    def __init__(self, argv, logger):
        self.short_args = 'hdf:'
        self.long_args = ['help', 'dru-run', 'file=']

        self.logger = logger

        filename = dryrun = None
        try:
            opts, args = getopt.getopt(argv,
                                       self.short_args,
                                       self.long_args)
        except getopt.GetoptError as e:
            self.logger.warning(e)
            self.usage(1)

        for opt, val in opts:
            if opt in ('-h', '--help'):
                self.usage()
            elif opt in ('-d', '--dry-run'):
                dryrun = True
            elif opt in ('-f', '--file='):
                filename = val
        if filename is None:
            # TBD: let config decide? Set a default?
            self.usage(1)
        self.settings = ABCFactory.get('Settings')()
        self.settings.set('filename', filename)
        self.settings.set('dryrun', dryrun)
Esempio n. 6
0
 def __init__(self, settings, logger):
     self.sett = settings
     self.db = Factory.get('Database')()
     self.co = Factory.get('Constants')(self.db)
     self._o2c = ABCFactory.get('Object2Cerebrum')(
         abcconf.SOURCE['source_system'], logger)
     self.logger = logger
Esempio n. 7
0
    def next(self):
        """Return the next DataOU object. Returns a ABCTypesError
        exception if object has errors in types. These objects should be
        skipped.

        Consume the next XML-element describing an organization, and
        return a suitable representation (DataOU).
        """

        # This call with propagate StopIteration when all the (XML) elements
        # are exhausted.
        element = super(XMLOrg2Object, self).next()
        result = DataOU()

        # Iterate over *all* subelements
        for sub in element:
            value = None
            if sub.text:
                value = sub.text.strip().encode("latin1")
            if sub.tag == "orgid":
                if len(sub.attrib) != 1:
                    raise ABCTypesError, "wrong number of arguments: %s" % value
                type = sub.attrib.get("orgidtype")
                result.add_id(ABCTypes.get_type("orgidtype", (type, )), value)
            elif sub.tag == "orgname":
                if len(sub.attrib) != 2:
                    raise ABCTypesError, "not 2 attributes: %s" % value
                type = sub.attrib.get("orgnametype")
                # TODO: support lang
                lang = sub.attrib.get("lang")
                result.add_name(ABCTypes.get_type("orgnametype", (type, )),
                                value)
            elif sub.tag == "realm":
                result.realm = value
            elif sub.tag == "address":
                if len(sub.attrib) != 1:
                    raise ABCTypesError, "error in address: %s" % value
                type = sub.attrib.get("addresstype")
                addr_type = ABCTypes.get_type("addresstype",
                                              ("organization", type))
                result.add_address(addr_type, self._make_address(sub))
            elif sub.tag == "contactinfo":
                if len(sub.attrib) != 1:
                    raise ABCTypesError, "error in contact: %s" % value
                if not sub.text:
                    continue
                type = sub.attrib.get("contacttype")
                result.add_contact(
                    ABCTypes.get_type("contacttype", (
                        "organization",
                        type,
                    )), value)
            elif sub.tag == "ou" and result.ou is None:
                # Rather tricky. We have to represent the trailing OUs with
                # something. Returning an iterator seems viable.
                result.ou = ABCFactory.get('OUParser')(iter(
                    element.getiterator("ou")))

        return result
Esempio n. 8
0
    def next(self):
        """Return the next DataOU object. Returns a ABCTypesError
        exception if object has errors in types. These objects should be
        skipped.

        Consume the next XML-element describing an organization, and
        return a suitable representation (DataOU).
        """

        # This call with propagate StopIteration when all the (XML) elements
        # are exhausted.
        element = super(XMLOrg2Object, self).next()
        result = DataOU()

        # Iterate over *all* subelements
        for sub in element:
            value = None
            if sub.text:
                value = sub.text.strip()
            if sub.tag == "orgid":
                if len(sub.attrib) != 1:
                    raise ABCTypesError(
                        "wrong number of arguments: {}".format(value))
                _type = sub.attrib.get("orgidtype")
                result.add_id(ABCTypes.get_type("orgidtype", (_type,)),
                              value)
            elif sub.tag == "orgname":
                if len(sub.attrib) != 2:
                    raise ABCTypesError("not 2 attributes: {}".format(value))
                _type = sub.attrib.get("orgnametype")
                result.add_name(ABCTypes.get_type("orgnametype", (_type,)),
                                value)
            elif sub.tag == "realm":
                result.realm = value
            elif sub.tag == "address":
                if len(sub.attrib) != 1:
                    raise ABCTypesError("error in address: {}".format(value))
                _type = sub.attrib.get("addresstype")
                addr_type = ABCTypes.get_type("addresstype",
                                              ("organization", _type))
                result.add_address(addr_type, self._make_address(sub))
            elif sub.tag == "contactinfo":
                if len(sub.attrib) != 1:
                    raise ABCTypesError("error in contact: {}".format(value))
                if not sub.text:
                    continue
                _type = sub.attrib.get("contacttype")
                result.add_contact(ABCTypes.get_type("contacttype",
                                                     ("organization", _type,)),
                                   value)
            elif sub.tag == "ou" and result.ou is None:
                # Rather tricky. We have to represent the trailing OUs with
                # something. Returning an iterator seems viable.
                result.ou = ABCFactory.get('OUParser')(
                    iter(element.getiterator("ou")))

        return result
Esempio n. 9
0
class ABCPreParser:
    """Class for parsing opts"""

    # TBD: make a pool of arguments different classes commit
    # parameters to? ex: Let properties-module issue warnings instead
    # of errors on config/file mimatch on a given parameter.

    def __init__(self, argv, logger):
        self.short_args = 'hdf:'
        self.long_args = ['help', 'dru-run', 'file=']

        self.logger = logger
        
        filename = dryrun = None
        verbose = False
        try:
            opts, args = getopt.getopt(argv,
                                       self.short_args,
                                       self.long_args)
        except getopt.GetoptError, e:
            self.logger.warning(e)
            self.usage(1)
            
        for opt, val in opts:
            if opt in ('-h', '--help'):
                self.usage()
            elif opt in ('-d', '--dry-run'):
                dryrun = True
            elif opt in ('-f', '--file='):
                filename = val
        if filename == None:
            # TBD: let config decide? Set a default?
            self.usage(1)
        self.settings = ABCFactory.get('Settings')()
        self.settings.set('filename', filename)
        self.settings.set('dryrun', dryrun)
Esempio n. 10
0
 def _get_iterator(self, element):
     return iter(ABCFactory.get('EntityIterator')(
         self.settings.variables['filename'],
         element))
Esempio n. 11
0
 def iter_groups(self):
     elem = "group"
     it = ABCFactory.get('EntityIterator')(self.settings.variables['filename'],
                                           elem)
     return ABCFactory.get('GroupParser')(iter(it))
Esempio n. 12
0
 def iter_relations(self):
     elem = "relation"
     it = ABCFactory.get('EntityIterator')(self.settings.variables['filename'],
                                           elem)
     return ABCFactory.get('RelationParser')(iter(it))
Esempio n. 13
0
 def iter_relations(self):
     return ABCFactory.get('RelationParser')(
         self._get_iterator("relation"))
Esempio n. 14
0
 def iter_groups(self):
     return ABCFactory.get('GroupParser')(
         self._get_iterator("group"))
Esempio n. 15
0
 def iter_orgs(self):
     return ABCFactory.get('OrgParser')(
         self._get_iterator("organization"))
Esempio n. 16
0
 def iter_persons(self):
     return ABCFactory.get('PersonParser')(
         self._get_iterator("person"))
Esempio n. 17
0
 def iter_orgs(self):
     elem = "organization"
     it = ABCFactory.get('EntityIterator')(self.settings.variables['filename'],
                                           elem)
     return ABCFactory.get('OrgParser')(iter(it))
def main():
    logger = Factory.get_logger("cronjob")
    ABCFactory.get('Analyzer')(sys.argv[1:], logger)
Esempio n. 19
0
 def iter_properties(self):
     return ABCFactory.get('PropertiesParser')(
         self._get_iterator("properties"))
Esempio n. 20
0
 def iter_properties(self):
     elem = "properties"
     it = ABCFactory.get('EntityIterator')(self.settings.variables['filename'],
                                           elem)
     return ABCFactory.get('PropertiesParser')(iter(it))