Passing Variable(s) as kwargs

BJ Swope bigblueswope at gmail.com
Mon Dec 6 11:40:21 EST 2010


Hello All.

I am trying to use values, retrieved from a config file, as kwargs and not
having any luck.  Well at least I think that's what I'm trying to do ;)

Any suggestions would be most appreciated.

Here's the exception:

Traceback (most recent call last):
  File "c:\dev\LogServerMonitor\LogServerMonitor.py", line 246, in <module>
    sched.add_cron_job(check_logging_db, minute = '*/run_interval_quantity')
  File "c:\Python26\lib\site-packages\apscheduler\scheduler.py", line 249,
in add_cron_job
    second)
  File "c:\Python26\lib\site-packages\apscheduler\triggers.py", line 22, in
__init__
    self._compile_expressions(minutes, 'minute')
  File "c:\Python26\lib\site-packages\apscheduler\triggers.py", line 43, in
_compile_expressions
    compiled_expr_list = [compile_single(expr) for expr in expr_list]
  File "c:\Python26\lib\site-packages\apscheduler\triggers.py", line 36, in
compile_single
    (expr, fieldname))
ValueError: Unrecognized expression "*/run_interval_quantity" for field
"minute"



An example of what I am doing is:
######################################################################################
Config File Contents:
[RunInterval]
#How often the application queries the DB to look for the date of
#the last entry (Default every 1 Minute).

#Valid RunInterval Quantities are integers > 0
RunIntervalQuantity: 1

#Valid RunInterval Types are S=Seconds, M=Minutes, H=Hours, D=Days
RunIntervalType: M

##############################################################################################

My Code


config = ConfigParser.ConfigParser()
try:
    config.readfp(open(config_file))
except:
    sys.stderr.write('Config file, "%s", is missing or unreadable. Exiting.'
% config_file)
    sys.stderr.write('ERROR: %s\r\n' % str(err))
    sys.exit(1)


def getOption(section, option):
    try:
        opt_value = config.get(section, option)
        return opt_value
    except (ConfigParser.NoOptionError), err:
        sys.stderr.write( "Application requires \"%s\" be defined in the
[%s] section of the config file %s\r\n" % (option, section, config_file))
        sys.stderr.write('ERROR: %s\r\n' % str(err))
        sys.exit(1)

def getOptionInt(section, option):
    try:
        opt_value = config.getint(section, option)
        return opt_value
    except (ValueError, ConfigParser.NoOptionError), err:
        sys.stderr.write("Application requires \"%s\" be defined as an
Integer in the \"[%s]\" section of the config file %s" % (option, section,
config_file))
        sys.stderr.write('ERROR: %s\r\n' % str(err))
        sys.exit(1)



# Start the scheduler
sched = Scheduler()
sched.start()
run_interval_quantity = getOptionInt('RunInterval', 'RunIntervalQuantity')
run_interval_type = getOption('RunInterval', 'RunIntervalType')

if run_interval_type in ['S', 's']:
    sched.add_cron_job(check_logging_db, second = '*/run_interval_quantity')
elif run_interval_type in ['M', 'm']:
    sched.add_cron_job(check_logging_db, minute = '*/run_interval_quantity')

elif run_interval_type in ['H', 'h']:
    sched.add_cron_job(check_logging_db, hour = '*/run_interval_quantity')
elif run_interval_type in ['D', 'd']:
    sched.add_cron_job(check_logging_db, day = '*/run_interval_quantity')
else:
    my_logger.warning('The value of RunIntervalType in the configuration
file section RunInterval was not one of "S, M, H or D". Running
LogServerMonitor application once per minute by default.')
    sched.add_cron_job(check_logging_db, minute = '*')
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20101206/bf5eeecd/attachment.html>


More information about the Python-list mailing list