/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/revert.py

  • Committer: Tim Marston
  • Date: 2021-09-01 12:24:09 UTC
  • Revision ID: tim@ed.am-20210901122409-g52rlxu8sxu1ftn3
updated configure.ac to use python 3.9

Show diffs side-by-side

added added

removed removed

20
20
 
21
21
 
22
22
import sys, re, getopt
23
 
from command import Command
 
23
from .command import Command
24
24
import stdhome.the as the
25
25
from stdhome.deployment import Deployment
26
26
from stdhome.walker.copy_out import CopyOutWalker
31
31
 
32
32
        def __init__( self ):
33
33
                self.all = False
 
34
                self.quiet = False
34
35
 
35
36
 
36
37
        def print_help( self ):
37
 
                print "Usage: " + the.program.name + " revert [--repo=REPO] [--all] [FILE]..."
38
 
                print
 
38
                print("Usage: " + the.program.name + " revert [--repo=REPO] [--all] [FILE]...")
 
39
                print()
39
40
                #      01234567890123456789012345678901234567890123456789012345678901234567890123456789
40
 
                print "Revert any local changes to a file in the home directory."
41
 
                print
42
 
                print "This reverts the content of the named files, in the local filesystem, specified"
43
 
                print "relative to the home directory, to its state in the repo.  Specifying individual"
44
 
                print "files and directories will revert them (recursively, in the case of"
45
 
                print "directories).  Or you can revert all files in your home directory by specifying"
46
 
                print "no files and explicitly using the --all option."
47
 
                print
48
 
                print "To see a list files that can be reverted, type:"
49
 
                print "    " + the.program.name + " status"
50
 
                print
51
 
                print "Options:"
52
 
                print "      --all        confirm that you want to revert all files"
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"
 
41
                print("Revert any local changes to a file in the home directory.")
 
42
                print()
 
43
                print("This reverts the content of the named files, in the local filesystem, specified")
 
44
                print("relative to the home directory, to its state in the repo.  Specifying individual")
 
45
                print("files and directories will revert them (recursively, in the case of")
 
46
                print("directories).  Or you can revert all files in your home directory by specifying")
 
47
                print("no files and explicitly using the --all option.")
 
48
                print()
 
49
                print("To see a list files that can be reverted, type:")
 
50
                print("    " + the.program.name + " status")
 
51
                print()
 
52
                print("Options:")
 
53
                print("      --all        confirm that you want to revert all files")
 
54
                print("      --quiet      do not report changes to the home directory")
 
55
                print("  -r, --repo=REPO  select the repo to check-out or create (defaults to 'home')")
 
56
                print("  -v, --verbose    display information about what is being done")
 
57
                print("      --help       display help and exit")
56
58
                exit( 0 )
57
59
 
58
60
 
59
61
        def parse_command_line( self ):
60
62
                opts, args = getopt.gnu_getopt(
61
63
                        sys.argv[ 1: ], "r:v",
62
 
                        [ "all", "repo=", "verbose", "help" ] )
 
64
                        [ "all", "quiet", "repo=", "verbose", "help" ] )
63
65
                for opt, optarg in opts:
64
66
                        if opt == "--all":
65
67
                                self.all = True
 
68
                        elif opt == "--quiet":
 
69
                                self.quiet = True
66
70
                        elif opt in [ '--repo', '-r' ]:
67
 
                                if not re.match( '^[-a-zA-z0-9.]+$', optarg ):
 
71
                                if not re.search( '^[-a-zA-z0-9.]+$', optarg ):
68
72
                                        raise the.program.FatalError(
69
73
                                                'invalid repository name: ' + optarg )
70
74
                                the.repo = optarg
71
 
                        elif opt in [ '--verbose', '-v' ]:
 
75
                        elif opt in [ '-v', '--verbose' ]:
72
76
                                the.verbose += 1
73
77
                        elif opt == "--help":
74
78
                                self.print_help()
75
 
                
 
79
 
76
80
                # discard first argument (the command)
77
81
                args.pop( 0 )
78
82
 
104
108
                if the.repo.vcs.has_changes():
105
109
                        raise the.program.FatalError(
106
110
                                'repo has local changes: %s\n'
107
 
                                'Hint: see "%s stage-revert --help"' % 
 
111
                                'Hint: see "%s stage-revert --help"' %
108
112
                                ( the.repo.name, the.program.name ) )
109
113
 
110
114
                # check status
111
 
                walker = CopyOutWalker( files if files else None )
 
115
                walker = CopyOutWalker( files if files else None, not self.quiet )
112
116
                walker.walk()