/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-04-05 17:30:58 UTC
  • Revision ID: tim@ed.am-20140405173058-1oyw150nzmxhbc6o
moved funcitonality of copy-out walker in to base class and made copy-out walker
a specialisation of it

Show diffs side-by-side

added added

removed removed

1
 
# command_stage_revert.py
 
1
# 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
 
import the
24
 
from deployment import Deployment
25
 
 
26
 
 
27
 
class CommandStageRevert:
28
 
 
29
 
 
30
 
        def __init__( self ):
31
 
                self.repo = None
32
 
                self.force = False
 
23
from command import Command
 
24
import stdhome.the as the
 
25
from stdhome.deployment import Deployment
 
26
 
 
27
 
 
28
class StageRevertCommand( Command ):
33
29
 
34
30
 
35
31
        def print_help( self ):
36
 
                print "Usage: " + the.program.name + " update [--repo=REPO]"
 
32
                print "Usage: " + the.program.name + " stage-revert [--repo=REPO]"
37
33
                print
38
34
                #      01234567890123456789012345678901234567890123456789012345678901234567890123456789
39
35
                print "Revert any modifications made to a local repository, losing those changes."
49
45
                print "repository."
50
46
                print
51
47
                print "Options:"
52
 
                print "      --force      disregard any ongoing deployment"
53
48
                print "  -r, --repo=REPO  select the repo to check-out or create (defaults to 'home')"
54
49
                print "  -v, --verbose    display information about what is being done"
55
50
                print "      --help       display help and exit"
59
54
        def parse_command_line( self ):
60
55
                opts, args = getopt.gnu_getopt(
61
56
                        sys.argv[ 1: ], "r:v",
62
 
                        [ "force", "repo=", "verbose", "help" ] )
 
57
                        [ "repo=", "verbose", "help" ] )
63
58
                for opt, optarg in opts:
64
 
                        if opt == '--force':
65
 
                                self.force = True
66
59
                        if opt in [ '--repo', '-r' ]:
67
60
                                if not re.match( '^[-a-zA-z0-9.]+$', optarg ):
68
61
                                        raise the.program.FatalError(
69
62
                                                'invalid repository name: ' + optarg )
70
 
                                self.repo = optarg
 
63
                                the.repo = optarg
71
64
                        elif opt in [ '--verbose', '-v' ]:
72
 
                                the.verbose = True
 
65
                                the.verbose += 1
73
66
                        elif opt == "--help":
74
67
                                self.print_help()
75
68
                
84
77
        def run( self ):
85
78
 
86
79
                # set up repo and check it exists
87
 
                the.set_repo( self.repo )
88
80
                the.repo.check_dir_exists()
89
81
 
90
 
                # check there isn't a deployment in progress
 
82
                # initialise deployment
91
83
                deployment = Deployment()
92
 
                if not self.force:
93
 
                        deployment.check_ongoing( False )
 
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!" )
94
87
 
95
88
                # check for local changes
96
89
                if the.verbose: print "reverting %s" % the.repo.dir
97
 
                the.repo.vcs.revert()
 
90
                the.repo.vcs.revert( deployment.get_initial_revno() )
98
91
 
99
 
                # remove deployment state, as necessary
100
 
                if self.force:
101
 
                        deployment.remove_deployment_state()
 
92
                # remove deployment state
 
93
                deployment.remove_deployment_state()