/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-07-30 19:07:14 UTC
  • Revision ID: tim@ed.am-20140730190714-si0k116f2px8wjxi
added --force command to stage-revert to override ongoing deployments that can
not be reverted (due to missing revo information)

Show diffs side-by-side

added added

removed removed

28
28
class StageRevertCommand( Command ):
29
29
 
30
30
 
 
31
        def __init__( self ):
 
32
                self.force = False
 
33
 
 
34
 
31
35
        def print_help( self ):
32
36
                print "Usage: " + the.program.name + " stage-revert [--repo=REPO]"
33
37
                print
45
49
                print "repository."
46
50
                print
47
51
                print "Options:"
 
52
                print "      --force      force revert of stage (when there is a problem)"
48
53
                print "  -r, --repo=REPO  select the repo to check-out or create (defaults to 'home')"
49
54
                print "  -v, --verbose    display information about what is being done"
50
55
                print "      --help       display help and exit"
54
59
        def parse_command_line( self ):
55
60
                opts, args = getopt.gnu_getopt(
56
61
                        sys.argv[ 1: ], "r:v",
57
 
                        [ "repo=", "verbose", "help" ] )
 
62
                        [ "force", "repo=", "verbose", "help" ] )
58
63
                for opt, optarg in opts:
59
 
                        if opt in [ '--repo', '-r' ]:
 
64
                        if opt == "--force":
 
65
                                self.force = True
 
66
                        elif opt in [ '--repo', '-r' ]:
60
67
                                if not re.match( '^[-a-zA-z0-9.]+$', optarg ):
61
68
                                        raise the.program.FatalError(
62
69
                                                'invalid repository name: ' + optarg )
81
88
 
82
89
                # initialise deployment
83
90
                deployment = Deployment()
84
 
                if deployment.is_ongoing() and deployment.get_initial_revno() is None:
85
 
                        raise RunteimError(
86
 
                                "can't revert ongoing deployment: initial revno is missing!" )
 
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!" )
87
96
 
88
97
                # check for local changes
89
98
                if the.verbose >= 1: print "reverting %s" % the.repo.dir