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

  • Committer: Tim Marston
  • Date: 2014-03-08 00:47:23 UTC
  • Revision ID: tim@ed.am-20140308004723-hkl3s2hobsblf72o
added diff command; moved all command to commands subdir; made stage-revert
handle ongoing deployment automatically (now that initial revno is known); made
verbose level incremental; detect obstructing conflicts in ConflictWalker;
handle files deleted from repo during copy-out (update)

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
class StatusCommand( Command ):
30
30
 
31
31
 
 
32
        def __init__( self ):
 
33
                self.repo = None
 
34
 
 
35
 
32
36
        def print_help( self ):
33
 
                print "Usage: " + the.program.name + " status [--repo=REPO] [FILE]..."
 
37
                print "Usage: " + the.program.name + " status [--repo=REPO]"
34
38
                print
35
39
                #      01234567890123456789012345678901234567890123456789012345678901234567890123456789
36
40
                print "Show the state of files in the local repository (including modifications and"
38
42
                print
39
43
                print "This lists files in your home directory that have been modified and which differ"
40
44
                print "from those in the local repository.  During an update that resulted in conflicts"
41
 
                print "this also lists files which have conflicts in the local respository, or which"
42
 
                print "can not be deployed due to conflicts with your home directory."
 
45
                print "this also lists files which have conflicts in the local local respository, or"
 
46
                print "which can not be deployed due to conflicts with your home directory."
43
47
                print
44
48
                print "For help with adding modified files to the repository, type:"
45
49
                print "    " + the.program.name + " add --help"
57
61
                        [ "repo=", "verbose", "help" ] )
58
62
                for opt, optarg in opts:
59
63
                        if opt in [ '--repo', '-r' ]:
60
 
                                if not re.search( '^[-a-zA-z0-9.]+$', optarg ):
 
64
                                if not re.match( '^[-a-zA-z0-9.]+$', optarg ):
61
65
                                        raise the.program.FatalError(
62
66
                                                'invalid repository name: ' + optarg )
63
 
                                the.repo = optarg
 
67
                                self.repo = optarg
 
68
                        elif opt in [ '--verbose', '-v' ]:
 
69
                                the.verbose += 1
64
70
                        elif opt == "--help":
65
71
                                self.print_help()
66
 
 
 
72
                
67
73
                # discard first argument (the command)
68
74
                args.pop( 0 )
69
75
 
70
76
                # remaining arguments
71
 
                self.files = args
 
77
                if len( args ):
 
78
                        raise the.program.UsageError( 'too many arguments' )
72
79
 
73
80
 
74
81
        def run( self ):
75
82
 
76
83
                # set up repo and check it exists
 
84
                the.set_repo( self.repo )
77
85
                the.repo.check_dir_exists()
78
86
 
79
 
                # determine files
80
 
                files = self.expand_files( self.files )
81
 
 
82
87
                message = ''
83
88
 
84
89
                # initialise deployment and check if it's ongoing
85
90
                deployment = Deployment()
86
91
                if deployment.is_ongoing():
87
 
                        print "deployment ongoing"
88
92
 
89
93
                        # check for conflicts in repo
90
94
                        files = the.repo.vcs.get_conflicts()
91
95
                        if files:
92
 
                                message += 'conflicts in %s:\n  %s\n' % \
 
96
                                message += 'Conflicts in %s:\n  %s\n' % \
93
97
                                                   ( the.repo.name, '\n  '.join( files ) )
94
98
 
95
99
                        # get deployment conflicts
96
100
                        conflicts = deployment.get_conflicts()
97
101
                        if conflicts:
98
 
                                message += 'deployment conflicts:\n  %s\n' % \
 
102
                                message += 'Deployment conflicts:\n  %s\n' % \
99
103
                                                   '\n  '.join( conflicts )
100
104
 
101
105
                else:
102
106
 
103
107
                        # check status
104
 
                        walker = StatusWalker( files if files else None )
 
108
                        walker = StatusWalker()
105
109
                        walker.walk()
106
110
                        if walker.modified:
107
 
                                message += 'modified:\n  %s\n' % \
 
111
                                message += 'Modified:\n  %s\n' % \
108
112
                                                   '\n  '.join( walker.modified )
109
113
                        if walker.missing:
110
 
                                message += 'missing:\n  %s\n' % \
 
114
                                message += 'Missing:\n  %s\n' % \
111
115
                                                   '\n  '.join( walker.missing )
112
116
                        if walker.changed:
113
 
                                message += 'kind changed:\n  %s\n' % \
 
117
                                message += 'Type changed:\n  %s\n' % \
114
118
                                                   '\n  '.join( walker.changed )
115
119
 
116
120
                # show status