/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-13 13:25:21 UTC
  • Revision ID: tim@ed.am-20160213132521-46v5774k6ql7tdfn
fixed uninitialised variable

Show diffs side-by-side

added added

removed removed

29
29
 
30
30
 
31
31
        def __init__( self ):
32
 
                self.repo = None
 
32
                self.force = False
33
33
 
34
34
 
35
35
        def print_help( self ):
36
 
                print "Usage: " + the.program.name + " update [--repo=REPO]"
 
36
                print "Usage: " + the.program.name + " stage-revert [--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)"
52
53
                print "  -r, --repo=REPO  select the repo to check-out or create (defaults to 'home')"
53
54
                print "  -v, --verbose    display information about what is being done"
54
55
                print "      --help       display help and exit"
58
59
        def parse_command_line( self ):
59
60
                opts, args = getopt.gnu_getopt(
60
61
                        sys.argv[ 1: ], "r:v",
61
 
                        [ "repo=", "verbose", "help" ] )
 
62
                        [ "force", "repo=", "verbose", "help" ] )
62
63
                for opt, optarg in opts:
63
 
                        if opt in [ '--repo', '-r' ]:
 
64
                        if opt == "--force":
 
65
                                self.force = True
 
66
                        elif opt in [ '--repo', '-r' ]:
64
67
                                if not re.match( '^[-a-zA-z0-9.]+$', optarg ):
65
68
                                        raise the.program.FatalError(
66
69
                                                'invalid repository name: ' + optarg )
67
 
                                self.repo = optarg
68
 
                        elif opt in [ '--verbose', '-v' ]:
69
 
                                the.verbose += 1
 
70
                                the.repo = optarg
70
71
                        elif opt == "--help":
71
72
                                self.print_help()
72
 
                
 
73
 
73
74
                # discard first argument (the command)
74
75
                args.pop( 0 )
75
76
 
81
82
        def run( self ):
82
83
 
83
84
                # set up repo and check it exists
84
 
                the.set_repo( self.repo )
85
85
                the.repo.check_dir_exists()
86
86
 
87
87
                # initialise deployment
88
88
                deployment = Deployment()
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!" )
 
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!" )
92
94
 
93
95
                # check for local changes
94
 
                if the.verbose: print "reverting %s" % the.repo.dir
 
96
                if the.verbose >= 1: print "reverting %s" % the.repo.dir
95
97
                the.repo.vcs.revert( deployment.get_initial_revno() )
96
98
 
97
99
                # remove deployment state