/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-02-23 22:37:03 UTC
  • Revision ID: tim@ed.am-20160223223703-sx94svvstwt8xvrb
determine and instantiate repo vcs dynamically; for new repos, added default vcs
configuration option and allow override in init command arguments; re-added
handling of -v/--verbose arguments to commands and removed from program (since
there may be problems parsing all arguments here)

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 )
141
161
                                else:
142
162
                                        raise RuntimeError( 'exotic file in repo: %s' % file )
143
163
 
144
 
                # if a revision identifyer has been given, update to that
145
 
                if revno is not None:
 
164
                # if a revision identifier has been given, ensure we're updated to that
 
165
                if revno is not None and self.get_revno() != revno:
146
166
 
147
167
                        # bzr update
148
168
                        self.run( [ 'bzr', 'update', '-r', revno ] )
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 )
259
278
                """
260
279
 
261
280
                # bzr add
262
 
                self.run( [ 'bzr', 'add' ] + files )
 
281
                self.run( [ 'bzr', 'add', '-N' ] + files )
263
282
 
264
283
 
265
284
        def commit( self ):
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
                        print re.sub( '(^|\n)', '\\1  > ', output.rstrip() )
280
301
                return output
281
302
 
282
303