19
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
22
import subprocess, os, re, shutil
27
23
from subprocess import Popen
29
26
from stdhome import the
34
29
class BzrVcs( Vcs ):
110
105
output = self.run( [ 'bzr', 'revno', '--tree' ] )
113
buf = io.StringIO( output )
108
buf = StringIO.StringIO( output )
114
109
return buf.readline().rstrip()
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 )
225
220
# parse output (see logic in report() in bzrlib/delta.py)
227
buf = io.StringIO( output )
222
buf = StringIO.StringIO( output )
229
224
if not re.search( '^[-R+ ?][K NMD!][* ] ', line ): continue
230
225
line = line.rstrip()
258
"""Get a list of any local modifications. This method returns a list of files
264
output = self.run( [ 'bzr', 'status', '--no-pending' ] )
267
return self.parse_file_blocks( output )
270
252
def has_changes( self ):
271
253
"""Check if the branch has any local modifications.
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 );
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 )
333
313
def parse_file_blocks( self, output ):
336
buf = io.StringIO( output )
316
buf = StringIO.StringIO( output )
338
318
matches = re.search( '^([a-z ]+):$', line, re.I )