/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: 2016-02-23 19:35:21 UTC
  • Revision ID: tim@ed.am-20160223193521-2vgtxbfos50rrpku
renamed version -> VERSION

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' ]:
60
 
                                if not re.match( '^[-a-zA-z0-9.]+$', optarg ):
 
64
                        if opt == "--force":
 
65
                                self.force = True
 
66
                        elif opt in [ '--repo', '-r' ]:
 
67
                                if not re.search( '^[-a-zA-z0-9.]+$', optarg ):
61
68
                                        raise the.program.FatalError(
62
69
                                                'invalid repository name: ' + optarg )
63
70
                                the.repo = optarg
64
 
                        elif opt in [ '--verbose', '-v' ]:
65
 
                                the.verbose += 1
66
71
                        elif opt == "--help":
67
72
                                self.print_help()
68
 
                
 
73
 
69
74
                # discard first argument (the command)
70
75
                args.pop( 0 )
71
76
 
81
86
 
82
87
                # initialise deployment
83
88
                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!" )
 
89
                if deployment.is_ongoing() and deployment.get_initial_revno() is None \
 
90
                   and not self.force:
 
91
                        raise RuntimeError(
 
92
                                "can't revert ongoing deployment: initial revno is missing!\n"
 
93
                                "use --force to override, but an update may miss changes!" )
87
94
 
88
95
                # check for local changes
89
96
                if the.verbose >= 1: print "reverting %s" % the.repo.dir