summaryrefslogtreecommitdiff
path: root/python/skytools/scripting.py
diff options
context:
space:
mode:
authorMarko Kreen2008-02-28 10:02:33 +0000
committerMarko Kreen2008-02-28 10:02:33 +0000
commit64cf02fe503d4169181bb971828c10ccbb2f6780 (patch)
treef9c4ab81f739ac85987138ea701ecd868ed1bca4 /python/skytools/scripting.py
parent8d358469aee6dab496e2b00e60b8843c1eec97c1 (diff)
allow config-less operation
Diffstat (limited to 'python/skytools/scripting.py')
-rw-r--r--python/skytools/scripting.py31
1 files changed, 16 insertions, 15 deletions
diff --git a/python/skytools/scripting.py b/python/skytools/scripting.py
index 08412926..cb6ee802 100644
--- a/python/skytools/scripting.py
+++ b/python/skytools/scripting.py
@@ -88,7 +88,7 @@ def run_single_process(runnable, daemon, pidfile):
_log_config_done = 0
_log_init_done = {}
-def _init_log(job_name, cf, log_level):
+def _init_log(job_name, service_name, cf, log_level):
"""Logging setup happens here."""
global _log_init_done, _log_config_done
@@ -100,13 +100,14 @@ def _init_log(job_name, cf, log_level):
# python logging.config braindamage:
# cannot specify external classess without such hack
logging.skylog = skytools.skylog
+ skytools.skylog.set_service_name(service_name)
# load general config
list = ['skylog.ini', '~/.skylog.ini', '/etc/skylog.ini']
for fn in list:
fn = os.path.expanduser(fn)
if os.path.isfile(fn):
- defs = {'job_name': job_name}
+ defs = {'job_name': job_name, 'service_name': service_name}
logging.config.fileConfig(fn, defs)
got_skylog = 1
break
@@ -268,17 +269,13 @@ class DBScript(object):
if len(self.args) < 1:
print "need config file"
sys.exit(1)
- conf_file = self.args[0]
- # load config
- self.cf = Config(self.service_name, conf_file)
- self.job_name = self.cf.get("job_name", self.service_name)
- self.pidfile = self.cf.getfile("pidfile", '')
-
+ # read config file
+ self.cf = self.load_config()
self.reload()
# init logging
- self.log = _init_log(self.job_name, self.cf, self.log_level)
+ self.log = _init_log(self.job_name, self.service_name, self.cf, self.log_level)
# send signal, if needed
if self.options.cmd == "kill":
@@ -288,6 +285,10 @@ class DBScript(object):
elif self.options.cmd == "reload":
self.send_signal(signal.SIGHUP)
+ def load_config(self):
+ conf_file = self.args[0]
+ return Config(self.service_name, conf_file)
+
def init_optparse(self, parser = None):
"""Initialize a OptionParser() instance that will be used to
parse command line arguments.
@@ -358,6 +359,8 @@ class DBScript(object):
def reload(self):
"Reload config."
self.cf.reload()
+ self.job_name = self.cf.get("job_name", self.service_name)
+ self.pidfile = self.cf.getfile("pidfile", '')
self.loop_delay = self.cf.getfloat("loop_delay", 1.0)
def hook_sighup(self, sig, frame):
@@ -410,11 +413,9 @@ class DBScript(object):
if cache in self.db_cache:
dbc = self.db_cache[cache]
else:
- if connstr:
- loc = connstr
- else:
- loc = self.cf.get(dbname)
- dbc = DBCachedConn(cache, loc, max_age)
+ if not connstr:
+ connstr = self.cf.get(dbname)
+ dbc = DBCachedConn(cache, connstr, max_age)
self.db_cache[cache] = dbc
return dbc.get_connection(autocommit, isolation_level)
@@ -506,7 +507,7 @@ class DBScript(object):
str(tb), repr(traceback.format_tb(tb))))
del tb
self.reset()
- if self.looping:
+ if self.looping and not self.do_single_loop:
time.sleep(20)
return 1