/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-02-12 21:51:08 UTC
  • Revision ID: tim@ed.am-20140212215108-stk5z0nlvgpi4oa8
added bzr as a vcs backend; finished init command; implemented deployment

Show diffs side-by-side

added added

removed removed

21
21
 
22
22
import subprocess, os, re, shutil
23
23
from subprocess import Popen
 
24
import stdhome.the as the
24
25
import StringIO
25
 
from vcs import Vcs
26
 
from stdhome import the
27
 
 
28
 
 
29
 
class VcsBzr( Vcs ):
 
26
 
 
27
 
 
28
class VcsBzr:
30
29
 
31
30
 
32
31
        def __init__( self, dir ):
56
55
                        except OSError:
57
56
                                pass
58
57
 
59
 
                        raise self.VcsError( 'bzr init failed', output )
 
58
                        raise the.program.FatalError( 'bzr init failed', output )
60
59
 
61
60
 
62
61
        def checkout( self, url ):
80
79
                        except OSError:
81
80
                                pass
82
81
 
83
 
                        raise self.VcsError( 'bzr checkout failed', output )
 
82
                        raise the.program.FatalError( 'bzr checkout failed', output )
84
83
 
85
84
 
86
85
        def revert( self ):
92
91
                                   stdout = subprocess.PIPE, stderr = subprocess.STDOUT )
93
92
                output = p.communicate()[ 0 ]
94
93
                if p.returncode > 0:
95
 
                        raise self.VcsError( 'bzr revert failed', output )
 
94
                        raise the.program.FatalError( 'bzr revert failed', output )
96
95
 
97
96
                # bzr st
98
97
                p = Popen( [ 'bzr', 'st' ], cwd = self.dir,
99
98
                                   stdout = subprocess.PIPE, stderr = subprocess.STDOUT )
100
99
                output = p.communicate()[ 0 ]
101
100
                if p.returncode > 0:
102
 
                        raise self.VcsError( 'bzr status failed', output )
 
101
                        raise the.program.FatalError( 'bzr status failed', output )
103
102
                files = self.parse_file_blocks( output )
104
103
 
105
104
                # remove unknown files
115
114
 
116
115
 
117
116
        def update( self ):
118
 
                """Update the branch, pulling down any upstream changes and merging them.  This
119
 
                method returns a list of the files that were modified as part of this
120
 
                operation.
 
117
                """Update the branch, pulling down any upstream changes and merging them.
121
118
                """
122
119
 
123
120
                # bzr update
125
122
                                   stdout = subprocess.PIPE, stderr = subprocess.STDOUT )
126
123
                output = p.communicate()[ 0 ]
127
124
                if p.returncode > 0:
128
 
                        raise self.VcsError( 'bzr update failed', output )
129
 
 
130
 
                # parse output (see logic in report() in bzrlib/delta.py)
131
 
                files = list()
132
 
                buf = StringIO.StringIO( output )
133
 
                for line in buf:
134
 
                        if not re.search( '^[-R+ ?][K NMD!][* ] ', line ): continue
135
 
                        line = line.rstrip()
136
 
                        if the.verbose: print '  %s' % line
137
 
 
138
 
                        # renames show before and after file names
139
 
                        matches = re.search( '^R.. (.*?)[/@+]? => (.*?)[/@+]?$', line )
140
 
                        if matches:
141
 
                                files.append( matches.group( 1 ) )
142
 
                                files.append( matches.group( 2 ) )
143
 
                                continue
144
 
 
145
 
                        # kind changes shows the same name twice
146
 
                        matches = re.search( '^.K. (.*?)[/@+]? => (.*?)[/@+]?$', line )
147
 
                        if matches:
148
 
                                files.append( matches.group( 1 ) )
149
 
                                continue
150
 
 
151
 
                        # other entries have only one filename
152
 
                        matches = re.search( '^... (.*?)[/@+]?$', line )
153
 
                        if matches:
154
 
                                files.append( matches.group( 1 ) )
155
 
                                continue
156
 
 
157
 
                        raise RuntimeError(
158
 
                                'failed to parse bzr update output line:\n%' % line )
159
 
 
160
 
                return files
 
125
                        raise the.program.FatalError( 'bzr update failed', output )
161
126
 
162
127
 
163
128
        def has_changes( self ):
169
134
                                   stdout = subprocess.PIPE, stderr = subprocess.STDOUT )
170
135
                output = p.communicate()[ 0 ]
171
136
                if p.returncode > 0:
172
 
                        raise self.VcsError( 'bzr status failed', output )
 
137
                        raise the.program.FatalError( 'bzr status failed', output )
173
138
                files = self.parse_file_blocks( output )
174
139
                return True if len( files ) else False
175
140
 
183
148
                                   stdout = subprocess.PIPE, stderr = subprocess.STDOUT )
184
149
                output = p.communicate()[ 0 ]
185
150
                if p.returncode > 0:
186
 
                        raise self.VcsError( 'bzr status failed', output )
 
151
                        raise the.program.FatalError( 'bzr status failed', output )
187
152
                files = self.parse_file_blocks( output )
188
153
                return files['conflicts'] if 'conflicts' in files else None
189
154