/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: 2022-06-27 15:47:18 UTC
  • Revision ID: tim@ed.am-20220627154718-coj4in7pqgl3c8lr
updated Makefile for previous commit

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 subprocess, os, re, shutil
 
22
import io
 
23
import os
 
24
import re
 
25
import shutil
 
26
import subprocess
23
27
from subprocess import Popen
24
 
import StringIO
25
 
from vcs import Vcs
 
28
 
26
29
from stdhome import the
27
30
 
 
31
from .vcs import Vcs
 
32
 
28
33
 
29
34
class BzrVcs( Vcs ):
30
35
 
105
110
                output = self.run( [ 'bzr', 'revno', '--tree' ] )
106
111
 
107
112
                # parse revno
108
 
                buf = StringIO.StringIO( output )
 
113
                buf = io.StringIO( output )
109
114
                return buf.readline().rstrip()
110
115
 
111
116
 
129
134
                                        raise RunTimeError(
130
135
                                                'failed to parse bzr kind change: %s' % file )
131
136
                                file = matches.group( 1 )
132
 
                                if the.verbose >= 2: print "removing (kind changed): " + file
 
137
                                if the.verbose >= 2: print("removing (kind changed): " + file)
133
138
                                full_file = os.path.join( self.dir, file )
134
139
                                if os.path.isfile( full_file ) or os.path.islink( full_file ):
135
140
                                        os.unlink( full_file )
153
158
                                        raise RunTimeError(
154
159
                                                'failed to parse bzr unknowns: %s' % file )
155
160
                                file = matches.group( 1 )
156
 
                                if the.verbose >= 2: print "removing (unknown): " + file
 
161
                                if the.verbose >= 2: print("removing (unknown): " + file)
157
162
                                full_file = os.path.join( self.dir, file )
158
163
                                if os.path.isfile( full_file ) or os.path.islink( full_file ):
159
164
                                        os.unlink( full_file )
219
224
 
220
225
                # parse output (see logic in report() in bzrlib/delta.py)
221
226
                files = list()
222
 
                buf = StringIO.StringIO( output )
 
227
                buf = io.StringIO( output )
223
228
                for line in buf:
224
229
                        if not re.search( '^[-R+ ?][K NMD!][* ] ', line ): continue
225
230
                        line = line.rstrip()
249
254
                return files
250
255
 
251
256
 
 
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
 
252
270
        def has_changes( self ):
253
271
                """Check if the branch has any local modifications.
254
272
                """
299
317
 
300
318
 
301
319
        def run( self, cmd ):
302
 
                if the.verbose >= 2: print 'exec: %s' % ' '.join( cmd )
 
320
                if the.verbose >= 2: print('exec: %s' % ' '.join( cmd ))
303
321
                p = Popen( cmd, cwd = self.dir,
304
322
                                   stdout = subprocess.PIPE, stderr = subprocess.STDOUT )
305
 
                output = p.communicate()[ 0 ]
 
323
                output = p.communicate()[ 0 ].decode()
306
324
                if p.returncode > 0:
307
325
                        raise self.VcsError( ' '.join( cmd[ : 2 ] ), output )
308
326
                if the.verbose >= 2:
309
327
                        verbose_output = output.rstrip()
310
328
                        if len( verbose_output ):
311
 
                                print re.sub( '(^|\n)', '\\1  : ', verbose_output )
 
329
                                print(re.sub( '(^|\n)', '\\1  : ', verbose_output ))
312
330
                return output
313
331
 
314
332
 
315
333
        def parse_file_blocks( self, output ):
316
334
                res = dict()
317
335
                current = None
318
 
                buf = StringIO.StringIO( output )
 
336
                buf = io.StringIO( output )
319
337
                for line in buf:
320
338
                        matches = re.search( '^([a-z ]+):$', line, re.I )
321
339
                        if matches: