Changeset 439 in tailor


Ignore:
Timestamp:
07/29/05 20:20:35 (8 years ago)
Author:
lele@…
Hash name:
20050729182035-97f81-9cb95299ca2fa5f46f2b9d0da11b82dc8525f6f1
Message:

M-x whitespace-cleanup

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vcpx/session.py

    r431 r439  
    44# :Autore:   Lele Gaifax <lele@nautilus.homeip.net> 
    55# :Licenza:  GNU General Public License 
    6 #  
     6# 
    77 
    88""" 
     
    3232    except ValueError: 
    3333        return arg.lower() in ('true', 'yes') 
    34      
     34 
    3535class Session(Cmd): 
    3636    """Tailor interactive session.""" 
    37      
     37 
    3838    prompt = "tailor $ " 
    39      
     39 
    4040    def __init__(self, options, args): 
    4141        """ 
     
    4646        a list of commands to be executed. 
    4747        """ 
    48          
    49         from os import getcwd        
     48 
     49        from os import getcwd 
    5050 
    5151        Cmd.__init__(self) 
    52         self.options = options         
     52        self.options = options 
    5353        self.args = args 
    54          
     54 
    5555        self.source_repository = options.repository 
    5656        self.source_kind = options.source_kind 
     
    6161        self.current_directory = getcwd() 
    6262        self.sub_directory = None 
    63          
     63 
    6464        self.state_file = None 
    6565        self.logfile = None 
    6666        self.logger = None 
    67          
     67 
    6868        self.__processArgs() 
    6969 
    7070        # Persistent 
    71          
     71 
    7272        self.changesets = None 
    7373        self.source_revision = None 
    74          
     74 
    7575    def __processArgs(self): 
    7676        """ 
     
    8787        if self.logger: 
    8888            self.logger.info(what) 
    89              
     89 
    9090        if self.options.verbose: 
    9191            self.stdout.write(what) 
     
    9898            else: 
    9999                self.logger.error(what) 
    100              
    101              
     100 
     101 
    102102        self.stdout.write('Error: ') 
    103103        self.stdout.write(what) 
     
    122122 
    123123        return line 
    124          
     124 
    125125    ## Interactive commands 
    126126 
     
    149149        if not arg: 
    150150            return 
    151              
     151 
    152152        readline.write_history_file(arg) 
    153153        self.__log('History saved in: %s' % arg) 
    154          
     154 
    155155    def do_cd(self, arg): 
    156156        """ 
     
    163163        from os import chdir, makedirs, getcwd 
    164164        from os.path import isabs, abspath, expanduser 
    165          
     165 
    166166        if arg: 
    167167            arg = expanduser(arg) 
     
    180180                    self.__err("Cannot create directory '%s'" % arg, True) 
    181181                    return 
    182                  
     182 
    183183            self.current_directory = getcwd() 
    184              
     184 
    185185        self.__log('Current directory: %s' % self.current_directory) 
    186186 
     
    190190        """ 
    191191        Usage: sub_directory dirname 
    192          
     192 
    193193        Print or set the subdirectory that actually contains the 
    194194        working copy. When not explicitly set, this is desumed from 
    195195        the last component of the upstream module name or repository. 
    196196        """ 
    197          
     197 
    198198        if arg and self.sub_directory <> arg: 
    199199            self.sub_directory = arg 
     
    204204        """ 
    205205        Usage: logfile [filename] 
    206          
     206 
    207207        Print or set the logfile of operations. By default there's no log. 
    208208        """ 
    209209 
    210210        import logging 
    211          
     211 
    212212        if arg: 
    213213            self.logfile = arg 
     
    216216            formatter = logging.Formatter('%(asctime)s [%(levelname)s] %(message)s') 
    217217            hdlr.setFormatter(formatter) 
    218             self.logger.addHandler(hdlr)  
     218            self.logger.addHandler(hdlr) 
    219219            self.logger.setLevel(logging.INFO) 
    220              
     220 
    221221        self.__log('Logging to: %s' % self.logfile) 
    222222 
     
    229229 
    230230        from shwrap import ExternalCommand 
    231          
     231 
    232232        if arg: 
    233233            ExternalCommand.VERBOSE = yesno(arg) 
     
    246246 
    247247        from shwrap import ExternalCommand 
    248          
     248 
    249249        if arg: 
    250250            if arg == 'None': 
     
    275275        self.__log('Patch name format: %s' % 
    276276                   SyncronizableTargetWorkingDir.PATCH_NAME_FORMAT) 
    277          
     277 
    278278    def do_remove_first_log_line(self, arg): 
    279279        """ 
    280280        Usage: remove_first_log_line [0|1] 
    281          
     281 
    282282        Print or set if tailor should drop the first line of the 
    283283        upstream changelog. 
     
    305305 
    306306        from changes import Changeset 
    307          
     307 
    308308        if arg: 
    309309            Changeset.REFILL_MESSAGE = yesno(arg) 
    310310 
    311311        self.__log('Refill changelogs: %s' % Changeset.REFILL_MESSAGE) 
    312          
     312 
    313313    def do_source_kind(self, arg): 
    314314        """ 
     
    322322 
    323323        self.__log('Current source kind: %s' % self.source_kind) 
    324          
     324 
    325325    def do_target_kind(self, arg): 
    326326        """ 
     
    343343 
    344344        from os.path import sep 
    345          
     345 
    346346        if arg and self.source_repository <> arg: 
    347347            if arg.endswith(sep): 
     
    359359 
    360360        from os.path import sep 
    361          
     361 
    362362        if arg and self.target_repository <> arg: 
    363363            if arg.endswith(sep): 
     
    370370        """ 
    371371        Usage: source_module [module] 
    372          
     372 
    373373        Print or set the source module. 
    374374        """ 
    375375 
    376376        from os.path import sep 
    377          
     377 
    378378        if arg and self.source_module <> arg: 
    379379            if arg.endswith(sep): 
     
    391391 
    392392        from os.path import sep 
    393          
     393 
    394394        if arg and self.target_module <> arg: 
    395395            if arg.endswith(sep): 
     
    424424 
    425425        from cPickle import dump 
    426          
     426 
    427427        sf = open(self.state_file, 'w') 
    428428        dump((self.source_revision, self.changesets), sf) 
     
    432432        """ 
    433433        Usage: state_file [filename] 
    434          
     434 
    435435        Print or set the current state file, where tailor stores the 
    436436        source revision that has been applied last. 
    437          
     437 
    438438        The argument must be a file name, possibly with the usual 
    439         "~user/file" convention.         
     439        "~user/file" convention. 
    440440        """ 
    441441 
    442442        from os.path import isabs, abspath, expanduser 
    443443        from cPickle import load 
    444          
     444 
    445445        if arg: 
    446446            arg = expanduser(arg) 
    447447            if not isabs(arg): 
    448448                arg = abspath(arg) 
    449          
     449 
    450450        if arg and self.state_file <> arg: 
    451451            self.state_file = arg 
    452              
     452 
    453453        self.__log('Current state file: %s' % self.state_file) 
    454454 
     
    468468        """ 
    469469        Usage: bootstrap [revision] 
    470          
     470 
    471471        Checkout the initial upstream revision, by default HEAD (or 
    472472        specified by argument), then import the subtree into the 
    473473        target repository. 
    474474        """ 
    475          
     475 
    476476        from os.path import join, split, sep 
    477477        from dualwd import DualWorkingDir 
     
    483483        if self.source_revision is not None: 
    484484            self.__err('Already bootstrapped!') 
    485              
     485 
    486486        if self.sub_directory: 
    487487            subdir = self.sub_directory 
     
    506506            self.__err('Checkout failed', True) 
    507507            return 
    508  
    509         self.source_revision = actual.revision 
    510508         
    511509        self.writeStateFile() 
    512          
     510 
    513511        try: 
    514512            dwd.initializeNewWorkingDir(self.current_directory, 
     
    520518            self.__err('Working copy initialization failed', True) 
    521519            return 
    522          
     520 
    523521    def willApply(self, root, changeset): 
    524522        """ 
     
    590588            self.__err('Need a state_file to proceed!') 
    591589            return 
    592                  
     590 
    593591        if self.source_revision is None: 
    594592            self.__log('Boostrapping, because source_revision is None!') 
    595593            return self.do_bootstrap(None) 
    596          
     594 
    597595        if self.sub_directory: 
    598596            subdir = self.sub_directory 
     
    604602                           self.source_repository)[1] or '' 
    605603            self.do_sub_directory(subdir) 
    606              
     604 
    607605        repodir = join(self.current_directory, subdir) 
    608606        dwd = DualWorkingDir(self.source_kind, self.target_kind) 
     
    610608        # If we have no pending changesets, ask the upstream server 
    611609        # about new changes 
    612          
     610 
    613611        if not self.changesets: 
    614612            try: 
     
    625623                self.__err('Unable to collect upstream changes', True) 
    626624                return 
    627              
     625 
    628626        nchanges = len(self.changesets) 
    629627        if nchanges: 
     
    639637            else: 
    640638                changesets = self.changesets[:] 
    641                  
     639 
    642640            self.__log('Applying %d changesets (out of %d)' % 
    643641                       (len(changesets), nchanges)) 
     
    658656            finally: 
    659657                self.writeStateFile() 
    660                  
     658 
    661659                if self.changesets: 
    662660                    self.__log("There are still %d pending changesets, " 
     
    682680        from darcs import DARCS_CMD, changesets_from_darcschanges 
    683681        from shwrap import ExternalCommand, PIPE 
    684          
     682 
    685683        if not (self.source_repository and self.target_repository and 
    686684                isdir(self.source_repository) and 
     
    695693            self.__err('Needs a patchname to proceed') 
    696694            return 
    697          
     695 
    698696        c = ExternalCommand(cwd=self.source_repository, 
    699697                            command=[DARCS_CMD, "changes", "--patches", 
     
    702700                                            unidiff=True, 
    703701                                            repodir=self.source_repository) 
    704          
     702 
    705703        if not last: 
    706704            self.__err('Specified patchname does not exist!') 
    707705            return 
    708          
     706 
    709707        cset = last[0] 
    710708        cset.applyPatch(working_dir=self.target_repository, 
    711709                        patch_options=["-p1", "--force"]) 
    712          
     710 
    713711        dwd = DualWorkingDir(self.source_kind, self.target_kind) 
    714712        dwd.replayChangeset(self.target_repository, self.target_module, cset, 
    715713                            logger=self.logger) 
    716          
     714 
    717715def interactive(options, args): 
    718716    session = Session(options, args) 
Note: See TracChangeset for help on using the changeset viewer.