/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: 2021-09-01 13:06:23 UTC
  • Revision ID: tim@ed.am-20210901130623-2yv2y02e3zwgd07y
fix newlines in resolve command

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:
 
23
from .command import Command
 
24
import stdhome.the as the
 
25
from stdhome.deployment import Deployment
 
26
 
 
27
 
 
28
class StageRevertCommand( Command ):
28
29
 
29
30
 
30
31
        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 + " update [--repo=REPO]"
37
 
                print
 
36
                print("Usage: " + the.program.name + " stage-revert [--repo=REPO]")
 
37
                print()
38
38
                #      01234567890123456789012345678901234567890123456789012345678901234567890123456789
39
 
                print "Revert any modifications made to a local repository, losing those changes."
40
 
                print
41
 
                print "In addition to using the add and remove commands, you can also manually modify"
42
 
                print "the files in a local repository and then commit them to a remote repository as"
43
 
                print "required.  This can be done with the staging commands."
44
 
                print
45
 
                print "When files in your local repository have been modified, several of the primary"
46
 
                print "commands of this program will not be able to function.  This command reverts all"
47
 
                print "modifications to a local repository so that the primary commands can work again."
48
 
                print "If you have not used any of the staging commands, it is safe to revert a local"
49
 
                print "repository."
50
 
                print
51
 
                print "Options:"
52
 
                print "      --force      disregard any ongoing deployment"
53
 
                print "  -r, --repo=REPO  select the repo to check-out or create (defaults to 'home')"
54
 
                print "  -v, --verbose    display information about what is being done"
55
 
                print "      --help       display help and exit"
 
39
                print("Revert any modifications made to a local repository, losing those changes.")
 
40
                print()
 
41
                Command.print_stage_commands_notice()
 
42
                print()
 
43
                print("If you have not used any of the staging commands, it is probably safe to revert")
 
44
                print("a local repository and doing so will allow many primary commands (such as add")
 
45
                print("and remove) to work again.")
 
46
                print()
 
47
                print("Options:")
 
48
                print("      --force      force revert of stage (when there is a problem)")
 
49
                print("  -r, --repo=REPO  select the repo to check-out or create (defaults to 'home')")
 
50
                print("  -v, --verbose    display information about what is being done")
 
51
                print("      --help       display help and exit")
56
52
                exit( 0 )
57
53
 
58
54
 
61
57
                        sys.argv[ 1: ], "r:v",
62
58
                        [ "force", "repo=", "verbose", "help" ] )
63
59
                for opt, optarg in opts:
64
 
                        if opt == '--force':
 
60
                        if opt == "--force":
65
61
                                self.force = True
66
 
                        if opt in [ '--repo', '-r' ]:
67
 
                                if not re.match( '^[-a-zA-z0-9.]+$', optarg ):
 
62
                        elif opt in [ '--repo', '-r' ]:
 
63
                                if not re.search( '^[-a-zA-z0-9.]+$', optarg ):
68
64
                                        raise the.program.FatalError(
69
65
                                                'invalid repository name: ' + optarg )
70
 
                                self.repo = optarg
 
66
                                the.repo = optarg
71
67
                        elif opt in [ '--verbose', '-v' ]:
72
 
                                the.verbose = True
 
68
                                the.verbose += 1
73
69
                        elif opt == "--help":
74
70
                                self.print_help()
75
 
                
 
71
 
76
72
                # discard first argument (the command)
77
73
                args.pop( 0 )
78
74
 
84
80
        def run( self ):
85
81
 
86
82
                # set up repo and check it exists
87
 
                the.set_repo( self.repo )
88
83
                the.repo.check_dir_exists()
89
84
 
90
 
                # check there isn't a deployment in progress
 
85
                # initialise deployment
91
86
                deployment = Deployment()
92
 
                if not self.force:
93
 
                        deployment.check_ongoing( False )
 
87
                if deployment.is_ongoing() and deployment.get_initial_revno() is None \
 
88
                   and not self.force:
 
89
                        raise RuntimeError(
 
90
                                "can't revert ongoing deployment: initial revno is missing!\n"
 
91
                                "use --force to override, but an update may miss changes!" )
94
92
 
95
93
                # check for local changes
96
 
                if the.verbose: print "reverting %s" % the.repo.dir
97
 
                the.repo.vcs.revert()
 
94
                if the.verbose >= 1: print("reverting %s" % the.repo.dir)
 
95
                the.repo.vcs.revert( deployment.get_initial_revno() )
98
96
 
99
 
                # remove deployment state, as necessary
100
 
                if self.force:
101
 
                        deployment.remove_deployment_state()
 
97
                # remove deployment state
 
98
                deployment.remove_deployment_state()