/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-02-26 19:15:30 UTC
  • Revision ID: tim@ed.am-20140226191530-6x21vlwto2xx80cd
renamed updated_files to affected_files

Show diffs side-by-side

added added

removed removed

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