/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: 2014-04-12 12:53:54 UTC
  • Revision ID: tim@ed.am-20140412125354-64aysxvaz7nnk8hm
make verbose levels clearer

Show diffs side-by-side

added added

removed removed

29
29
class RevertCommand( Command ):
30
30
 
31
31
 
32
 
        def __init__( self ):
33
 
                self.all = False
34
 
                self.quiet = False
35
 
 
36
 
 
37
32
        def print_help( self ):
38
 
                print "Usage: " + the.program.name + " revert [--repo=REPO] [--all] [FILE]..."
 
33
                print "Usage: " + the.program.name + " revert [--repo=REPO] [FILE]..."
39
34
                print
40
35
                #      01234567890123456789012345678901234567890123456789012345678901234567890123456789
41
36
                print "Revert any local changes to a file in the home directory."
42
37
                print
43
38
                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."
 
39
                print "relative to the home directory, to its state in the repo."
48
40
                print
49
41
                print "To see a list files that can be reverted, type:"
50
42
                print "    " + the.program.name + " status"
51
43
                print
52
44
                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
45
                print "  -r, --repo=REPO  select the repo to check-out or create (defaults to 'home')"
56
46
                print "  -v, --verbose    display information about what is being done"
57
47
                print "      --help       display help and exit"
61
51
        def parse_command_line( self ):
62
52
                opts, args = getopt.gnu_getopt(
63
53
                        sys.argv[ 1: ], "r:v",
64
 
                        [ "all", "quiet", "repo=", "verbose", "help" ] )
 
54
                        [ "repo=", "verbose", "help" ] )
65
55
                for opt, optarg in opts:
66
 
                        if opt == "--all":
67
 
                                self.all = True
68
 
                        elif opt == "--quiet":
69
 
                                self.quiet = True
70
 
                        elif opt in [ '--repo', '-r' ]:
71
 
                                if not re.search( '^[-a-zA-z0-9.]+$', optarg ):
 
56
                        if opt in [ '--repo', '-r' ]:
 
57
                                if not re.match( '^[-a-zA-z0-9.]+$', optarg ):
72
58
                                        raise the.program.FatalError(
73
59
                                                'invalid repository name: ' + optarg )
74
60
                                the.repo = optarg
75
 
                        elif opt in [ '-v', '--verbose' ]:
 
61
                        elif opt in [ '--verbose', '-v' ]:
76
62
                                the.verbose += 1
77
63
                        elif opt == "--help":
78
64
                                self.print_help()
79
 
 
 
65
                
80
66
                # discard first argument (the command)
81
67
                args.pop( 0 )
82
68
 
83
69
                # remaining arguments
84
70
                self.files = args
85
71
 
86
 
                # check that either files or --all was given
87
 
                if len( self.files ) == 0 and not self.all:
88
 
                        raise the.program.UsageError(
89
 
                                "no files were specified and --all was not given" )
90
 
                if len( self.files ) > 0 and self.all:
91
 
                        raise the.program.UsageError(
92
 
                                "files specified, which conflicts with using --all" )
93
 
 
94
72
 
95
73
        def run( self ):
96
74
 
108
86
                if the.repo.vcs.has_changes():
109
87
                        raise the.program.FatalError(
110
88
                                'repo has local changes: %s\n'
111
 
                                'Hint: see "%s stage-revert --help"' %
 
89
                                'Hint: see "%s stage-revert --help"' % 
112
90
                                ( the.repo.name, the.program.name ) )
113
91
 
114
92
                # check status
115
 
                walker = CopyOutWalker( files if files else None, not self.quiet )
 
93
                walker = CopyOutWalker( files if files else None )
116
94
                walker.walk()