Changeset 439 in tailor
- Timestamp:
- 07/29/05 20:20:35 (8 years ago)
- Hash name:
- 20050729182035-97f81-9cb95299ca2fa5f46f2b9d0da11b82dc8525f6f1
- File:
-
- 1 edited
-
vcpx/session.py (modified) (37 diffs)
Legend:
- Unmodified
- Added
- Removed
-
vcpx/session.py
r431 r439 4 4 # :Autore: Lele Gaifax <lele@nautilus.homeip.net> 5 5 # :Licenza: GNU General Public License 6 # 6 # 7 7 8 8 """ … … 32 32 except ValueError: 33 33 return arg.lower() in ('true', 'yes') 34 34 35 35 class Session(Cmd): 36 36 """Tailor interactive session.""" 37 37 38 38 prompt = "tailor $ " 39 39 40 40 def __init__(self, options, args): 41 41 """ … … 46 46 a list of commands to be executed. 47 47 """ 48 49 from os import getcwd 48 49 from os import getcwd 50 50 51 51 Cmd.__init__(self) 52 self.options = options 52 self.options = options 53 53 self.args = args 54 54 55 55 self.source_repository = options.repository 56 56 self.source_kind = options.source_kind … … 61 61 self.current_directory = getcwd() 62 62 self.sub_directory = None 63 63 64 64 self.state_file = None 65 65 self.logfile = None 66 66 self.logger = None 67 67 68 68 self.__processArgs() 69 69 70 70 # Persistent 71 71 72 72 self.changesets = None 73 73 self.source_revision = None 74 74 75 75 def __processArgs(self): 76 76 """ … … 87 87 if self.logger: 88 88 self.logger.info(what) 89 89 90 90 if self.options.verbose: 91 91 self.stdout.write(what) … … 98 98 else: 99 99 self.logger.error(what) 100 101 100 101 102 102 self.stdout.write('Error: ') 103 103 self.stdout.write(what) … … 122 122 123 123 return line 124 124 125 125 ## Interactive commands 126 126 … … 149 149 if not arg: 150 150 return 151 151 152 152 readline.write_history_file(arg) 153 153 self.__log('History saved in: %s' % arg) 154 154 155 155 def do_cd(self, arg): 156 156 """ … … 163 163 from os import chdir, makedirs, getcwd 164 164 from os.path import isabs, abspath, expanduser 165 165 166 166 if arg: 167 167 arg = expanduser(arg) … … 180 180 self.__err("Cannot create directory '%s'" % arg, True) 181 181 return 182 182 183 183 self.current_directory = getcwd() 184 184 185 185 self.__log('Current directory: %s' % self.current_directory) 186 186 … … 190 190 """ 191 191 Usage: sub_directory dirname 192 192 193 193 Print or set the subdirectory that actually contains the 194 194 working copy. When not explicitly set, this is desumed from 195 195 the last component of the upstream module name or repository. 196 196 """ 197 197 198 198 if arg and self.sub_directory <> arg: 199 199 self.sub_directory = arg … … 204 204 """ 205 205 Usage: logfile [filename] 206 206 207 207 Print or set the logfile of operations. By default there's no log. 208 208 """ 209 209 210 210 import logging 211 211 212 212 if arg: 213 213 self.logfile = arg … … 216 216 formatter = logging.Formatter('%(asctime)s [%(levelname)s] %(message)s') 217 217 hdlr.setFormatter(formatter) 218 self.logger.addHandler(hdlr) 218 self.logger.addHandler(hdlr) 219 219 self.logger.setLevel(logging.INFO) 220 220 221 221 self.__log('Logging to: %s' % self.logfile) 222 222 … … 229 229 230 230 from shwrap import ExternalCommand 231 231 232 232 if arg: 233 233 ExternalCommand.VERBOSE = yesno(arg) … … 246 246 247 247 from shwrap import ExternalCommand 248 248 249 249 if arg: 250 250 if arg == 'None': … … 275 275 self.__log('Patch name format: %s' % 276 276 SyncronizableTargetWorkingDir.PATCH_NAME_FORMAT) 277 277 278 278 def do_remove_first_log_line(self, arg): 279 279 """ 280 280 Usage: remove_first_log_line [0|1] 281 281 282 282 Print or set if tailor should drop the first line of the 283 283 upstream changelog. … … 305 305 306 306 from changes import Changeset 307 307 308 308 if arg: 309 309 Changeset.REFILL_MESSAGE = yesno(arg) 310 310 311 311 self.__log('Refill changelogs: %s' % Changeset.REFILL_MESSAGE) 312 312 313 313 def do_source_kind(self, arg): 314 314 """ … … 322 322 323 323 self.__log('Current source kind: %s' % self.source_kind) 324 324 325 325 def do_target_kind(self, arg): 326 326 """ … … 343 343 344 344 from os.path import sep 345 345 346 346 if arg and self.source_repository <> arg: 347 347 if arg.endswith(sep): … … 359 359 360 360 from os.path import sep 361 361 362 362 if arg and self.target_repository <> arg: 363 363 if arg.endswith(sep): … … 370 370 """ 371 371 Usage: source_module [module] 372 372 373 373 Print or set the source module. 374 374 """ 375 375 376 376 from os.path import sep 377 377 378 378 if arg and self.source_module <> arg: 379 379 if arg.endswith(sep): … … 391 391 392 392 from os.path import sep 393 393 394 394 if arg and self.target_module <> arg: 395 395 if arg.endswith(sep): … … 424 424 425 425 from cPickle import dump 426 426 427 427 sf = open(self.state_file, 'w') 428 428 dump((self.source_revision, self.changesets), sf) … … 432 432 """ 433 433 Usage: state_file [filename] 434 434 435 435 Print or set the current state file, where tailor stores the 436 436 source revision that has been applied last. 437 437 438 438 The argument must be a file name, possibly with the usual 439 "~user/file" convention. 439 "~user/file" convention. 440 440 """ 441 441 442 442 from os.path import isabs, abspath, expanduser 443 443 from cPickle import load 444 444 445 445 if arg: 446 446 arg = expanduser(arg) 447 447 if not isabs(arg): 448 448 arg = abspath(arg) 449 449 450 450 if arg and self.state_file <> arg: 451 451 self.state_file = arg 452 452 453 453 self.__log('Current state file: %s' % self.state_file) 454 454 … … 468 468 """ 469 469 Usage: bootstrap [revision] 470 470 471 471 Checkout the initial upstream revision, by default HEAD (or 472 472 specified by argument), then import the subtree into the 473 473 target repository. 474 474 """ 475 475 476 476 from os.path import join, split, sep 477 477 from dualwd import DualWorkingDir … … 483 483 if self.source_revision is not None: 484 484 self.__err('Already bootstrapped!') 485 485 486 486 if self.sub_directory: 487 487 subdir = self.sub_directory … … 506 506 self.__err('Checkout failed', True) 507 507 return 508 509 self.source_revision = actual.revision510 508 511 509 self.writeStateFile() 512 510 513 511 try: 514 512 dwd.initializeNewWorkingDir(self.current_directory, … … 520 518 self.__err('Working copy initialization failed', True) 521 519 return 522 520 523 521 def willApply(self, root, changeset): 524 522 """ … … 590 588 self.__err('Need a state_file to proceed!') 591 589 return 592 590 593 591 if self.source_revision is None: 594 592 self.__log('Boostrapping, because source_revision is None!') 595 593 return self.do_bootstrap(None) 596 594 597 595 if self.sub_directory: 598 596 subdir = self.sub_directory … … 604 602 self.source_repository)[1] or '' 605 603 self.do_sub_directory(subdir) 606 604 607 605 repodir = join(self.current_directory, subdir) 608 606 dwd = DualWorkingDir(self.source_kind, self.target_kind) … … 610 608 # If we have no pending changesets, ask the upstream server 611 609 # about new changes 612 610 613 611 if not self.changesets: 614 612 try: … … 625 623 self.__err('Unable to collect upstream changes', True) 626 624 return 627 625 628 626 nchanges = len(self.changesets) 629 627 if nchanges: … … 639 637 else: 640 638 changesets = self.changesets[:] 641 639 642 640 self.__log('Applying %d changesets (out of %d)' % 643 641 (len(changesets), nchanges)) … … 658 656 finally: 659 657 self.writeStateFile() 660 658 661 659 if self.changesets: 662 660 self.__log("There are still %d pending changesets, " … … 682 680 from darcs import DARCS_CMD, changesets_from_darcschanges 683 681 from shwrap import ExternalCommand, PIPE 684 682 685 683 if not (self.source_repository and self.target_repository and 686 684 isdir(self.source_repository) and … … 695 693 self.__err('Needs a patchname to proceed') 696 694 return 697 695 698 696 c = ExternalCommand(cwd=self.source_repository, 699 697 command=[DARCS_CMD, "changes", "--patches", … … 702 700 unidiff=True, 703 701 repodir=self.source_repository) 704 702 705 703 if not last: 706 704 self.__err('Specified patchname does not exist!') 707 705 return 708 706 709 707 cset = last[0] 710 708 cset.applyPatch(working_dir=self.target_repository, 711 709 patch_options=["-p1", "--force"]) 712 710 713 711 dwd = DualWorkingDir(self.source_kind, self.target_kind) 714 712 dwd.replayChangeset(self.target_repository, self.target_module, cset, 715 713 logger=self.logger) 716 714 717 715 def interactive(options, args): 718 716 session = Session(options, args)
Note: See TracChangeset
for help on using the changeset viewer.
