/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:
20
20
 
21
21
 
22
22
import sys, re, getopt
23
 
from .command import Command
 
23
from command import Command
24
24
import stdhome.the as the
25
25
from stdhome.deployment import Deployment
26
26
from stdhome.walker.status import StatusWalker
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]...")
34
 
                print()
 
37
                print "Usage: " + the.program.name + " status [--repo=REPO]"
 
38
                print
35
39
                #      01234567890123456789012345678901234567890123456789012345678901234567890123456789
36
 
                print("Show the state of files in your home directory (including modifications and")
37
 
                print("conflicts).")
38
 
                print()
39
 
                print("This lists files in your home directory that have been modified and which differ")
40
 
                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.")
43
 
                print()
44
 
                print("Options:")
45
 
                print("  -r, --repo=REPO  select the repo to check-out or create (defaults to 'home')")
46
 
                print("  -v, --verbose    display information about what is being done")
47
 
                print("      --help       display help and exit")
 
40
                print "Show the state of files in the local repository (including modifications and"
 
41
                print "conflicts)."
 
42
                print
 
43
                print "This lists files in your home directory that have been modified and which differ"
 
44
                print "from those in the local repository.  During an update that resulted in conflicts"
 
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."
 
47
                print
 
48
                print "For help with adding modified files to the repository, type:"
 
49
                print "    " + the.program.name + " add --help"
 
50
                print
 
51
                print "Options:"
 
52
                print "  -r, --repo=REPO  select the repo to check-out or create (defaults to 'home')"
 
53
                print "  -v, --verbose    display information about what is being done"
 
54
                print "      --help       display help and exit"
48
55
                exit( 0 )
49
56
 
50
57
 
54
61
                        [ "repo=", "verbose", "help" ] )
55
62
                for opt, optarg in opts:
56
63
                        if opt in [ '--repo', '-r' ]:
57
 
                                if not re.search( '^[-a-zA-z0-9.]+$', optarg ):
 
64
                                if not re.match( '^[-a-zA-z0-9.]+$', optarg ):
58
65
                                        raise the.program.FatalError(
59
66
                                                'invalid repository name: ' + optarg )
60
 
                                the.repo = optarg
 
67
                                self.repo = optarg
61
68
                        elif opt in [ '--verbose', '-v' ]:
62
69
                                the.verbose += 1
63
70
                        elif opt == "--help":
64
71
                                self.print_help()
65
 
 
 
72
                
66
73
                # discard first argument (the command)
67
74
                args.pop( 0 )
68
75
 
69
76
                # remaining arguments
70
 
                self.files = args
 
77
                if len( args ):
 
78
                        raise the.program.UsageError( 'too many arguments' )
71
79
 
72
80
 
73
81
        def run( self ):
74
82
 
75
83
                # set up repo and check it exists
 
84
                the.set_repo( self.repo )
76
85
                the.repo.check_dir_exists()
77
86
 
78
 
                # determine files
79
 
                files = self.expand_files( self.files )
80
 
 
81
87
                message = ''
82
88
 
83
89
                # initialise deployment and check if it's ongoing
84
90
                deployment = Deployment()
85
91
                if deployment.is_ongoing():
86
 
                        print("deployment ongoing")
87
92
 
88
93
                        # check for conflicts in repo
89
94
                        files = the.repo.vcs.get_conflicts()
90
95
                        if files:
91
 
                                message += 'conflicts in %s:\n  %s\n' % \
 
96
                                message += 'Conflicts in %s:\n  %s\n' % \
92
97
                                                   ( the.repo.name, '\n  '.join( files ) )
93
98
 
94
99
                        # get deployment conflicts
95
100
                        conflicts = deployment.get_conflicts()
96
101
                        if conflicts:
97
 
                                message += 'deployment conflicts:\n  %s\n' % \
 
102
                                message += 'Deployment conflicts:\n  %s\n' % \
98
103
                                                   '\n  '.join( conflicts )
99
104
 
100
105
                else:
101
106
 
102
107
                        # check status
103
 
                        walker = StatusWalker( files if files else None )
 
108
                        walker = StatusWalker()
104
109
                        walker.walk()
105
110
                        if walker.modified:
106
 
                                message += 'modified:\n  %s\n' % \
 
111
                                message += 'Modified:\n  %s\n' % \
107
112
                                                   '\n  '.join( walker.modified )
108
113
                        if walker.missing:
109
 
                                message += 'missing:\n  %s\n' % \
 
114
                                message += 'Missing:\n  %s\n' % \
110
115
                                                   '\n  '.join( walker.missing )
111
116
                        if walker.changed:
112
 
                                message += 'kind changed:\n  %s\n' % \
 
117
                                message += 'Type changed:\n  %s\n' % \
113
118
                                                   '\n  '.join( walker.changed )
114
119
 
115
120
                # show status
116
 
                if message: print(message.rstrip())
 
121
                if message: print message.rstrip()