/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:40:42 UTC
  • Revision ID: tim@ed.am-20140308004042-j5rco14bjp3teegj
updated .bzrignore

Show diffs side-by-side

added added

removed removed

1
 
# stage_revert.py
 
1
# command_stage_revert.py
2
2
#
3
3
# Copyright (C) 2014 Tim Marston <tim@edm.am>
4
4
#
20
20
 
21
21
 
22
22
import sys, re, getopt
23
 
from command import Command
24
 
import stdhome.the as the
25
 
from stdhome.deployment import Deployment
26
 
 
27
 
 
28
 
class StageRevertCommand( Command ):
 
23
import the
 
24
from deployment import Deployment
 
25
 
 
26
 
 
27
class CommandStageRevert:
29
28
 
30
29
 
31
30
        def __init__( self ):
 
31
                self.repo = None
32
32
                self.force = False
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)"
 
52
                print "      --force      disregard any ongoing deployment"
53
53
                print "  -r, --repo=REPO  select the repo to check-out or create (defaults to 'home')"
54
54
                print "  -v, --verbose    display information about what is being done"
55
55
                print "      --help       display help and exit"
61
61
                        sys.argv[ 1: ], "r:v",
62
62
                        [ "force", "repo=", "verbose", "help" ] )
63
63
                for opt, optarg in opts:
64
 
                        if opt == "--force":
 
64
                        if opt == '--force':
65
65
                                self.force = True
66
 
                        elif opt in [ '--repo', '-r' ]:
67
 
                                if not re.search( '^[-a-zA-z0-9.]+$', optarg ):
 
66
                        if opt in [ '--repo', '-r' ]:
 
67
                                if not re.match( '^[-a-zA-z0-9.]+$', optarg ):
68
68
                                        raise the.program.FatalError(
69
69
                                                'invalid repository name: ' + optarg )
70
 
                                the.repo = optarg
 
70
                                self.repo = optarg
 
71
                        elif opt in [ '--verbose', '-v' ]:
 
72
                                the.verbose = True
71
73
                        elif opt == "--help":
72
74
                                self.print_help()
73
 
 
 
75
                
74
76
                # discard first argument (the command)
75
77
                args.pop( 0 )
76
78
 
82
84
        def run( self ):
83
85
 
84
86
                # set up repo and check it exists
 
87
                the.set_repo( self.repo )
85
88
                the.repo.check_dir_exists()
86
89
 
87
 
                # initialise deployment
 
90
                # check there isn't a deployment in progress
88
91
                deployment = Deployment()
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
                if not self.force:
 
93
                        deployment.check_ongoing( False )
94
94
 
95
95
                # check for local changes
96
 
                if the.verbose >= 1: print "reverting %s" % the.repo.dir
97
 
                the.repo.vcs.revert( deployment.get_initial_revno() )
 
96
                if the.verbose: print "reverting %s" % the.repo.dir
 
97
                the.repo.vcs.revert()
98
98
 
99
 
                # remove deployment state
100
 
                deployment.remove_deployment_state()
 
99
                # remove deployment state, as necessary
 
100
                if self.force:
 
101
                        deployment.remove_deployment_state()