/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/command/stage_revert.py

  • Committer: Tim Marston
  • Date: 2014-03-08 00:47:23 UTC
  • Revision ID: tim@ed.am-20140308004723-hkl3s2hobsblf72o
added diff command; moved all command to commands subdir; made stage-revert
handle ongoing deployment automatically (now that initial revno is known); made
verbose level incremental; detect obstructing conflicts in ConflictWalker;
handle files deleted from repo during copy-out (update)

Show diffs side-by-side

added added

removed removed

29
29
 
30
30
 
31
31
        def __init__( self ):
32
 
                self.force = False
 
32
                self.repo = None
33
33
 
34
34
 
35
35
        def print_help( self ):
36
 
                print "Usage: " + the.program.name + " stage-revert [--repo=REPO]"
 
36
                print "Usage: " + the.program.name + " update [--repo=REPO]"
37
37
                print
38
38
                #      01234567890123456789012345678901234567890123456789012345678901234567890123456789
39
39
                print "Revert any modifications made to a local repository, losing those changes."
49
49
                print "repository."
50
50
                print
51
51
                print "Options:"
52
 
                print "      --force      force revert of stage (when there is a problem)"
53
52
                print "  -r, --repo=REPO  select the repo to check-out or create (defaults to 'home')"
54
53
                print "  -v, --verbose    display information about what is being done"
55
54
                print "      --help       display help and exit"
59
58
        def parse_command_line( self ):
60
59
                opts, args = getopt.gnu_getopt(
61
60
                        sys.argv[ 1: ], "r:v",
62
 
                        [ "force", "repo=", "verbose", "help" ] )
 
61
                        [ "repo=", "verbose", "help" ] )
63
62
                for opt, optarg in opts:
64
 
                        if opt == "--force":
65
 
                                self.force = True
66
 
                        elif opt in [ '--repo', '-r' ]:
67
 
                                if not re.search( '^[-a-zA-z0-9.]+$', optarg ):
 
63
                        if opt in [ '--repo', '-r' ]:
 
64
                                if not re.match( '^[-a-zA-z0-9.]+$', optarg ):
68
65
                                        raise the.program.FatalError(
69
66
                                                'invalid repository name: ' + optarg )
70
 
                                the.repo = optarg
 
67
                                self.repo = optarg
71
68
                        elif opt in [ '--verbose', '-v' ]:
72
69
                                the.verbose += 1
73
70
                        elif opt == "--help":
74
71
                                self.print_help()
75
 
 
 
72
                
76
73
                # discard first argument (the command)
77
74
                args.pop( 0 )
78
75
 
84
81
        def run( self ):
85
82
 
86
83
                # set up repo and check it exists
 
84
                the.set_repo( self.repo )
87
85
                the.repo.check_dir_exists()
88
86
 
89
87
                # initialise deployment
90
88
                deployment = Deployment()
91
 
                if deployment.is_ongoing() and deployment.get_initial_revno() is None \
92
 
                   and not self.force:
93
 
                        raise RuntimeError(
94
 
                                "can't revert ongoing deployment: initial revno is missing!\n"
95
 
                                "use --force to override, but an update may miss changes!" )
 
89
                if deployment.is_ongoing() and deployment.get_initial_revno() is None:
 
90
                        raise RunteimError(
 
91
                                "can't revert ongoing deployment: initial revno is missing!" )
96
92
 
97
93
                # check for local changes
98
 
                if the.verbose >= 1: print "reverting %s" % the.repo.dir
 
94
                if the.verbose: print "reverting %s" % the.repo.dir
99
95
                the.repo.vcs.revert( deployment.get_initial_revno() )
100
96
 
101
97
                # remove deployment state