Changeset 514 for CMT/HEAD


Ignore:
Timestamp:
Jul 1, 2009, 5:29:45 PM (15 years ago)
Author:
rybkin
Message:

See C.L. 403

Location:
CMT/HEAD
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • CMT/HEAD/ChangeLog

    r513 r514  
     12009-07-01    <rybkin@lal.in2p3.fr> 403
     2       
     3        * mgr/cmt_svn_checkout.py: Introduce a version working on Windows. Do not
     4        use module commands, instead, in class Utils, introduce portable (static)
     5        methods getstatusoutput, getstatuserror, and make use of them
     6       
    172009-06-27    <rybkin@lal.in2p3.fr> 402
    28       
  • CMT/HEAD/mgr/cmt_svn_checkout.py

    r513 r514  
    2323"""
    2424
    25 __version__ = '0.3.0'
    26 __date__ = 'Thu Jun 27 2009'
     25__version__ = '0.4.0'
     26__date__ = 'Wed Jul 01 2009'
    2727__author__ = 'Grigory Rybkin'
    2828
     
    3939            urlparse.uses_netloc.append(p)
    4040import tempfile
    41 import commands
    4241import re
    4342
     
    4948#           % (self, str(e))
    5049#     sys.exit(1)
     50
     51class Utils(object):
     52    def getstatusoutput(cmd):
     53        """Return (status, stdout + stderr) of executing cmd in a shell.
     54       
     55        A trailing line separator is removed from the output string. The exit status of the command is encoded in the format specified for wait(), when the exit status is zero (termination without errors), 0 is returned.
     56        """
     57        p = os.popen('( %s ) 2>&1' % cmd, 'r')
     58        out = p.read()
     59        sts = p.close()
     60        if sts is None: sts = 0
     61        if out.endswith(os.linesep):
     62            out = out[:out.rindex(os.linesep)]
     63        elif out[-1:] == '\n': out = out[:-1]
     64        return sts, out
     65    getstatusoutput = staticmethod(getstatusoutput)
     66   
     67    def getstatuserror(cmd):
     68        """Return (status, stderr) of executing cmd in a shell.
     69       
     70        On Unix, the return value is the exit status of the command is encoded in the format specified for wait(). On Windows, on command.com systems (Windows 95, 98 and ME) this is always 0; on cmd.exe systems (Windows NT, 2000 and XP) this is the exit status of the command run.
     71        """
     72        fd, p = tempfile.mkstemp()
     73        os.close(fd)
     74#        print >> sys.stderr, 'Created file %s with fd %i' % (p, fd)
     75#        p = os.tempnam()
     76#        print >> sys.stderr, 'Created file name %s' % (p)
     77        sc = os.system('( %s ) 2>%s' % (cmd, p))
     78        f = open(p)
     79        e = f.read()
     80        f.close()
     81        os.unlink(p)
     82        return sc, e
     83    getstatuserror = staticmethod(getstatuserror)
    5184
    5285class ClientContext(object):
     
    154187        message = ': '.join([str(arg) for arg in instance.args])
    155188    except AttributeError:
    156         message = instance
     189        message = str(instance).rstrip()
    157190    if location: location += ': '
    158191    print >> file, "%s%s" % (location, message)
     
    302335        cmd = 'svn diff %s %s' % (path1, path2)
    303336#        cmd = 'svn diff --summarize %s %s' % (path1, path2)
    304         sc, out = commands.getstatusoutput(cmd)
     337        sc, out = Utils.getstatusoutput(cmd)
    305338        if sc != 0:
    306339            return 2
     
    341374#        trunk = posixpath.normpath(posixpath.join(module.url, self.trunk))
    342375        cmd = 'svn info %s' % trunk
    343         sc, out = commands.getstatusoutput(cmd)
     376        sc, out = Utils.getstatusoutput(cmd)
    344377        if sc != 0:
    345378            return None
     
    360393#        tags = posixpath.normpath(posixpath.join(module.url, self.tags))
    361394        cmd = 'svn ls -v %s' % tags
    362         sc, out = commands.getstatusoutput(cmd)
     395        sc, out = Utils.getstatusoutput(cmd)
    363396        if sc != 0:
    364397            return None
     
    471504
    472505    def execute(self, cmt_context, client_context):
    473         sc = 0
     506        sce = 0
    474507
    475508        for m in self.modules:
     
    478511            err = []
    479512            for url in m.URL:
    480 #                cmd = 'svn checkout -q %s %s 2>/dev/null' % (url, m.path)
    481                 cmd = 'svn checkout -q %s %s' % (url, m.path)
    482                 sc, e = commands.getstatusoutput(cmd)
    483                 #sc = os.system(cmd)
     513                cmd = 'svn checkout %s %s' % (url, m.path)
     514#                cmd = 'svn checkout -q %s %s' % (url, m.path)
     515                sc, e = Utils.getstatuserror(cmd)
     516#                 cmd = 'svn checkout -q %s %s' % (url, m.path)
     517#                 sc, e = Utils.getstatusoutput(cmd)
    484518                if 0 == sc:
    485519#                 try:
     
    508542#                 print >> sys.stderr, 'Failed to checkout %s into %s.' % \
    509543#                       (' or '.join(m.URL), m.path)
    510                 sc += 1
    511                 continue
     544                sce += 1
    512545
    513546#            print 'Checked out revision %i.' % result_rev
     
    516549                print >> sys.stderr, \
    517550                      '%s %s: configure returned %i.' % (m.path, m.version, scc)
    518             sc += scc
    519 
    520         return sc
     551            sce += scc
     552
     553        return sce
    521554
    522555def main(argv=[__name__]):
Note: See TracChangeset for help on using the changeset viewer.