SVN: zdaemon/trunk/src/zdaemon/ also create rundirectory/socketdirectory when configured from config file

Christian Zagrodnick <[email protected]>
Newsgroups gmane.comp.web.zope.zope3.cvs
Message-ID <[email protected]>
Log message for revision 95380:
  also create rundirectory/socketdirectory when configured from config file
  

Changed:
  U   zdaemon/trunk/src/zdaemon/component.xml
  U   zdaemon/trunk/src/zdaemon/tests/testzdrun.py
  U   zdaemon/trunk/src/zdaemon/zdoptions.py

-=-
Modified: zdaemon/trunk/src/zdaemon/component.xml
===================================================================
--- zdaemon/trunk/src/zdaemon/component.xml	2009-01-29 08:09:28 UTC (rev 95379)
+++ zdaemon/trunk/src/zdaemon/component.xml	2009-01-29 08:32:15 UTC (rev 95380)
@@ -78,7 +78,8 @@
       </description>
     </key>
 
-    <key name="socket-name" datatype="existing-dirpath"
+    <key name="socket-name"
+         datatype="zdaemon.zdoptions.existing_parent_dirpath"
          required="no"
          default="zdsock">
       <description>
@@ -113,7 +114,8 @@
       </description>
     </key>
 
-    <key name="directory" datatype="existing-directory"
+    <key name="directory"
+         datatype="zdaemon.zdoptions.existing_parent_directory"
          required="no">
       <description>
         Command-line option: -z or --directory.

Modified: zdaemon/trunk/src/zdaemon/tests/testzdrun.py
===================================================================
--- zdaemon/trunk/src/zdaemon/tests/testzdrun.py	2009-01-29 08:09:28 UTC (rev 95379)
+++ zdaemon/trunk/src/zdaemon/tests/testzdrun.py	2009-01-29 08:32:15 UTC (rev 95380)
@@ -319,6 +319,9 @@
         sys.stdout = StringIO()
         sys.stderr = StringIO()
         self.expect = ''
+        self.cmd = "/bin/true"
+        if not os.path.exists(self.cmd):
+            self.cmd = "/usr/bin/true"  # Mac OS X
 
     def tearDown(self):
         shutil.rmtree(self.root)
@@ -332,23 +335,30 @@
         super(TestRunnerDirectory, self).tearDown()
 
     def run_ctl(self, opts):
-        true_cmd = "/bin/true"
-        if not os.path.exists(true_cmd):
-            true_cmd = "/usr/bin/true"  # Mac OS X
         options = zdctl.ZDCtlOptions()
-        options.realize(opts + ['-p', 'sleep 1', 'fg'])
-        self.expect = 'sleep 1\n'
+        options.realize(opts + ['fg'])
+        self.expect = self.cmd + '\n'
         proc = zdctl.ZDCmd(options)
         proc.onecmd(" ".join(options.args))
 
     def testCtlRunDirectoryCreation(self):
         path = os.path.join(self.root, 'rundir')
-        self.run_ctl(['-z', path])
+        self.run_ctl(['-z', path, '-p', self.cmd])
         self.assert_(os.path.exists(path))
 
+    def testCtlRunDirectoryCreationFromConfigFile(self):
+        path = os.path.join(self.root, 'rundir')
+        options = ['directory ' + path,
+                   'program ' + self.cmd]
+        config = self.writeConfig(
+            '<runner>\n%s\n</runner>' % '\n'.join(options))
+        self.run_ctl(['-C', config])
+        self.assert_(os.path.exists(path))
+
     def testCtlRunDirectoryCreationOnlyOne(self):
         path = os.path.join(self.root, 'rundir', 'not-created')
-        self.assertRaises(SystemExit, self.run_ctl, ['-z', path])
+        self.assertRaises(SystemExit,
+                          self.run_ctl, ['-z', path, '-p', self.cmd])
         self.assertFalse(os.path.exists(path))
         got = sys.stderr.getvalue().strip()
         sys.stderr = StringIO()
@@ -356,19 +366,33 @@
 
     def testCtlSocketDirectoryCreation(self):
         path = os.path.join(self.root, 'rundir', 'sock')
-        self.run_ctl(['-s', path])
+        self.run_ctl(['-s', path, '-p', self.cmd])
         self.assert_(os.path.exists(os.path.dirname(path)))
 
-
     def testCtlSocketDirectoryCreationOnlyOne(self):
         path = os.path.join(self.root, 'rundir', 'not-created', 'sock')
-        self.assertRaises(SystemExit, self.run_ctl, ['-s', path])
+        self.assertRaises(SystemExit,
+                          self.run_ctl, ['-s', path, '-p', self.cmd])
         self.assertFalse(os.path.exists(path))
         got = sys.stderr.getvalue().strip()
         sys.stderr = StringIO()
         self.assertTrue(got.startswith('Error: invalid value for -s'))
 
+    def testCtlSocketDirectoryCreationFromConfigFile(self):
+        path = os.path.join(self.root, 'rundir')
+        options = ['socket-name %s/sock' % path,
+                   'program ' + self.cmd]
+        config = self.writeConfig(
+            '<runner>\n%s\n</runner>' % '\n'.join(options))
+        self.run_ctl(['-C', config])
+        self.assert_(os.path.exists(path))
 
+    def writeConfig(self, config):
+        config_file = os.path.join(self.root, 'config')
+        open(config_file, 'w').write(config)
+        return config_file
+
+
 def send_action(action, sockname):
     """Send an action to the zdrun server and return the response.
 

Modified: zdaemon/trunk/src/zdaemon/zdoptions.py
===================================================================
--- zdaemon/trunk/src/zdaemon/zdoptions.py	2009-01-29 08:09:28 UTC (rev 95379)
+++ zdaemon/trunk/src/zdaemon/zdoptions.py	2009-01-29 08:32:15 UTC (rev 95380)
@@ -403,6 +403,9 @@
 
 def existing_parent_directory(arg):
     path = os.path.expanduser(arg)
+    if os.path.isdir(path):
+        # If the directory exists, that's fine.
+        return path
     parent, tail = os.path.split(path)
     if os.path.isdir(parent):
         return path
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.