/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-02-26 19:10:31 UTC
  • Revision ID: tim@ed.am-20140226191031-elcqy5j09h2syn2j
moved copy-in, copy-out and deployment conflict checking to a set of "walkers";
bzr vcs back-end now parses affected files during update; deployment state now
includes affected files

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 ):
32
31
                self.repo = None
 
32
                self.force = False
33
33
 
34
34
 
35
35
        def print_help( self ):
49
49
                print "repository."
50
50
                print
51
51
                print "Options:"
 
52
                print "      --force      disregard any ongoing deployment"
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:
 
64
                        if opt == '--force':
 
65
                                self.force = True
63
66
                        if 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
70
                                self.repo = optarg
68
71
                        elif opt in [ '--verbose', '-v' ]:
69
 
                                the.verbose += 1
 
72
                                the.verbose = True
70
73
                        elif opt == "--help":
71
74
                                self.print_help()
72
75
                
84
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
 
                        raise RunteimError(
91
 
                                "can't revert ongoing deployment: initial revno is missing!" )
 
92
                if not self.force:
 
93
                        deployment.check_ongoing( False )
92
94
 
93
95
                # check for local changes
94
96
                if the.verbose: print "reverting %s" % the.repo.dir
95
 
                the.repo.vcs.revert( deployment.get_initial_revno() )
 
97
                the.repo.vcs.revert()
96
98
 
97
 
                # remove deployment state
98
 
                deployment.remove_deployment_state()
 
99
                # remove deployment state, as necessary
 
100
                if self.force:
 
101
                        deployment.remove_deployment_state()