Adding Command Line Arguments to Python Twisted -


i still new python keep in mind when reading this.

i have been hacking away @ existing python script "put" few different people.

the script designed load it's 'configuration' using module named "conf/config.py" python code.

setting_name='setting value' 

i've modified instead read it's settings configuration file using configparser:

import configparser config_file_parser = configparser.configparser() config_file_name = "/etc/service_settings.conf" config_file_parser.readfp(open(r'' + config_file_name)) setting_name = config_file_parser.get('basic', 'setting_name') 

the problem having how specify configuration file use. have managed working (somewhat) having multiple tac files , setting "config_file_name" variable there using module hold variable value. example, have module 'conf/configloader.py":

global config_file_name 

then tac file has:

import conf.configloader configloader configloader.config_file_name = '/etc/service_settings.conf' 

so conf/config.py module looks like:

import configloader config_file_parser = configparser.configparser() config_file_parser.readfp(open(r'' + configloader.config_file_name)) 

it works, requires managing 2 files instead of single conf file. attempted use "usage.options" feature described on http://twistedmatrix.com/documents/current/core/howto/options.html. have twisted/plugins/options.py

from twisted.python import usage global config_file_name  class options(usage.options):     optparameters = [['conf', 'c', 'tidepool.conf', 'configuration file']]  # config config = options() config.parseoptions() config_file_name = config.opts['conf'] 

that not work @ all. tips?

i don't know if understood problem.

if want load configuration multiple locations pass list of filenames configparser: https://docs.python.org/2/library/configparser.html#configparser.rawconfigparser.read

if trying make generic configuration manager, create class of functions receives filename or use set configuration file name in environment variable , read variable in script using os.environ.get('config_file_name').


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -