/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-04-05 22:29:08 UTC
  • Revision ID: tim@ed.am-20140405222908-3onggkfp5akpz21t
got symlink accept lists working; fixed some walker bugs

Show diffs side-by-side

added added

removed removed

34
34
 
35
35
                @param dir the fully-qualified directory to work in.
36
36
                """
37
 
 
38
37
                self.dir = dir
39
38
 
40
39
 
86
85
                """Obtain some sort of revision identifier
87
86
                """
88
87
 
89
 
                # bzr revno
 
88
                # bzr revert
90
89
                output = self.run( [ 'bzr', 'revno', '--tree' ] )
91
90
 
92
91
                # parse revno
109
108
                # symlink to a non-existant file)
110
109
                if 'kind changed' in files:
111
110
                        for file in files[ 'kind changed' ]:
112
 
                                matches = re.search( '^(.+?)[/@+]? \([^)]+\)$', file )
 
111
                                matches = re.match( r'(.+?)[/@+]? \([^)]+\)', file )
113
112
                                if not matches:
114
113
                                        raise RunTimeError(
115
114
                                                'failed to parse bzr kind change: %s' % file )
116
115
                                file = matches.group( 1 )
117
 
                                if the.verbose >= 2: print "removing (kind changed): " + file
 
116
                                if the.verbose > 1: print "removing (kind changed): " + file
118
117
                                full_file = os.path.join( self.dir, file )
119
118
                                if os.path.isfile( full_file ) or os.path.islink( full_file ):
120
119
                                        os.unlink( full_file )
133
132
                # remove unknown files
134
133
                if 'unknown' in files:
135
134
                        for file in files[ 'unknown' ]:
136
 
                                matches = re.search( r'^(.+?)[/@+]?$', file )
137
 
                                if not matches:
138
 
                                        raise RunTimeError(
139
 
                                                'failed to parse bzr unknowns: %s' % file )
140
 
                                file = matches.group( 1 )
141
 
                                if the.verbose >= 2: print "removing (unknown): " + file
 
135
                                if the.verbose > 1: print "removing (unknown): " + file
142
136
                                full_file = os.path.join( self.dir, file )
143
 
                                if os.path.isfile( full_file ) or os.path.islink( full_file ):
 
137
                                if os.path.isfile( full_file ):
144
138
                                        os.unlink( full_file )
145
139
                                elif os.path.isdir( full_file ):
146
140
                                        shutil.rmtree( full_file )
147
141
                                else:
148
142
                                        raise RuntimeError( 'exotic file in repo: %s' % file )
149
143
 
150
 
                # if a revision identifier has been given, ensure we're updated to that
151
 
                if revno is not None and self.get_revno() != revno:
 
144
                # if a revision identifyer has been given, update to that
 
145
                if revno is not None:
152
146
 
153
147
                        # bzr update
154
148
                        self.run( [ 'bzr', 'update', '-r', revno ] )
208
202
                for line in buf:
209
203
                        if not re.search( '^[-R+ ?][K NMD!][* ] ', line ): continue
210
204
                        line = line.rstrip()
 
205
                        if the.verbose > 1: print '  %s' % line
211
206
 
212
207
                        # renames show before and after file names
213
208
                        matches = re.search( '^R.. (.*?)[/@+]? => (.*?)[/@+]?$', line )
258
253
                return files['conflicts'] if 'conflicts' in files else None
259
254
 
260
255
 
261
 
        def add( self, files ):
262
 
                """Make sure files are added to version control.
263
 
                @param files a list of relative filenames
264
 
                """
265
 
 
266
 
                # bzr add
267
 
                self.run( [ 'bzr', 'add', '-N' ] + files )
268
 
 
269
 
 
270
 
        def commit( self ):
271
 
                """Commit changes to the repo.
272
 
                """
273
 
 
274
 
                # bzr commit
275
 
                self.run( [ 'bzr', 'commit', '-m', '' ] )
276
 
 
277
 
 
278
256
        def run( self, cmd ):
279
 
                if the.verbose >= 2: print 'exec: %s' % ' '.join( cmd )
 
257
                if the.verbose > 1: print 'exec: %s' % ' '.join( cmd )
280
258
                p = Popen( cmd, cwd = self.dir,
281
259
                                   stdout = subprocess.PIPE, stderr = subprocess.STDOUT )
282
260
                output = p.communicate()[ 0 ]
283
261
                if p.returncode > 0:
284
262
                        raise self.VcsError( ' '.join( cmd[ : 2 ] ), output )
285
 
                if the.verbose >= 2:
286
 
                        print re.sub( '(^|\n)', '\\1  > ', output.rstrip() )
287
263
                return output
288
264
 
289
265