/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:58:26 UTC
  • Revision ID: tim@ed.am-20160522165826-yi3hljqajbvp2par
changed copy base change reporting so that it doesn't silence when verbose
reporting is on

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
                """
317
299
 
318
300
 
319
301
        def run( self, cmd ):
320
 
                if the.verbose >= 2: print('exec: %s' % ' '.join( cmd ))
 
302
                if the.verbose >= 2: print 'exec: %s' % ' '.join( cmd )
321
303
                p = Popen( cmd, cwd = self.dir,
322
304
                                   stdout = subprocess.PIPE, stderr = subprocess.STDOUT )
323
 
                output = p.communicate()[ 0 ].decode()
 
305
                output = p.communicate()[ 0 ]
324
306
                if p.returncode > 0:
325
307
                        raise self.VcsError( ' '.join( cmd[ : 2 ] ), output )
326
308
                if the.verbose >= 2:
327
309
                        verbose_output = output.rstrip()
328
310
                        if len( verbose_output ):
329
 
                                print(re.sub( '(^|\n)', '\\1  : ', verbose_output ))
 
311
                                print re.sub( '(^|\n)', '\\1  : ', verbose_output )
330
312
                return output
331
313
 
332
314
 
333
315
        def parse_file_blocks( self, output ):
334
316
                res = dict()
335
317
                current = None
336
 
                buf = io.StringIO( output )
 
318
                buf = StringIO.StringIO( output )
337
319
                for line in buf:
338
320
                        matches = re.search( '^([a-z ]+):$', line, re.I )
339
321
                        if matches: