Package jazzparser :: Package utils :: Module config
[hide private]
[frames] | no frames]

Module config

source code

Config file parsing

All of the scripts in this project use the optparse package to handle command line options.

This module provides a very simple mechanism for taking config files as input instead of specifying options on the command line. This is convenient, for example, for running experiments repeatedly where a whole load of options need to be given to set parameters.

The options in the file are stored in the following format:

optname=value

- The files may contain comments beginning with a '#'.
- To specify arguments, just put the argument on a line of its own.
- To specify flags, put the flag name on a line of its own preceded by a +.

You can only use long option names currently. This is best practice anyway, as it makes the file more readable.

The config options are simply transformed into a string of command-line-like options and added to the actual command-line options.

Don't forget to put a comment in the file so you know what script it's for!

Additionally, lines beginning with '%%' are treated as directives.

You may use certain substitutions in the options. %{X} will be replaced by a value if one can be found. The following sources are consulted (in this order):

One purpose of this is to allow you to specify paths relative to the project root, etc, rather than where the script is run.

A linebreak preceded by a \ will be ignored. Whitespace at the start of the subsequent line will be ignored (but not whitespace before the \).


Author: Mark Granroth-Wilding <mark.granroth-wilding@ed.ac.uk>

Classes [hide private]
  ConfigFile
A really simple interface to options stored in config files.
  ConfigFileReadError
Functions [hide private]
 
parse_args_with_config(parser, option_name='config')
An alternative to calling parser.parse_args() which adds a --config option to the parser's options and uses it to read in a config file if it's given.
source code
Variables [hide private]
  __package__ = 'jazzparser.utils'
Function Details [hide private]

parse_args_with_config(parser, option_name='config')

source code 

An alternative to calling parser.parse_args() which adds a --config option to the parser's options and uses it to read in a config file if it's given.

The args will potentially get parsed twice: once to get the config file and then again to incorporate options from the file.

Returns:
(options, arguments) tuple, as given by parser.parse_args().