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 ):
36
32
def print_help( self ):
37
print "Usage: " + the.program.name + " status [--repo=REPO]"
33
print("Usage: " + the.program.name + " status [--repo=REPO] [FILE]...")
39
35
# 01234567890123456789012345678901234567890123456789012345678901234567890123456789
40
print "Show the state of files in the local repository (including modifications and"
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."
48
print "For help with adding modified files to the repository, type:"
49
print " " + the.program.name + " add --help"
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"
36
print("Show the state of files in your home directory (including modifications and")
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.")
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")
61
54
[ "repo=", "verbose", "help" ] )
62
55
for opt, optarg in opts:
63
56
if opt in [ '--repo', '-r' ]:
64
if not re.match( '^[-a-zA-z0-9.]+$', optarg ):
57
if not re.search( '^[-a-zA-z0-9.]+$', optarg ):
65
58
raise the.program.FatalError(
66
59
'invalid repository name: ' + optarg )
68
61
elif opt in [ '--verbose', '-v' ]:
70
63
elif opt == "--help":
73
66
# discard first argument (the command)
76
69
# remaining arguments
78
raise the.program.UsageError( 'too many arguments' )
83
75
# set up repo and check it exists
84
the.set_repo( self.repo )
85
76
the.repo.check_dir_exists()
79
files = self.expand_files( self.files )
89
83
# initialise deployment and check if it's ongoing
90
84
deployment = Deployment()
91
85
if deployment.is_ongoing():
86
print("deployment ongoing")
93
88
# check for conflicts in repo
94
89
files = the.repo.vcs.get_conflicts()
96
message += 'Conflicts in %s:\n %s\n' % \
91
message += 'conflicts in %s:\n %s\n' % \
97
92
( the.repo.name, '\n '.join( files ) )
99
94
# get deployment conflicts
100
95
conflicts = deployment.get_conflicts()
102
message += 'Deployment conflicts:\n %s\n' % \
97
message += 'deployment conflicts:\n %s\n' % \
103
98
'\n '.join( conflicts )
108
walker = StatusWalker()
103
walker = StatusWalker( files if files else None )
110
105
if walker.modified:
111
message += 'Modified:\n %s\n' % \
106
message += 'modified:\n %s\n' % \
112
107
'\n '.join( walker.modified )
113
108
if walker.missing:
114
message += 'Missing:\n %s\n' % \
109
message += 'missing:\n %s\n' % \
115
110
'\n '.join( walker.missing )
116
111
if walker.changed:
117
message += 'Type changed:\n %s\n' % \
112
message += 'kind changed:\n %s\n' % \
118
113
'\n '.join( walker.changed )
121
if message: print message.rstrip()
116
if message: print(message.rstrip())