/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/program.py

  • Committer: Tim Marston
  • Date: 2014-03-19 20:01:06 UTC
  • Revision ID: tim@ed.am-20140319200106-ou5y1nat6y2auaue
removed square brackets from AC_INIT parameter

Show diffs side-by-side

added added

removed removed

19
19
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
20
 
21
21
 
22
 
import os, sys, getopt, ConfigParser
 
22
import os, sys, getopt
23
23
import the
24
24
from vcs.vcs import Vcs
25
25
 
65
65
#               print "  remove        remove a local file from the repository"
66
66
                print "  status        list files that have changed locally"
67
67
                print "  diff          shows changes made to local files"
68
 
                print "  revert        undo changes made to local files"
69
 
#               print "  stage-add     add (but don't commit) files/changes to local repository"
70
 
#               print "  stage-remove  delete *but don't comit) files from the local repository"
71
 
                print "  stage-revert  revert changes in the local repository"
72
 
#               print "  stage-status  show status of local repository"
73
 
#               print "  stage-diff    shows changes in local repository"
74
 
#               print "  stage-commit  commit changes in the local repository"
 
68
#               print "  revert        undo changes made to a local file"
 
69
#               print "  stage-add     stage local files/changes"
 
70
#               print "  stage-remove  stage the removal of files"
 
71
                print "  stage-revert  revert staged changes"
 
72
#               print "  stage-status  show status of staging area"
 
73
#               print "  stage-diff    shows staged changes"
 
74
#               print "  stage-commit  commit staged changes to repository"
75
75
                print
76
76
                print "For help about a particular command (including the additional options that the"
77
77
                print "command accepts) try typing:"
123
123
                return None
124
124
 
125
125
 
 
126
        def get_command_argument( self, args ):
 
127
                """
 
128
                Find the first program argument what isn't an option argument.
 
129
 
 
130
        Arguments:
 
131
        - `args`: the program arguments
 
132
        """
 
133
                while args:
 
134
                        if args[ 0 ] == '--':
 
135
                                return args[ 1 ] if len( args ) > 1 else None
 
136
                        if args[ 0 ][ 0 : 1 ] != '-':
 
137
                                return args[ 0 ]
 
138
                        args = args[ 1 : ]
 
139
                return None
 
140
 
 
141
 
126
142
        def run( self ):
127
143
                # make an initial attempt to parse the command line, looking only for
128
144
                # --help and --version, so that they have the chance to run without a
145
161
                        # ignore errors -- we aren't parsing the command line properly yet
146
162
                        pass
147
163
 
148
 
                # read program configuration
149
 
                self.read_config()
150
 
 
151
 
                # the first argument should be the command
152
 
                the.command = sys.argv[ 1 ] if len( sys.argv ) > 1 else None
 
164
                # find the first non-option argument (the command)
 
165
                the.command = self.get_command_argument( sys.argv[ 1: ] )
153
166
                if the.command == None:
154
167
                        self.print_usage( "missing command" )
155
168
 
172
185
                                                         fromlist = [ class_name ] )
173
186
                instance = getattr( module, class_name )()
174
187
 
175
 
                # fully parse the command line, as per the command
 
188
                # run the command
176
189
                try:
177
190
                        instance.parse_command_line()
 
191
                        instance.run()
178
192
                except( getopt.GetoptError, self.UsageError ) as e:
179
193
                        self.print_usage( e.msg )
180
 
                except self.FatalError as e:
181
 
                        self.die( e.msg )
182
 
 
183
 
                # do late initialisation
184
 
                the.late_init()
185
 
 
186
 
                # run the command
187
 
                try:
188
 
                        instance.run()
189
194
                except Vcs.VcsError as e:
190
195
                        message = e.msg.rstrip()
191
196
                        if the.verbose:
195
200
                        self.die( e.msg )
196
201
 
197
202
 
198
 
        def read_config( self ):
199
 
                config = ConfigParser.SafeConfigParser( allow_no_value = True )
200
 
                config.read( the.config_file )
201
 
                if config.has_option( 'stdhome', 'home-dir' ):
202
 
                        the.home_dir = config.get( 'stdhome', 'home-dir' )
203
 
 
204
 
 
205
203
        class UsageError( Exception ):
206
204
 
207
205
                def __init__( self, error_message ):