/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-12 21:51:49 UTC
  • Revision ID: tim@ed.am-20140212215149-msaxl7vo98il5i4a
added more commands

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