/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-05 22:30:23 UTC
  • Revision ID: tim@ed.am-20140405223023-3co87mbvnxwk1l65
added revert command

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 )
79
69
                # remaining arguments
80
70
                self.files = args
81
71
 
82
 
                # check that either files or --all was given
83
 
                if len( self.files ) == 0 and not self.all:
84
 
                        raise the.program.UsageError(
85
 
                                "no files were specified and --all was not given" )
86
 
                if len( self.files ) > 0 and self.all:
87
 
                        raise the.program.UsageError(
88
 
                                "files specified, which conflicts with using --all" )
89
 
 
90
72
 
91
73
        def run( self ):
92
74