/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-04-10 17:42:36 UTC
  • Revision ID: tim@ed.am-20160410174236-708ckdxils6m2ndv
added tools

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
 
37
38
                self.dir = dir
38
39
 
39
40
 
 
41
        def has_authority( self ):
 
42
                """Check that the directory is under this VCS's control.
 
43
                """
 
44
 
 
45
                return os.path.exists( os.path.join( self.dir, '.bzr' ) )
 
46
 
 
47
 
 
48
        def expand_repo_url( self, url ):
 
49
                """Convert a simple hostname in to an URL that the VCS can use.
 
50
                """
 
51
 
 
52
                return 'bzr+ssh://%s/%s/%s' % ( url, the.dir, the.repo.name )
 
53
 
 
54
 
40
55
        def init( self ):
41
56
                """Create a new, empty branch
42
57
                """
85
100
                """Obtain some sort of revision identifier
86
101
                """
87
102
 
88
 
                # bzr revert
 
103
                # bzr revno
89
104
                output = self.run( [ 'bzr', 'revno', '--tree' ] )
90
105
 
91
106
                # parse revno
108
123
                # symlink to a non-existant file)
109
124
                if 'kind changed' in files:
110
125
                        for file in files[ 'kind changed' ]:
111
 
                                matches = re.match( r'(.+?)[/@+]? \([^)]+\)', file )
 
126
                                matches = re.search( '^(.+?)[/@+]? \([^)]+\)$', file )
112
127
                                if not matches:
113
128
                                        raise RunTimeError(
114
129
                                                'failed to parse bzr kind change: %s' % file )
132
147
                # remove unknown files
133
148
                if 'unknown' in files:
134
149
                        for file in files[ 'unknown' ]:
 
150
                                matches = re.search( r'^(.+?)[/@+]?$', file )
 
151
                                if not matches:
 
152
                                        raise RunTimeError(
 
153
                                                'failed to parse bzr unknowns: %s' % file )
 
154
                                file = matches.group( 1 )
135
155
                                if the.verbose >= 2: print "removing (unknown): " + file
136
156
                                full_file = os.path.join( self.dir, file )
137
 
                                if os.path.isfile( full_file ):
 
157
                                if os.path.isfile( full_file ) or os.path.islink( full_file ):
138
158
                                        os.unlink( full_file )
139
159
                                elif os.path.isdir( full_file ):
140
160
                                        shutil.rmtree( full_file )
202
222
                for line in buf:
203
223
                        if not re.search( '^[-R+ ?][K NMD!][* ] ', line ): continue
204
224
                        line = line.rstrip()
205
 
                        if the.verbose >= 2: print '  %s' % line
206
225
 
207
226
                        # renames show before and after file names
208
227
                        matches = re.search( '^R.. (.*?)[/@+]? => (.*?)[/@+]?$', line )
277
296
                output = p.communicate()[ 0 ]
278
297
                if p.returncode > 0:
279
298
                        raise self.VcsError( ' '.join( cmd[ : 2 ] ), output )
 
299
                if the.verbose >= 2:
 
300
                        verbose_output = output.rstrip()
 
301
                        if len( verbose_output ):
 
302
                                print re.sub( '(^|\n)', '\\1  : ', verbose_output )
280
303
                return output
281
304
 
282
305