Changeset 393 in tailor for vcpx/monotone.py


Ignore:
Timestamp:
07/03/05 19:13:06 (8 years ago)
Author:
lele@…
Hash name:
20050703171306-97f81-11c9593de1896089b8be2153d79f4656276e3d86
Message:

Transition to a Python 2.4 subprocess compatible way of executing external tools
The shwrap module now makes use of the new subprocess module available
with Python 2.4; under older snakes it uses an almost compatible module,
_process.py. This does not bring in any new functionality, it should just
make it easier to port the tool under other OS, and hopefully use a less
hackish way of doing the task.

BEWARE: even if I did several round trips over the various backends, there
may still be bugs in the way I translated the external commands.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vcpx/monotone.py

    r390 r393  
    1212__docformat__ = 'reStructuredText' 
    1313 
    14 from shwrap import SystemCommand, shrepr, ReopenableNamedTemporaryFile 
     14from shwrap import ExternalCommand, PIPE, ReopenableNamedTemporaryFile 
    1515from source import UpdatableSourceWorkingDir, \ 
    1616     ChangesetApplicationFailure, GetUpstreamChangesetsFailure 
     
    1818from sys import stderr 
    1919 
    20 class MonotoneCommit(SystemCommand): 
    21     COMMAND = "monotone commit --author=\"%(key)s\" --date=\"%(date)s\" --message-file=\"%(logfile)s\" 2>&1" 
    22  
    23     def __call__(self, output=None, dry_run=False, **kwargs): 
    24  
    25         # the log message is written on a temporary file 
    26         rontf = ReopenableNamedTemporaryFile('mtn', 'tailor') 
    27         logmessage = kwargs.get('logmessage') 
    28         if logmessage: 
    29             log = open(rontf.name, "w") 
    30             log.write(logmessage) 
    31             log.close()             
    32         kwargs['logfile'] = rontf.name 
    33  
    34         return SystemCommand.__call__(self, output=output, 
    35                                       dry_run=dry_run, **kwargs) 
    36  
    37 class MonotoneRemove(SystemCommand): 
    38     COMMAND = "monotone drop %(entry)s" 
    39  
    40  
    41 class MonotoneMv(SystemCommand): 
    42     COMMAND = "monotone rename %(old)s %(new)s" 
    43  
     20MONOTONE_CMD = "monotone" 
    4421 
    4522class MonotoneWorkingDir(SyncronizableTargetWorkingDir): 
     
    5229        """ 
    5330 
    54         c = SystemCommand(working_dir=root, command="monotone add %(names)s") 
    55         c(names=' '.join([shrepr(n) for n in names])) 
     31        cmd = [MONOTONE_CMD, "add"] 
     32        add = ExternalCommand(cwd=root, command=cmd) 
     33        add.execute(names) 
    5634 
    5735    def _commit(self,root, date, author, remark, changelog=None, entries=None): 
     
    6038        """ 
    6139 
    62         c = MonotoneCommit(working_dir=root) 
     40        rontf = ReopenableNamedTemporaryFile('mtn', 'tailor') 
     41        log = open(rontf.name, "w") 
     42        log.write(remark) 
     43        log.write('\n') 
     44        if changelog: 
     45            log.write(changelog) 
     46            log.write('\n') 
     47        log.close() 
     48 
     49        cmd = [MONOTONE_CMD, "commit", "--author", author, 
     50               "--date", date.isoformat(), 
     51               "--message-file", rontf.name] 
     52        commit = ExternalCommit(cwd=root, command=cmd) 
    6353         
    64         if entries: 
    65             entries = ' '.join([shrepr(e) for e in entries]) 
    66         else: 
    67             entries = '.' 
     54        if not entries: 
     55            entries = ['.'] 
    6856 
    69         # monotone doesn't like empty changelogs ... 
    70         if changelog == None or len(changelog)<1: 
    71             if len(remark)>0: 
    72                 changelog = remark 
    73             else: 
    74                 changelog = "**** empty log message ****" 
    75          
    76         # monotone dates must be expressed as ISO8601  
    77         outstr = c(output=True, key=author, logmessage=changelog, 
    78                    date=date.isoformat(), entries=entries) 
     57        output = commit.execute(entries, stdout=PIPE) 
    7958 
    8059        # monotone complaints if there are no changes from the last commit. 
    8160        # we ignore those errors ... 
    82         if c.exit_status: 
    83            if outstr.getvalue().find("monotone: misuse: no changes to commit") == -1: 
    84                stderr.write(outstr.getvalue()) 
    85                outstr.close() 
    86                raise TargetInitializationFailure( 
    87                   "'monotone commit returned %s" % c.exit_status) 
    88            else: 
    89                stderr.write("No changes to commit - changeset ignored\n") 
    90               
    91         outstr.close()       
     61        if commit.exit_status: 
     62            text = output.read() 
     63            if text.find("monotone: misuse: no changes to commit") == -1: 
     64                stderr.write(text) 
     65                raise TargetInitializationFailure( 
     66                    "%s returned status %s" % (str(commit),commit.exit_status)) 
     67            else: 
     68                stderr.write("No changes to commit - changeset ignored\n") 
    9269         
    9370    def _removePathnames(self, root, names): 
     
    9673        """ 
    9774 
    98         c = MonotoneRemove(working_dir=root) 
    99         c(entry=' '.join([shrepr(n) for n in names])) 
     75        cmd = [MONOTONE_CMD, "drop"] 
     76        drop = ExternalCommand(cwd=root, command=cmd) 
     77        drop.execute(names) 
    10078 
    10179    def _renamePathname(self, root, oldname, newname): 
     
    10482        """ 
    10583 
    106         c = MonotoneMv(working_dir=root) 
    107         c(old=shrepr(oldname), new=shrepr(newname)) 
     84        cmd = [MONOTONE_CMD, "rename"] 
     85        rename = ExternalCommand(cwd=root, command=cmd) 
     86        rename.execute(oldname, newname) 
    10887 
    10988    def _initializeWorkingDir(self, root, repository, module, subdir): 
     
    122101            raise TargetInitializationFailure("Please setup '%s' as a monotone working directory" % root) 
    123102 
    124         c = SystemCommand(working_dir=root, 
    125                           command="monotone add %(names)s") 
    126         c(names=subdir) 
     103        self._addPathnames(root, [subdir]) 
Note: See TracChangeset for help on using the changeset viewer.