Example #1
0
 def test_configuration(self):
     with open(self.file_unicode, 'w') as config:
         config.write("Hello { World 1; };")
     apt_pkg.read_config_file(apt_pkg.config, self.file_bytes)
     apt_pkg.read_config_file(apt_pkg.config, self.file_unicode)
     apt_pkg.read_config_file_isc(apt_pkg.config, self.file_bytes)
     apt_pkg.read_config_file_isc(apt_pkg.config, self.file_unicode)
     apt_pkg.read_config_dir(apt_pkg.config, self.dir_unicode)
     apt_pkg.read_config_dir(apt_pkg.config, b"/etc/apt/apt.conf.d")
Example #2
0
 def test_configuration(self):
     with open(self.file_unicode, 'w') as config:
         config.write("Hello { World 1; };")
     apt_pkg.read_config_file(apt_pkg.config, self.file_bytes)
     apt_pkg.read_config_file(apt_pkg.config, self.file_unicode)
     apt_pkg.read_config_file_isc(apt_pkg.config, self.file_bytes)
     apt_pkg.read_config_file_isc(apt_pkg.config, self.file_unicode)
     apt_pkg.read_config_dir(apt_pkg.config, self.dir_unicode)
     apt_pkg.read_config_dir(apt_pkg.config, b"/etc/apt/apt.conf.d")
Example #3
0
def which_conf_file ():
    if os.getenv('DAK_CONFIG'):
        return os.getenv('DAK_CONFIG')

    res = socket.getfqdn()
    # In case we allow local config files per user, try if one exists
    if Cnf.find_b("Config::" + res + "::AllowLocalConfig"):
        homedir = os.getenv("HOME")
        confpath = os.path.join(homedir, "/etc/dak.conf")
        if os.path.exists(confpath):
            apt_pkg.read_config_file_isc(Cnf,confpath)

    # We are still in here, so there is no local config file or we do
    # not allow local files. Do the normal stuff.
    if Cnf.get("Config::" + res + "::DakConfig"):
        return Cnf["Config::" + res + "::DakConfig"]

    return default_config
Example #4
0
def which_conf_file ():
    if os.getenv('DAK_CONFIG'):
        return os.getenv('DAK_CONFIG')

    res = socket.getfqdn()
    # In case we allow local config files per user, try if one exists
    if Cnf.find_b("Config::" + res + "::AllowLocalConfig"):
        homedir = os.getenv("HOME")
        confpath = os.path.join(homedir, "/etc/dak.conf")
        if os.path.exists(confpath):
            apt_pkg.read_config_file_isc(Cnf,confpath)

    # We are still in here, so there is no local config file or we do
    # not allow local files. Do the normal stuff.
    if Cnf.get("Config::" + res + "::DakConfig"):
        return Cnf["Config::" + res + "::DakConfig"]

    return default_config
Example #5
0
File: config.py Project: evgeni/dak
    def _readconf(self):
        apt_pkg.init()

        self.Cnf = apt_pkg.Configuration()

        apt_pkg.read_config_file_isc(self.Cnf, which_conf_file())

        # Check whether our dak.conf was the real one or
        # just a pointer to our main one
        res = socket.gethostbyaddr(socket.gethostname())
        conffile = self.Cnf.get("Config::" + res[0] + "::DakConfig")
        if conffile:
            apt_pkg.read_config_file_isc(self.Cnf, conffile)

        # Rebind some functions
        # TODO: Clean this up
        self.get = self.Cnf.get
        self.subtree = self.Cnf.subtree
        self.value_list = self.Cnf.value_list
        self.find = self.Cnf.find
        self.find_b = self.Cnf.find_b
Example #6
0
File: config.py Project: abhi11/dak
    def _readconf(self):
        apt_pkg.init()

        self.Cnf = apt_pkg.Configuration()

        apt_pkg.read_config_file_isc(self.Cnf, which_conf_file())

        # Check whether our dak.conf was the real one or
        # just a pointer to our main one
        res = socket.gethostbyaddr(socket.gethostname())
        conffile = self.Cnf.get("Config::" + res[0] + "::DakConfig")
        if conffile:
            apt_pkg.read_config_file_isc(self.Cnf, conffile)

        # Read group-specific options
        if 'ByGroup' in self.Cnf:
            bygroup = self.Cnf.subtree('ByGroup')
            groups = set([os.getgid()])
            groups.update(os.getgroups())

            for group in bygroup.list():
                gid = grp.getgrnam(group).gr_gid
                if gid in groups:
                    if bygroup.get(group):
                        apt_pkg.read_config_file_isc(self.Cnf, bygroup[group])
                    break

        # Rebind some functions
        # TODO: Clean this up
        self.get = self.Cnf.get
        self.subtree = self.Cnf.subtree
        self.value_list = self.Cnf.value_list
        self.find = self.Cnf.find
        self.find_b = self.Cnf.find_b
        self.find_i = self.Cnf.find_i
Example #7
0
    def _readconf(self):
        apt_pkg.init()

        self.Cnf = apt_pkg.Configuration()

        apt_pkg.read_config_file_isc(self.Cnf, which_conf_file())

        # Check whether our dak.conf was the real one or
        # just a pointer to our main one
        res = socket.gethostbyaddr(socket.gethostname())
        conffile = self.Cnf.get("Config::" + res[0] + "::DakConfig")
        if conffile:
            apt_pkg.read_config_file_isc(self.Cnf, conffile)

        # Read group-specific options
        if 'ByGroup' in self.Cnf:
            bygroup = self.Cnf.subtree('ByGroup')
            groups = set([os.getgid()])
            groups.update(os.getgroups())

            for group in bygroup.list():
                gid = grp.getgrnam(group).gr_gid
                if gid in groups:
                    if bygroup.get(group):
                        apt_pkg.read_config_file_isc(self.Cnf, bygroup[group])
                    break

        # Rebind some functions
        # TODO: Clean this up
        self.get = self.Cnf.get
        self.subtree = self.Cnf.subtree
        self.value_list = self.Cnf.value_list
        self.find = self.Cnf.find
        self.find_b = self.Cnf.find_b
        self.find_i = self.Cnf.find_i
Example #8
0
# represent object instances and shows how to iterate over the sections.
# Pass it the sample apt-ftparchive configuration,
# doc/examples/ftp-archive.conf
# or a bind8 config file..

import apt_pkg
import sys

ConfigFile = apt_pkg.parse_commandline(apt_pkg.config, [], sys.argv)

if len(ConfigFile) != 1:
    print "Must have exactly 1 file name"
    sys.exit(0)

Cnf = apt_pkg.Configuration()
apt_pkg.read_config_file_isc(Cnf, ConfigFile[0])

# Print the configuration space
#print "The Configuration space looks like:"
#for I in Cnf.keys():
#   print "%s \"%s\";" % (I, Cnf[I])

# bind8 config file..
if "Zone" in Cnf:
    print "Zones: ", Cnf.sub_tree("zone").list()
    for I in Cnf.list("zone"):
        SubCnf = Cnf.sub_tree(I)
        if SubCnf.find("type") == "slave":
            print "Masters for %s: %s" % (
                SubCnf.my_tag(), SubCnf.value_list("masters"))
else:
Example #9
0
# represent object instances and shows how to iterate over the sections.
# Pass it the sample apt-ftparchive configuration,
# doc/examples/ftp-archive.conf
# or a bind8 config file..

import apt_pkg
import sys

ConfigFile = apt_pkg.parse_commandline(apt_pkg.config, [], sys.argv)

if len(ConfigFile) != 1:
    print "Must have exactly 1 file name"
    sys.exit(0)

Cnf = apt_pkg.Configuration()
apt_pkg.read_config_file_isc(Cnf, ConfigFile[0])

# Print the configuration space
#print "The Configuration space looks like:"
#for I in Cnf.keys():
#   print "%s \"%s\";" % (I, Cnf[I])

# bind8 config file..
if "Zone" in Cnf:
    print "Zones: ", Cnf.sub_tree("zone").list()
    for I in Cnf.list("zone"):
        SubCnf = Cnf.sub_tree(I)
        if SubCnf.find("type") == "slave":
            print "Masters for %s: %s" % (SubCnf.my_tag(),
                                          SubCnf.value_list("masters"))
else: