Changeset 257


Ignore:
Timestamp:
26-05-07 13:21:34 (6 years ago)
Author:
thomas
Message:

Patch by: Andy Wingo <wingo at pobox dot com>

  • moap/vcs/Makefile.am:
  • moap/vcs/bzr.py (_getoutput, _getstatusoutput, detect, Bzr, Bzr.getNotIgnored, Bzr.ignore, Bzr.commit, Bzr.diff, Bzr.getFileMatcher, Bzr.update): Added Bazaar backend. Fixes #243.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/moap/vcs/bzr.py

    r256 r257  
    88import os 
    99import commands 
    10 import subprocess 
    1110import re 
    1211 
     
    1413from moap.vcs import vcs 
    1514 
    16 def _getoutput(argv): 
    17     return subprocess.Popen(argv, stdout=subprocess.PIPE).communicate()[0] 
    18  
    19 def _getstatusoutput(argv): 
    20     p = subprocess.Popen(argv, stdout=subprocess.PIPE) 
    21     out = p.communicate()[0] 
    22     return p.returncode, out 
    23  
    2415def detect(path): 
    2516    """ 
    26     Detect if the given source tree is using Bzr. 
     17    Detect if the given source tree is using Bazaar. 
    2718 
    28     @return: True if the given path looks like a Bzr tree. 
     19    @return: True if the given path looks like a Bazaar tree. 
    2920    """ 
    3021    while path and path != '/': 
     
    4031 
    4132    def getNotIgnored(self): 
    42         return _getoutput(["bzr", "unknowns"]).split('\n') 
     33        oldPath = os.getcwd() 
     34        os.chdir(self.path) 
     35 
     36        result = commands.getoutput("bzr unknowns").split('\n') 
     37        # one empty line does not a return value make 
     38        if result and result == ['']: 
     39            result = [] 
     40 
     41        os.chdir(oldPath) 
     42        return result 
    4343 
    4444    def ignore(self, paths, commit=True): 
    45         subprocess.call(['bzr', 'ignore'] + list(paths)) 
     45        if not paths: 
     46            return 
     47 
     48        oldPath = os.getcwd() 
     49        os.chdir(self.path) 
     50 
     51        self.debug("Ignoring %d paths" % len(paths)) 
     52 
     53        cmd = "bzr ignore %s" % " ".join(paths) 
     54        self.debug("Running %s" % cmd) 
     55        os.system(cmd) 
     56 
    4657        if commit: 
    47             self.commit([os.path.join(self.path, '.bzrignore'),], 
     58            self.commit([os.path.join(self.path, '.bzrignore'), ], 
    4859                        'moap ignore') 
     60 
     61        os.chdir(oldPath) 
    4962 
    5063    def commit(self, paths, message): 
    5164        try: 
    52             curpath = os.getcwd() 
     65            oldPath = os.getcwd() 
    5366            os.chdir(self.path) 
    54             subprocess.call(['bzr', 'commit', '-m', message] + paths) 
     67            os.system("bzr commit -m \"%s\" %s" % (message, " ".join(paths))) 
    5568        finally: 
    56             os.chdir(curpath) 
     69            os.chdir(oldPath) 
    5770 
    5871    def diff(self, path): 
    59         return _getoutput(['bzr', 'diff']) 
     72        oldPath = os.getcwd() 
     73        os.chdir(path) 
     74 
     75        output = commands.getoutput("bzr diff") 
     76 
     77        os.chdir(oldPath) 
     78        return output 
    6079 
    6180    def getFileMatcher(self): 
     
    6483    def update(self, path): 
    6584        # FIXME: No way to pull just updates to the given path 
    66         status, output = _getstatusoutput(['bzr', 'pull']) 
     85        status, output = commands.getstatusoutput("bzr pull") 
    6786        if status != 0: 
    6887            raise vcs.VCSException(output) 
Note: See TracChangeset for help on using the changeset viewer.