/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-04-18 15:00:34 UTC
  • Revision ID: tim@ed.am-20140418150034-l94wfs6ururhi9t5
fixed error in walker.py (from last checkin)

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
from config import Config
24
25
from vcs.vcs import Vcs
25
26
 
26
27
 
123
124
                return None
124
125
 
125
126
 
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
 
 
142
127
        def run( self ):
143
128
                # make an initial attempt to parse the command line, looking only for
144
129
                # --help and --version, so that they have the chance to run without a
162
147
                        pass
163
148
 
164
149
                # read program configuration
165
 
                self.read_config()
 
150
                the.config = Config()
166
151
 
167
 
                # find the first non-option argument (the command)
168
 
                the.command = self.get_command_argument( sys.argv[ 1: ] )
 
152
                # the first argument should be the command
 
153
                the.command = sys.argv[ 1 ] if len( sys.argv ) > 1 else None
169
154
                if the.command == None:
170
155
                        self.print_usage( "missing command" )
171
156
 
204
189
                        instance.run()
205
190
                except Vcs.VcsError as e:
206
191
                        message = e.msg.rstrip()
207
 
                        if the.verbose:
 
192
                        if the.verbose >= 1:
208
193
                                message += '\n\nOUTPUT:\n' + e.output.rstrip()
209
194
                        self.die( message )
210
195
                except self.FatalError as e:
211
196
                        self.die( e.msg )
212
197
 
213
198
 
214
 
        def read_config( self ):
215
 
                config = ConfigParser.SafeConfigParser( allow_no_value = True )
216
 
                config.read( the.config_file )
217
 
                if config.has_option( 'stdhome', 'home-dir' ):
218
 
                        the.home_dir = config.get( 'stdhome', 'home-dir' )
219
 
 
220
 
 
221
199
        class UsageError( Exception ):
222
200
 
223
201
                def __init__( self, error_message ):