[Zope-CVS] CVS: Packages/zpkgtools/zpkgtools - runlog.py:1.1 app.py:1.40 cvsloader.py:1.18 svnloader.py:1.7

Fred L. Drake, Jr. fred at zope.com
Thu Apr 29 19:20:28 EDT 2004


Update of /cvs-repository/Packages/zpkgtools/zpkgtools
In directory cvs.zope.org:/tmp/cvs-serv15304

Modified Files:
	app.py cvsloader.py svnloader.py 
Added Files:
	runlog.py 
Log Message:
report the external commands we run


=== Added File Packages/zpkgtools/zpkgtools/runlog.py ===
##############################################################################
#
# Copyright (c) 2004 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Utilities to help log running an external command."""

import logging
import os
import sys


def report_command(cmd):
    """Report that we're running an external process.

    :param cmd:  The command line we're going to run.

    """
    logger = get_logger()
    #
    # XXX Using two log entries isn't really the right way to do this,
    # but makes things easier to debug for now.  Not sure how well the
    # log formats deal with multi-line messages, so this suffice.
    #
    logger.debug("running: %s", cmd)
    logger.debug("  (cwd = %s)", os.getcwd())


def report_exit_code(rc):
    """Report the exit code for an external process.

    :param rc:  The return code of the process.

    """
    logger = get_logger()
    logger.debug("exit code: %s", rc)


def get_logger():
    """Return the logger to report with.

    :rtype: logging.Logger

    """
    f = sys._getframe(2)
    name = f.f_globals.get("__name__", "<unknown>")
    return logging.getLogger(name)


=== Packages/zpkgtools/zpkgtools/app.py 1.39 => 1.40 ===
--- Packages/zpkgtools/zpkgtools/app.py:1.39	Wed Apr 28 17:04:47 2004
+++ Packages/zpkgtools/zpkgtools/app.py	Thu Apr 29 19:20:27 2004
@@ -40,7 +40,7 @@
         """Initialize the application based on an options object as
         returned by `parse_args()`.
         """
-        self.logger = logging.getLogger(options.program)
+        self.logger = logging.getLogger(__name__)
         self.options = options
         cf = config.Configuration()
         cf.location_maps.extend(options.location_maps)
@@ -61,7 +61,7 @@
             options.include_support_code = cf.include_support_code
 
     def error(self, message, rc=1):
-        print >>sys.stderr, message
+        self.logger.critical(message)
         sys.exit(rc)
 
 
@@ -497,11 +497,13 @@
         """
         pwd = os.getcwd()
         os.chdir(self.tmpdir)
+        cmdline = ("tar", "cjf", self.target_file, self.target_name)
+        runlog.report_command(" ".join(cmdline))
         try:
-            rc = os.spawnlp(os.P_WAIT, "tar",
-                            "tar", "cjf", self.target_file, self.target_name)
+            rc = os.spawnlp(os.P_WAIT, "tar", *cmdline)
         finally:
             os.chdir(pwd)
+        runlog.report_exit_code(rc)
         if rc:
             self.error("error generating %s" % self.target_file)
         # We have a tarball; clear some space, then copy the tarball


=== Packages/zpkgtools/zpkgtools/cvsloader.py 1.17 => 1.18 ===
--- Packages/zpkgtools/zpkgtools/cvsloader.py:1.17	Tue Apr 27 11:13:52 2004
+++ Packages/zpkgtools/zpkgtools/cvsloader.py	Thu Apr 29 19:20:27 2004
@@ -23,6 +23,7 @@
 import urlparse
 
 from zpkgtools import Error, LoadingError
+from zpkgtools import runlog
 
 
 class CvsLoadingError(LoadingError):
@@ -233,12 +234,16 @@
         wf = posixpath.basename(path)
         pwd = os.getcwd()
         os.chdir(workdir)
+        cmdline = ("cvs", "-f", "-Q", "-z6", "-d", cvsroot,
+                   "export", "-kk", "-d", wf, "-r", tag, path)
+
+        runlog.report_command(" ".join(cmdline))
         try:
-            return os.spawnlp(os.P_WAIT, "cvs",
-                              "cvs", "-f", "-Q", "-z6", "-d", cvsroot,
-                              "export", "-kk", "-d", wf, "-r", tag, path)
+            rc = os.spawnlp(os.P_WAIT, "cvs", *cmdline)
         finally:
             os.chdir(pwd)
+        runlog.report_exit_code(rc)
+        return rc
 
     # XXX CVS does some weird things with export; not sure how much
     # they mean yet.  Note that there's no way to tell if the resource
@@ -280,5 +285,6 @@
     # separate this out to ease testing
 
     def openCvsRLog(self, cvsroot, path):
-        return os.popen(
-            "cvs -f -q -d '%s' rlog -R -l '%s'" % (cvsroot, path), "r")
+        cmd = "cvs -f -q -d '%s' rlog -R -l '%s'" % (cvsroot, path)
+        runlog.report_command(cmd)
+        return os.popen(cmd, "r")


=== Packages/zpkgtools/zpkgtools/svnloader.py 1.6 => 1.7 ===
--- Packages/zpkgtools/zpkgtools/svnloader.py:1.6	Tue Apr 27 15:59:51 2004
+++ Packages/zpkgtools/zpkgtools/svnloader.py	Thu Apr 29 19:20:27 2004
@@ -24,6 +24,7 @@
 import urlparse
 
 from zpkgtools import LoadingError
+from zpkgtools import runlog
 
 
 class SubversionLoadingError(LoadingError):
@@ -225,7 +226,9 @@
 
         """
         # do an "svn cat" to get a file, or learn that this is a directory
-        stdin, stdout, stderr = os.popen3("svn cat '%s'" % url)
+        cmd = "svn cat '%s'" % url
+        runlog.report_command(cmd)
+        stdin, stdout, stderr = os.popen3(cmd)
         data = stdout.read()
         if not data:
             # maybe url referenced a directory
@@ -233,7 +236,10 @@
             if "directory" in err:
                 # it is!
                 target = os.path.join(workdir, "foo")
-                rc = os.system("svn export -q '%s' '%s'" % (url, target))
+                cmd = "svn export -q '%s' '%s'" % (url, target)
+                runlog.report_command(cmd)
+                rc = os.system(cmd)
+                runlog.report_exit_code(rc)
                 if rc != 0:
                     raise SubversionLoadingError(url, rc)
                 return target




More information about the Zope-CVS mailing list