Changeset 323 in tailor


Ignore:
Timestamp:
05/24/05 01:42:38 (8 years ago)
Author:
lele@…
Hash name:
20050523234238-97f81-48f3cff2ff0f172a917ee376c7fca337caa25aa6
Message:

Implement 'update' command

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vcpx/session.py

    r322 r323  
    381381                 
    382382        self.__log('Current state file: %s\n' % self.state_file) 
    383  
    384     def do_get_changes(self, arg): 
    385         """Fetch information on upstream changes.""" 
    386  
    387         source_revision = self.readSourceRevision() 
    388         if self.source_kind and \ 
    389            self.source_repository and \ 
    390            self.source_module and \ 
    391            source_revision: 
    392  
    393             dwd = DualWorkingDir(self.source_kind, self.target_kind) 
    394             self.changesets = dwd.getUpstreamChangesets(self.current_directory, 
    395                                                         self.source_repository, 
    396                                                         self.source_module, 
    397                                                         source_revision) 
    398             self.__log('Collected %d upstream changesets\n' % 
    399                        len(self.changesets)) 
    400         else: 
    401             self.__err("needs 'source_kind', 'source_repository' and " 
    402                        "'source_module' to proceed.\n") 
    403  
    404     def do_show_changes(self, arg): 
    405         """Show the upstream changes not yet applied.""" 
    406  
    407         if self.changesets: 
    408             self.__log(`self.changesets`) 
    409             self.__log('\n') 
    410         else: 
    411             self.__err("needs `get_changes` to proceed.\n") 
    412383 
    413384    def do_bootstrap(self, arg): 
     
    460431                self.logger.exception('Working copy initialization failed') 
    461432 
     433    def willApply(self, root, changeset): 
     434        """ 
     435        Print the changeset being applied. 
     436        """ 
     437 
     438        self.__log("Changeset %s:\n%s\n" % (changeset.revision, 
     439                                            changeset.log)) 
     440        return True 
     441 
     442    def shouldApply(self, root, changeset): 
     443        """ 
     444        Ask weather a changeset should be applied. 
     445        """ 
     446 
     447        self.stdout.write("Changeset %s:\n%s\n" % (changeset.revision, 
     448                                                   changeset.log)) 
     449        ans = raw_input("Apply [Y/n]? ") 
     450         
     451        return ans == '' or ans[0].lower() == 'y' 
     452 
     453    def applied(self, root, changeset): 
     454        """ 
     455        Save current status. 
     456        """ 
     457 
     458        self.saveSourceRevision(changeset.revision) 
     459 
     460    def do_update(self, arg): 
     461        """ 
     462        Usage: update [arg] 
     463 
     464        Fetch information on upstream changes and replay them with the 
     465        target system. 
     466 
     467        Argument may be either an integer value or the string 'ask'. The 
     468        number specify the maximum number of changesets the will be 
     469        applied. With 'ask' tailor will propose a "y/n" question for each 
     470        changeset before applying it. 
     471        """ 
     472 
     473        source_revision = self.readSourceRevision() 
     474        if self.source_kind and \ 
     475           self.source_repository and \ 
     476           self.source_module and \ 
     477           source_revision: 
     478 
     479            dwd = DualWorkingDir(self.source_kind, self.target_kind) 
     480            self.changesets = dwd.getUpstreamChangesets(self.current_directory, 
     481                                                        self.source_repository, 
     482                                                        self.source_module, 
     483                                                        source_revision) 
     484            nchanges = len(changesets) 
     485            if nchanges: 
     486                self.__log('Collected %d upstream changesets\n' % nchanges) 
     487 
     488                if arg: 
     489                    appliable = self.willApply 
     490                    try: 
     491                        howmany = min(int(arg), nchanges) 
     492                        changesets = changesets[:howmany] 
     493                        self.__log('Applying first %d of them\n' % howmany) 
     494                    except ValueError: 
     495                        if arg.lower() == 'ask': 
     496                            appliable = self.shouldApply 
     497 
     498                try: 
     499                    last, conflicts = dwd.applyUpstreamChangesets( 
     500                        proj, self.module, changesets, applyable=applyable, 
     501                        applied=self.applied, logger=self.logger, 
     502                        delayed_commit=single_commit) 
     503                except: 
     504                    if self.logger: 
     505                        self.logger.exception('Upstream change application ' 
     506                                              'failed') 
     507                    self.__err('Stopping after upstream change application ' 
     508                               'failure.') 
     509                    return 
     510 
     511                if last: 
     512                    self.__log("Update completed, now at revision '%s'" % 
     513                               self.readSourceRevision()) 
     514            else: 
     515                self.__log("Update completed with no upstream changes") 
     516        else: 
     517            self.__err("needs 'source_kind', 'source_repository' and " 
     518                       "'source_module' to proceed.\n") 
     519 
    462520         
    463521def interactive(options, args): 
Note: See TracChangeset for help on using the changeset viewer.