]> git.decadent.org.uk Git - dak.git/commitdiff
daklib/config.py: allow additional configuration files for specific groups
authorAnsgar Burchardt <ansgar@debian.org>
Mon, 17 Sep 2012 13:22:07 +0000 (15:22 +0200)
committerAnsgar Burchardt <ansgar@debian.org>
Mon, 17 Sep 2012 14:21:19 +0000 (16:21 +0200)
daklib/config.py

index c79582c2aceb3add0dbaf7043fc0988da7fc0268..99b84dd605bea42040435c23d8eb177d3f9f1000 100755 (executable)
@@ -28,6 +28,7 @@ Config access class
 
 ################################################################################
 
+import grp
 import os
 import apt_pkg
 import socket
@@ -76,6 +77,19 @@ class Config(object):
         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