/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/deployment.py

  • Committer: Tim Marston
  • Date: 2016-04-10 20:29:46 UTC
  • Revision ID: tim@ed.am-20160410202946-9eoh5i3et9443aq6
fixed greps in tools/dev to detect home-dir lines in stdhomerc

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
                """
44
44
 
45
45
                # list of files that were copied-in (or at least given the opportunity
46
 
        # to be) and updated through the vcs update.  This means that, while
47
 
        # there may have been conflicts during the update (which will be dealt
48
 
        # with in the repo), any conflicts arising with these files in the home
49
 
        # directory are no longer important and can be ignored.  In short, this
50
 
        # is a list of files that it is safe to deploy, regardless of their
51
 
        # state in the home directory.
52
 
                self.deploy_files = None
 
46
                # to be) and updated through the vcs update.  This means that, while
 
47
                # there may have been conflicts during the update (which the user will
 
48
                # have to have dealt with in the repo), any conflicts arising with these
 
49
                # files in the home directory are no longer important and can be
 
50
                # ignored.  In short, this is a list of files that can safely be
 
51
                # deployed, regardless of the state of the home directory.
 
52
                self.imported_files = None
53
53
 
54
54
                # list of files that were affected by a recent vcs update (so only these
55
55
                # files need to be checked for deployment conflicts or copied-out)
67
67
                        return
68
68
 
69
69
                # read the file list
70
 
                if the.verbose: print "deployment state found; loading"
 
70
                if the.verbose >= 1: print "deployment state found; loading"
71
71
                f = open( file, 'r' )
72
72
                state = json.loads( f.read() )
73
73
 
74
74
                # unpack deployment state
75
 
                self.deploy_files = state['deploy_files'];
76
 
                self.initial_revno = state['initial_revno'];
77
 
                self.affected_files = state['affected_files'];
 
75
                if 'imported_files' in state:
 
76
                        self.imported_files = state['imported_files'];
 
77
                if 'initial_revno' in state:
 
78
                        self.initial_revno = state['initial_revno'];
 
79
                if 'affected_files' in state:
 
80
                        self.affected_files = state['affected_files'];
78
81
 
79
82
 
80
83
        def save_deployment_state( self ):
81
84
                """Save the current deployment state (so there will be a deployment ongoing).
82
85
                """
83
86
 
84
 
                if the.verbose: print "saving deployment state"
 
87
                if the.verbose >= 1: print "saving deployment state"
85
88
 
86
89
                # create metadata directory, as necessary
87
90
                if not os.path.isdir( the.full_mddir ):
89
92
 
90
93
                # pack deployment state
91
94
                state = {
92
 
                        'deploy_files': self.deploy_files,
 
95
                        'imported_files': self.imported_files,
93
96
                        'initial_revno': self.initial_revno,
94
97
                        'affected_files': self.affected_files,
95
98
                }
109
112
                if( os.path.isfile( file ) ):
110
113
 
111
114
                        # delete it
112
 
                        if the.verbose: print "removing deployment state"
 
115
                        if the.verbose >= 1: print "removing deployment state"
113
116
                        os.unlink( file )
114
117
 
115
118
 
117
120
                """Is there a deployment currently ongoing?
118
121
                """
119
122
 
120
 
                return False if self.deploy_files is None else True
 
123
                return False if self.imported_files is None else True
121
124
 
122
125
 
123
126
        def check_ongoing( self, ongoing = True ):
126
129
                """
127
130
 
128
131
                if( ongoing ):
129
 
                        if self.deploy_files is None:
 
132
                        if self.imported_files is None:
130
133
                                raise self.DeploymentOngoing( False )
131
134
                else:
132
 
                        if self.deploy_files is not None:
 
135
                        if self.imported_files is not None:
133
136
                                raise self.DeploymentOngoing( True )
134
137
 
135
138
 
150
153
 
151
154
                # if the repo doesn't exist, we have an empty file list
152
155
                if not os.path.exists( the.repo.full_dir ):
153
 
                        self.deploy_files = list()
 
156
                        self.imported_files = list()
154
157
                else:
155
158
                        # copy in
156
 
                        if the.verbose: print "importing files..."
 
159
                        if the.verbose >= 1: print "importing files..."
157
160
                        walker = CopyInWalker()
158
161
                        walker.walk()
159
 
                        if( walker.changed ):
160
 
                                raise self.CopyInConflicts( walker.changed )
161
 
                        self.deploy_files = walker.walk_list
 
162
                        self.imported_files = walker.walk_list
162
163
 
163
164
                        # obtain initial revno
164
165
                        self.initial_revno = the.repo.vcs.get_revno()
168
169
 
169
170
 
170
171
        def get_conflicts( self, affected_files = None ):
171
 
                """Check to see if there are any delpoyment conflicts.  If a list of affected
 
172
                """Check to see if there are any deployment conflicts.  If a list of affected
172
173
                files is supplied, then only those files are checked (and they are also
173
174
                saved with the deployment state).  Otherwise, all files in the
174
175
                repository are checked.
183
184
                        self.save_deployment_state()
184
185
 
185
186
                # check for deployment conflicts
186
 
                walker = ConflictWalker( self.deploy_files, self.affected_files )
 
187
                walker = ConflictWalker( self.imported_files, self.affected_files )
187
188
                walker.walk()
188
189
 
189
190
                self.conflicts_checked = True
190
191
                return walker.changed + walker.obstructed
191
192
 
192
193
 
193
 
        def copy_out( self ):
194
 
                """Copy-out changed files frmo the repository to the home directory.  If the
195
 
                deployment state incudes a list of affected files, then only those fiels
196
 
                are copied-out.
 
194
        def copy_out( self, quiet ):
 
195
                """Copy-out changed files from the repository to the home directory.  If the
 
196
                deployment state includes a list of affected files, then only those
 
197
                files are copied-out.
197
198
                """
198
199
 
199
200
                # check we have a file list
204
205
                        raise RuntimeError('logic error: deployment conflicts unchecked' )
205
206
 
206
207
                # copy out
207
 
                if the.verbose: print "exporting files..."
208
 
                walker = CopyOutWalker( self.affected_files )
 
208
                if the.verbose >= 1: print "exporting files..."
 
209
                walker = CopyOutWalker( self.affected_files, quiet )
209
210
                walker.walk()
210
211
 
211
212
                # clear state
219
220
                                self.msg = "there is an ongoing deployment"
220
221
                        else:
221
222
                                self.msg = "there is no ongoing deployment"
222
 
 
223
 
 
224
 
        class CopyInConflicts( the.program.FatalError ):
225
 
 
226
 
                def __init__( self, conflicts ):
227
 
                        self.conflicts = conflicts