/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-06 14:09:14 UTC
  • Revision ID: tim@ed.am-20140406140914-lyd6n7proccrcr7v
minor tweaks to variable names and comments

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