Exemple #1
0
    def __init__(self, config, net=None):
        self._conf = None

        if net is not None and net.find("acl"):
            conffile = net.find("acl").get("file", None)
        elif config.find("acl") is not None:
            conffile = config.find("acl").get("file", None)
        else:
            log.debug("No ACL file to load")
            return

        if conffile is None:
            raise ConfigError("<acl> tag is missing the file attribute!");

        if not os.path.isabs(conffile):
            confdir = config.get('config', None)
            if not confdir:
                log.error("Unable to resolve relative path to ACL")
                return
            confdir = os.path.dirname(confdir)
            conffile = os.path.join(confdir, conffile)

        if not os.access(conffile, os.R_OK):
            raise ConfigError("Cannot read ACL file %s" % conffile);

        log.debug("Loading ACL file %s" % conffile)
        self._conf = ElementTree.parse(conffile)
Exemple #2
0
    def __init__(self, config, net=None):
        self._conf = None

        if net is not None and net.find("acl"):
            conffile = net.find("acl").get("file", None)
        elif config.find("acl") is not None:
            conffile = config.find("acl").get("file", None)
        else:
            log.debug("No ACL file to load")
            return

        if conffile is None:
            raise ConfigError("<acl> tag is missing the file attribute!")

        if not os.path.isabs(conffile):
            confdir = config.get('config', None)
            if not confdir:
                log.error("Unable to resolve relative path to ACL")
                return
            confdir = os.path.dirname(confdir)
            conffile = os.path.join(confdir, conffile)

        if not os.access(conffile, os.R_OK):
            raise ConfigError("Cannot read ACL file %s" % conffile)

        log.debug("Loading ACL file %s" % conffile)
        self._conf = ElementTree.parse(conffile)
Exemple #3
0
def parse_config(path=None, xml=None):
    """Load configuration XML, return the root element"""
    assert not (path and xml)

    from hackabot.etree import ElementTree

    # Assuming the normal svn layout, find the source root
    root = os.path.abspath(__file__).rsplit("/",4)[0]

    defaults = {
        'root': root,
        'perl': "%s/lib/perl" % root,
        'mysql': "%s/lib/mysql" % root,
        'python': "%s/lib/python" % root,
    }

    if path:
        path = os.path.abspath(path)
        try:
            config = ElementTree.parse(path).getroot()
        except IOError, (exno, exstr):
            raise ConfigError("Failed to read %s: %s" % (path, exstr))