/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: 2016-05-22 16:45:54 UTC
  • Revision ID: tim@ed.am-20160522164554-n5qhuibvnv0z4tk1
added general reporting to CopyBase and configured it via copy-in and copy-out
walkers (it is required in copy in, during add command); added -R (recursive)
flass to add command; allow vcs backends to augment statically ignored files
list; added detection of out of date working copy to bzr backend;
generate_walk_list() now takes a mandatory directory as the first argument;
don't copy entire subtree during copy of missing directory (as this makes
assumptions about what's in the walk-list)

Show diffs side-by-side

added added

removed removed

19
19
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
20
 
21
21
 
22
 
import io
23
 
import os
24
 
import re
25
 
import shutil
26
 
import subprocess
 
22
import subprocess, os, re, shutil
27
23
from subprocess import Popen
28
 
 
 
24
import StringIO
 
25
from vcs import Vcs
29
26
from stdhome import the
30
27
 
31
 
from .vcs import Vcs
32
 
 
33
28
 
34
29
class BzrVcs( Vcs ):
35
30
 
110
105
                output = self.run( [ 'bzr', 'revno', '--tree' ] )
111
106
 
112
107
                # parse revno
113
 
                buf = io.StringIO( output )
 
108
                buf = StringIO.StringIO( output )
114
109
                return buf.readline().rstrip()
115
110
 
116
111
 
134
129
                                        raise RunTimeError(
135
130
                                                'failed to parse bzr kind change: %s' % file )
136
131
                                file = matches.group( 1 )
137
 
                                if the.verbose >= 2: print("removing (kind changed): " + file)
 
132
                                if the.verbose >= 2: print "removing (kind changed): " + file
138
133
                                full_file = os.path.join( self.dir, file )
139
134
                                if os.path.isfile( full_file ) or os.path.islink( full_file ):
140
135
                                        os.unlink( full_file )
158
153
                                        raise RunTimeError(
159
154
                                                'failed to parse bzr unknowns: %s' % file )
160
155
                                file = matches.group( 1 )
161
 
                                if the.verbose >= 2: print("removing (unknown): " + file)
 
156
                                if the.verbose >= 2: print "removing (unknown): " + file
162
157
                                full_file = os.path.join( self.dir, file )
163
158
                                if os.path.isfile( full_file ) or os.path.islink( full_file ):
164
159
                                        os.unlink( full_file )
224
219
 
225
220
                # parse output (see logic in report() in bzrlib/delta.py)
226
221
                files = list()
227
 
                buf = io.StringIO( output )
 
222
                buf = StringIO.StringIO( output )
228
223
                for line in buf:
229
224
                        if not re.search( '^[-R+ ?][K NMD!][* ] ', line ): continue
230
225
                        line = line.rstrip()
254
249
                return files
255
250
 
256
251
 
257
 
        def status( self ):
258
 
                """Get a list of any local modifications.  This method returns a list of files
259
 
                which are modified.
260
 
 
261
 
                """
262
 
 
263
 
                # bzr status
264
 
                output = self.run( [ 'bzr', 'status', '--no-pending' ] )
265
 
 
266
 
                # parse output
267
 
                return self.parse_file_blocks( output )
268
 
 
269
 
 
270
252
        def has_changes( self ):
271
253
                """Check if the branch has any local modifications.
272
254
                """
308
290
                try:
309
291
                        self.run( [ 'bzr', 'commit', '-m', '' ] )
310
292
                except self.VcsError as e:
311
 
                        if re.search( 'Working tree is out of date', e.output ):
 
293
                        if re.search( '/Working tree is out of date, please/', e.output ):
312
294
                                raise the.program.FatalError(
313
295
                                        'you must update your files first.\n' +
314
296
                                        'Hint: see "%s update --help"' % the.program.name );
315
 
                        else:
316
 
                                raise e
317
297
 
318
298
 
319
299
        def run( self, cmd ):
320
 
                if the.verbose >= 2: print('exec: %s' % ' '.join( cmd ))
 
300
                if the.verbose >= 2: print 'exec: %s' % ' '.join( cmd )
321
301
                p = Popen( cmd, cwd = self.dir,
322
302
                                   stdout = subprocess.PIPE, stderr = subprocess.STDOUT )
323
 
                output = p.communicate()[ 0 ].decode()
 
303
                output = p.communicate()[ 0 ]
324
304
                if p.returncode > 0:
325
305
                        raise self.VcsError( ' '.join( cmd[ : 2 ] ), output )
326
306
                if the.verbose >= 2:
327
307
                        verbose_output = output.rstrip()
328
308
                        if len( verbose_output ):
329
 
                                print(re.sub( '(^|\n)', '\\1  : ', verbose_output ))
 
309
                                print re.sub( '(^|\n)', '\\1  : ', verbose_output )
330
310
                return output
331
311
 
332
312
 
333
313
        def parse_file_blocks( self, output ):
334
314
                res = dict()
335
315
                current = None
336
 
                buf = io.StringIO( output )
 
316
                buf = StringIO.StringIO( output )
337
317
                for line in buf:
338
318
                        matches = re.search( '^([a-z ]+):$', line, re.I )
339
319
                        if matches: