/stdhome

To get this branch, use:
bzr branch http://bzr.ed.am/stdhome

« back to all changes in this revision

Viewing changes to lib/stdhome/vcs/bzr.py

  • Committer: Tim Marston
  • Date: 2014-02-26 19:10:31 UTC
  • Revision ID: tim@ed.am-20140226191031-elcqy5j09h2syn2j
moved copy-in, copy-out and deployment conflict checking to a set of "walkers";
bzr vcs back-end now parses affected files during update; deployment state now
includes affected files

Show diffs side-by-side

added added

removed removed

21
21
 
22
22
import subprocess, os, re, shutil
23
23
from subprocess import Popen
24
 
import stdhome.the as the
25
24
import StringIO
26
 
 
27
 
 
28
 
class VcsBzr:
 
25
from vcs import Vcs
 
26
from stdhome import the
 
27
 
 
28
 
 
29
class VcsBzr( Vcs ):
29
30
 
30
31
 
31
32
        def __init__( self, dir ):
55
56
                        except OSError:
56
57
                                pass
57
58
 
58
 
                        raise the.program.FatalError( 'bzr init failed', output )
 
59
                        raise self.VcsError( 'bzr init failed', output )
59
60
 
60
61
 
61
62
        def checkout( self, url ):
79
80
                        except OSError:
80
81
                                pass
81
82
 
82
 
                        raise the.program.FatalError( 'bzr checkout failed', output )
 
83
                        raise self.VcsError( 'bzr checkout failed', output )
83
84
 
84
85
 
85
86
        def revert( self ):
91
92
                                   stdout = subprocess.PIPE, stderr = subprocess.STDOUT )
92
93
                output = p.communicate()[ 0 ]
93
94
                if p.returncode > 0:
94
 
                        raise the.program.FatalError( 'bzr revert failed', output )
 
95
                        raise self.VcsError( 'bzr revert failed', output )
95
96
 
96
97
                # bzr st
97
98
                p = Popen( [ 'bzr', 'st' ], cwd = self.dir,
98
99
                                   stdout = subprocess.PIPE, stderr = subprocess.STDOUT )
99
100
                output = p.communicate()[ 0 ]
100
101
                if p.returncode > 0:
101
 
                        raise the.program.FatalError( 'bzr status failed', output )
 
102
                        raise self.VcsError( 'bzr status failed', output )
102
103
                files = self.parse_file_blocks( output )
103
104
 
104
105
                # remove unknown files
114
115
 
115
116
 
116
117
        def update( self ):
117
 
                """Update the branch, pulling down any upstream changes and merging them.
 
118
                """Update the branch, pulling down any upstream changes and merging them.  This
 
119
                method returns a list of the files that were modified as part of this
 
120
                operation.
118
121
                """
119
122
 
120
123
                # bzr update
122
125
                                   stdout = subprocess.PIPE, stderr = subprocess.STDOUT )
123
126
                output = p.communicate()[ 0 ]
124
127
                if p.returncode > 0:
125
 
                        raise the.program.FatalError( 'bzr update failed', output )
 
128
                        raise self.VcsError( 'bzr update failed', output )
 
129
 
 
130
                # parse output (see logic in report() in bzrlib/delta.py)
 
131
                files = list()
 
132
                buf = StringIO.StringIO( output )
 
133
                for line in buf:
 
134
                        if not re.search( '^[-R+ ?][K NMD!][* ] ', line ): continue
 
135
                        line = line.rstrip()
 
136
                        if the.verbose: print '  %s' % line
 
137
 
 
138
                        # renames show before and after file names
 
139
                        matches = re.search( '^R.. (.*?)[/@+]? => (.*?)[/@+]?$', line )
 
140
                        if matches:
 
141
                                files.append( matches.group( 1 ) )
 
142
                                files.append( matches.group( 2 ) )
 
143
                                continue
 
144
 
 
145
                        # kind changes shows the same name twice
 
146
                        matches = re.search( '^.K. (.*?)[/@+]? => (.*?)[/@+]?$', line )
 
147
                        if matches:
 
148
                                files.append( matches.group( 1 ) )
 
149
                                continue
 
150
 
 
151
                        # other entries have only one filename
 
152
                        matches = re.search( '^... (.*?)[/@+]?$', line )
 
153
                        if matches:
 
154
                                files.append( matches.group( 1 ) )
 
155
                                continue
 
156
 
 
157
                        raise RuntimeError(
 
158
                                'failed to parse bzr update output line:\n%' % line )
 
159
 
 
160
                return files
126
161
 
127
162
 
128
163
        def has_changes( self ):
134
169
                                   stdout = subprocess.PIPE, stderr = subprocess.STDOUT )
135
170
                output = p.communicate()[ 0 ]
136
171
                if p.returncode > 0:
137
 
                        raise the.program.FatalError( 'bzr status failed', output )
 
172
                        raise self.VcsError( 'bzr status failed', output )
138
173
                files = self.parse_file_blocks( output )
139
174
                return True if len( files ) else False
140
175
 
148
183
                                   stdout = subprocess.PIPE, stderr = subprocess.STDOUT )
149
184
                output = p.communicate()[ 0 ]
150
185
                if p.returncode > 0:
151
 
                        raise the.program.FatalError( 'bzr status failed', output )
 
186
                        raise self.VcsError( 'bzr status failed', output )
152
187
                files = self.parse_file_blocks( output )
153
188
                return files['conflicts'] if 'conflicts' in files else None
154
189