r919 - /zope-common/trunk/dzhandle

bzed-guest at users.alioth.debian.org bzed-guest at users.alioth.debian.org
Tue Jul 3 18:30:56 UTC 2007


Author: bzed-guest
Date: Tue Jul  3 18:30:55 2007
New Revision: 919

URL: http://svn.debian.org/wsvn/pkg-zope/?sc=1&rev=919
Log:
first UNTESTED try to fix #431484

Modified:
    zope-common/trunk/dzhandle

Modified: zope-common/trunk/dzhandle
URL: http://svn.debian.org/wsvn/pkg-zope/zope-common/trunk/dzhandle?rev=919&op=diff
==============================================================================
--- zope-common/trunk/dzhandle (original)
+++ zope-common/trunk/dzhandle Tue Jul  3 18:30:55 2007
@@ -131,7 +131,7 @@
             continue
         try:
             key, value = [field.strip() for field in line.split(':', 1)]
-	    if value.count('#') > 0: value = value.split('#')[0].strip()
+            if value.count('#') > 0: value = value.split('#')[0].strip()
         except:
             raise DZError, "error reading %s\n\t%s" % (fn, line)
         if attrs.has_key(key):
@@ -1868,6 +1868,19 @@
         # manage addons
         # self.write_dzfile()
 
+    def set_zope_user(self, zopeuser):
+        if len(zopeuser) != 2:
+            raise ValueError, "Zope-User: `%s' is not in 'user:group' format" % ':'.join(zopeuser)
+        try:
+            pwd.getpwnam(zopeuser[0])
+        except KeyError:
+            raise ValueError, "unknown username `%s' in Zope-User option" % zopeuser[0]
+        try:
+            grp.getgrnam(zopeuser[1])
+        except KeyError:
+            raise ValueError, "unknown groupname `%s' in Zope-User option" % zopeuser[1]
+        self.zope_user = zopeuser
+
     def set_restart_policy(self, policy):
         if policy in (None, 'configuring', 'end', 'manually'):
             self.restart_policy = policy
@@ -1905,21 +1918,28 @@
 
         try:
             self.set_addon_mode(attrs['Addon-Mode'])
-        except ValueError:
+        except ValueError, msg:
             raise DZError, \
-                  "unknown addon mode `%s' in `%s'" % (attrs['Addon-Mode'], fn)
+                  "%s in `%s'" % (msg, fn)
 
         try:
             self.set_restart_policy(attrs['Restart-Policy'])
         except KeyError:
             pass
         except ValueError, msg:
-            raise DZError, "%s in `%s'" % (attrs['Restart-Policy'], fn)
+            raise DZError, "%s in `%s'" % (msg, fn)
 
         try:
             self.excluded_addons = attrs['Excluded-Addons'].split()
         except KeyError:
             pass
+
+        try:
+            self.set_zope_user(attrs['Zope-User'].split(':'))
+        except KeyError:
+            self.zope_user = None
+        except ValueError, msg:
+            raise DZError, "%s in `%s'" % (msg, fn)
 
         if attrs['Name'] != self.name:
             raise DZError, "instance name `%s' doesn't match in `%s'" % (attrs['Name'], fn)
@@ -1939,6 +1959,8 @@
                  }
         if self.excluded_addons:
             attrs['Excluded-Addons'] = ' '.join(self.excluded_addons)
+        if self.zope_user:
+            attrs['Zope-User'] = ':'.join(self.zope_user)
         write_config_file(fn, attrs, uid=uid, gid=gid)
 
     def installed_addons(self):
@@ -1947,6 +1969,13 @@
         return self._installed_addons
 
     def add_addon(self, addon, global_options, addon_technique=None):
+        if self.zope_user:
+            uid = self.zope_user[0]
+            gid = self.zope_user[1]
+        else:
+            uid = uid=global_options.uid
+            gid = global_options.gid
+
         installed = [a for a in self.installed_addons() if addon.name == a.name]
         if installed:
             a = installed[0]
@@ -1977,12 +2006,12 @@
                 print "linked: %s -> %s" % (target_path, addon.path)
         elif addon_technique == ADDON_TREELINKED:
             copytree(addon.path, target_path, copy_all=False,
-                     uid=global_options.uid, gid=global_options.gid)
+                     uid=uid, gid=gid)
             if global_options.verbose:
                 print "tree linked: %s -> %s" % (target_path, addon.path)
         elif addon_technique == ADDON_COPIED:
             copytree(addon.path, target_path, copy_all=True,
-                     uid=global_options.uid, gid=global_options.gid)
+                     uid=uid, gid=gid)
             if global_options.verbose:
                 print "copied: %s -> %s" % (addon.path, target_path)
 




More information about the pkg-zope-commits mailing list