/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: 2016-12-13 21:40:34 UTC
  • Revision ID: tim@ed.am-20161213214034-nd5t7ztnlrjd627i
fix add command and generic filename expansion/resolution to expend to
homedir-relative filename and absolute filename based on original filename, as
specified, rather than a fully, symlink-resolved filename.  So, e.g., if ~/bob
was a symlink to ~/fred, then ~/bob/a would resolve to the relative filename
bob/a, becuase it is inside the homedir (it would resolve to fred/a otherwise)

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