/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: 2021-07-05 21:04:21 UTC
  • Revision ID: tim@ed.am-20210705210421-75rb9swyku2397lb
added stage-status to main help

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
 
 
36
32
        def print_help( self ):
37
 
                print "Usage: " + the.program.name + " status [--repo=REPO]"
38
 
                print
 
33
                print("Usage: " + the.program.name + " status [--repo=REPO] [FILE]...")
 
34
                print()
39
35
                #      01234567890123456789012345678901234567890123456789012345678901234567890123456789
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"
 
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")
55
48
                exit( 0 )
56
49
 
57
50
 
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 )
67
 
                                self.repo = optarg
 
60
                                the.repo = optarg
68
61
                        elif opt in [ '--verbose', '-v' ]:
69
62
                                the.verbose += 1
70
63
                        elif opt == "--help":
71
64
                                self.print_help()
72
 
                
 
65
 
73
66
                # discard first argument (the command)
74
67
                args.pop( 0 )
75
68
 
76
69
                # remaining arguments
77
 
                if len( args ):
78
 
                        raise the.program.UsageError( 'too many arguments' )
 
70
                self.files = args
79
71
 
80
72
 
81
73
        def run( self ):
82
74
 
83
75
                # set up repo and check it exists
84
 
                the.set_repo( self.repo )
85
76
                the.repo.check_dir_exists()
86
77
 
 
78
                # determine files
 
79
                files = self.expand_files( self.files )
 
80
 
87
81
                message = ''
88
82
 
89
83
                # initialise deployment and check if it's ongoing
90
84
                deployment = Deployment()
91
85
                if deployment.is_ongoing():
 
86
                        print("deployment ongoing")
92
87
 
93
88
                        # check for conflicts in repo
94
89
                        files = the.repo.vcs.get_conflicts()
95
90
                        if files:
96
 
                                message += 'Conflicts in %s:\n  %s\n' % \
 
91
                                message += 'conflicts in %s:\n  %s\n' % \
97
92
                                                   ( the.repo.name, '\n  '.join( files ) )
98
93
 
99
94
                        # get deployment conflicts
100
95
                        conflicts = deployment.get_conflicts()
101
96
                        if conflicts:
102
 
                                message += 'Deployment conflicts:\n  %s\n' % \
 
97
                                message += 'deployment conflicts:\n  %s\n' % \
103
98
                                                   '\n  '.join( conflicts )
104
99
 
105
100
                else:
106
101
 
107
102
                        # check status
108
 
                        walker = StatusWalker()
 
103
                        walker = StatusWalker( files if files else None )
109
104
                        walker.walk()
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 )
119
114
 
120
115
                # show status
121
 
                if message: print message.rstrip()
 
116
                if message: print(message.rstrip())