Changeset 596 in tailor for vcpx/monotone.py


Ignore:
Timestamp:
08/16/05 22:15:38 (8 years ago)
Author:
R.Ghetta <birrachiara@…>
Hash name:
20050816201538-2c016-42f18a85dee805089e54c56a0acdea806452fc08
Message:

Small improvement to monotone backend

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vcpx/monotone.py

    r594 r596  
    1212__docformat__ = 'reStructuredText' 
    1313 
    14 from shwrap import ExternalCommand, PIPE, ReopenableNamedTemporaryFile 
     14from shwrap import ExternalCommand, PIPE, ReopenableNamedTemporaryFile, STDOUT 
    1515from source import UpdatableSourceWorkingDir, \ 
    1616     ChangesetApplicationFailure, GetUpstreamChangesetsFailure 
    1717from target import SyncronizableTargetWorkingDir, TargetInitializationFailure 
    1818from sys import stderr 
     19from os.path import exists, join, isdir 
     20from os import renames, access, F_OK 
    1921 
    2022class MonotoneWorkingDir(SyncronizableTargetWorkingDir): 
     
    2426    def _addPathnames(self, names): 
    2527        """ 
    26         Add some new filesystem objects. 
     28        Add some new filesystem objects, skipping directories (directory addition is implicit in monotone) 
    2729        """ 
     30        fnames=[] 
     31        for fn in names: 
     32            if isdir(join(self.basedir, fn)): 
     33                self.log_info("ignoring addition of directory '%s' (%s)" % (fn, join(self.basedir, fn)) ); 
     34            else: 
     35                fnames.append(fn) 
    2836 
    2937        cmd = [self.repository.MONOTONE_CMD, "add"] 
    3038        add = ExternalCommand(cwd=self.basedir, command=cmd) 
    31         add.execute(names) 
     39        add.execute(fnames) 
     40        if add.exit_status: 
     41            raise ChangesetApplicationFailure("%s returned status %s" % (str(add),add.exit_status)) 
     42 
     43    def _addSubtree(self, subdir): 
     44        """ 
     45        Add a whole subtree 
     46        """ 
     47        cmd = [self.repository.MONOTONE_CMD, "add"] 
     48        add = ExternalCommand(cwd=self.basedir, command=cmd) 
     49        add.execute(subdir) 
     50        if add.exit_status: 
     51            raise ChangesetApplicationFailure("%s returned status %s" % (str(add),add.exit_status)) 
    3252 
    3353    def _commit(self, date, author, patchname, changelog=None, entries=None): 
     
    6888            text = error.read() 
    6989            if text.find("monotone: misuse: no changes to commit") == -1: 
    70                 stderr.write(text) 
     90                self.log_error(text) 
    7191                raise ChangesetApplicationFailure( 
    7292                    "%s returned status %s" % (str(commit),commit.exit_status)) 
     
    7696    def _removePathnames(self, names): 
    7797        """ 
    78         Remove some filesystem object. 
     98        Remove some filesystem object.  
    7999        """ 
    80100 
     101        # Monotone currently doesn't allow removing a directory, 
     102        # so we must remove every item separately and intercept monotone directory errore messages. 
     103        # We can't just filter the directories, because the wc doesn't contain them anymore ... 
    81104        cmd = [self.repository.MONOTONE_CMD, "drop"] 
    82105        drop = ExternalCommand(cwd=self.basedir, command=cmd) 
    83         drop.execute(names) 
     106        for fn in names: 
     107            dum, error = drop.execute(fn, stderr=PIPE) 
     108            if drop.exit_status: 
     109                if not error.read().find("drop <directory>"): 
     110                    log_error(error.read()) 
     111                    raise ChangesetApplicationFailure("%s returned status %s" % (str(drop),drop.exit_status)) 
    84112 
    85113    def _renamePathname(self, oldname, newname): 
     
    87115        Rename a filesystem object. 
    88116        """ 
    89  
     117        # this function is called *after* the file/dir has changed name, 
     118        # and monotone doesn't like it. 
     119        # we put names back to make it happy ... 
     120        if access(join(self.basedir, newname), F_OK): 
     121            if access(join(self.basedir, oldname), F_OK): 
     122                raise ChangesetApplicationFailure("Can't rename %s to %s. Both names already exist" % (oldname, newname) ) 
     123            renames(join(self.basedir, newname), join(self.basedir, oldname)) 
     124            self.log_info("preparing to rename %s->%s" % (oldname, newname)) 
     125         
    90126        cmd = [self.repository.MONOTONE_CMD, "rename"] 
    91127        rename = ExternalCommand(cwd=self.basedir, command=cmd) 
    92         rename.execute(oldname, newname) 
     128        o1, o2 =rename.execute(oldname, newname, stderr=PIPE) 
     129        stderr.write(o2.read()) 
     130         
     131        # redo the rename ... 
     132        renames(join(self.basedir, oldname), join(self.basedir, newname)) 
     133        if rename.exit_status: 
     134            raise ChangesetApplicationFailure("%s returned status %s" % (str(rename),rename.exit_status)) 
    93135 
    94136    def _initializeWorkingDir(self): 
     
    102144        """ 
    103145 
    104         from os.path import exists, join 
    105  
    106146        if not exists(join(self.basedir, 'MT')): 
    107147            raise TargetInitializationFailure("Please setup '%s' as a monotone working directory" % self.basedir) 
    108148 
    109         self._addPathnames([self.repository.subdir]) 
     149        self._addSubtree([self.repository.subdir]) 
Note: See TracChangeset for help on using the changeset viewer.