[Zope-CVS] SVN: zpkgtools/trunk/zpkgtools/ try to be better behaved on Windows, avoiding the os.spawnlp() function

Fred L. Drake, Jr. fdrake at gmail.com
Mon Aug 22 17:42:42 EDT 2005


Log message for revision 38026:
  try to be better behaved on Windows, avoiding the os.spawnlp() function
  (it does not exist on Windows)
  

Changed:
  U   zpkgtools/trunk/zpkgtools/app.py
  U   zpkgtools/trunk/zpkgtools/cvsloader.py
  U   zpkgtools/trunk/zpkgtools/runlog.py

-=-
Modified: zpkgtools/trunk/zpkgtools/app.py
===================================================================
--- zpkgtools/trunk/zpkgtools/app.py	2005-08-22 21:13:49 UTC (rev 38025)
+++ zpkgtools/trunk/zpkgtools/app.py	2005-08-22 21:42:41 UTC (rev 38026)
@@ -308,9 +308,12 @@
         pwd = os.getcwd()
         os.chdir(self.tmpdir)
         cmdline = ("tar", "czf", self.target_file, self.target_name)
+        # The os.spawn?p*() functions are not available on Windows, so
+        # we need to search the PATH ourselves:
+        cmdpath = runlog.find_command(cmdline[0])
         runlog.report_command(" ".join(cmdline))
         try:
-            rc = os.spawnlp(os.P_WAIT, cmdline[0], *cmdline)
+            rc = os.spawnv(os.P_WAIT, cmdpath, cmdline)
         finally:
             os.chdir(pwd)
         runlog.report_exit_code(rc)

Modified: zpkgtools/trunk/zpkgtools/cvsloader.py
===================================================================
--- zpkgtools/trunk/zpkgtools/cvsloader.py	2005-08-22 21:13:49 UTC (rev 38025)
+++ zpkgtools/trunk/zpkgtools/cvsloader.py	2005-08-22 21:42:41 UTC (rev 38026)
@@ -289,14 +289,15 @@
         # separated out from load() to ease testing the rest of load()
         # XXX not sure of a good way to test this method!
         wf = posixpath.basename(path)
+        cmdline = ("cvs", "-f", "-Q", "-z6", "-d", cvsroot,
+                   "export", "-kk", "-d", wf, "-r", tag, path)
         pwd = os.getcwd()
         os.chdir(workdir)
-        cmdline = ("cvs", "-f", "-Q", "-z6", "-d", cvsroot,
-                   "export", "-kk", "-d", wf, "-r", tag, path)
 
+        cmdpath = runlog.find_command(cmdline[0])
         runlog.report_command(" ".join(cmdline))
         try:
-            rc = os.spawnlp(os.P_WAIT, cmdline[0], *cmdline)
+            rc = os.spawnv(os.P_WAIT, cmdpath, cmdline)
         finally:
             os.chdir(pwd)
         runlog.report_exit_code(rc)

Modified: zpkgtools/trunk/zpkgtools/runlog.py
===================================================================
--- zpkgtools/trunk/zpkgtools/runlog.py	2005-08-22 21:13:49 UTC (rev 38025)
+++ zpkgtools/trunk/zpkgtools/runlog.py	2005-08-22 21:42:41 UTC (rev 38026)
@@ -54,3 +54,31 @@
     f = sys._getframe(2)
     name = f.f_globals.get("__name__", "<unknown>")
     return logging.getLogger(name)
+
+
+# Since the os.spawn?p*() functions are not available on Windows, we
+# need to search the PATH for the desired executable ourselves.  This
+# function is called to do that, and tries to mimic the platform
+# algorithm to determine whether the executable is found.
+
+if sys.platform[:3].lower() == "win":
+    def find_command(name):
+        # This list of defaults was found at:
+        # http://www.computerhope.com/starthlp.htm
+        exts = os.environ.get("PATHEXT", ".COM;.EXE;.BAT;.CMD").splits(";")
+        for i, ext in enumerate(exts):
+            if not ext.startswith("."):
+                exts[i] = "." + ext
+        for p in os.environ.get("PATH").split(os.path.pathsep):
+            for ext in exts:
+                fn = os.path.join(p, name + ext)
+                if os.path.isfile(fn):
+                    return fn
+        raise ValueError("could not locate matching command: %s" % name)
+else:
+    def find_command(name):
+        for p in os.environ.get("PATH").split(os.path.pathsep):
+            fn = os.path.join(p, name)
+            if os.path.isfile(fn):
+                return fn
+        raise ValueError("could not locate matching command: %s" % name)



More information about the Zope-CVS mailing list