/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-07-17 18:17:18 UTC
  • Revision ID: tim@ed.am-20140717181718-gxi5lpi8qszsigxf
switch to using bzr+ssh, rather than sftp (to work around broken pimiko)

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
 
23
from command import Command
 
24
import stdhome.the as the
 
25
from stdhome.deployment import Deployment
 
26
 
 
27
 
 
28
class StageRevertCommand( Command ):
32
29
 
33
30
 
34
31
        def print_help( self ):
35
 
                print "Usage: " + the.program.name + " update [--repo=REPO]"
 
32
                print "Usage: " + the.program.name + " stage-revert [--repo=REPO]"
36
33
                print
37
34
                #      01234567890123456789012345678901234567890123456789012345678901234567890123456789
38
35
                print "Revert any modifications made to a local repository, losing those changes."
63
60
                                if not re.match( '^[-a-zA-z0-9.]+$', optarg ):
64
61
                                        raise the.program.FatalError(
65
62
                                                'invalid repository name: ' + optarg )
66
 
                                self.repo = optarg
 
63
                                the.repo = optarg
67
64
                        elif opt in [ '--verbose', '-v' ]:
68
 
                                the.verbose = True
 
65
                                the.verbose += 1
69
66
                        elif opt == "--help":
70
67
                                self.print_help()
71
68
                
80
77
        def run( self ):
81
78
 
82
79
                # set up repo and check it exists
83
 
                the.set_repo( self.repo )
84
80
                the.repo.check_dir_exists()
85
81
 
86
 
                # check there isn't a deployment in progress
 
82
                # initialise deployment
87
83
                deployment = Deployment()
88
 
                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!" )
89
87
 
90
88
                # check for local changes
91
 
                if the.verbose: print "reverting %s" % the.repo.dir
92
 
                the.repo.vcs.revert()
 
89
                if the.verbose >= 1: print "reverting %s" % the.repo.dir
 
90
                the.repo.vcs.revert( deployment.get_initial_revno() )
 
91
 
 
92
                # remove deployment state
 
93
                deployment.remove_deployment_state()