summaryrefslogtreecommitdiff
path: root/python/skytools/scripting.py
diff options
context:
space:
mode:
authorMarko Kreen2011-08-24 08:56:43 +0000
committerMarko Kreen2011-08-24 08:56:43 +0000
commit83fd021a904c8c967fb0ac42766783fbf2ae6c6c (patch)
tree02b8c127a7638cdd11e540324ff0b32f16aa4a4d /python/skytools/scripting.py
parent4f58daa272d731ac64afe7b391ef1a93dfe5ced1 (diff)
parent600501e373633ec305951b03b1e4dd75edbb1751 (diff)
Merge remote-tracking branch 'martino/master'
Diffstat (limited to 'python/skytools/scripting.py')
-rw-r--r--python/skytools/scripting.py32
1 files changed, 14 insertions, 18 deletions
diff --git a/python/skytools/scripting.py b/python/skytools/scripting.py
index 801d3d8f..9834e588 100644
--- a/python/skytools/scripting.py
+++ b/python/skytools/scripting.py
@@ -58,7 +58,7 @@ def signal_pidfile(pidfile, sig):
def daemonize():
"""Turn the process into daemon.
-
+
Goes background and disables all i/o.
"""
@@ -243,7 +243,7 @@ class BaseScript(object):
NB: in case of daemon, the __init__() and startup()/work() will be
run in different processes. So nothing fancy should be done in __init__().
-
+
@param service_name: unique name for script.
It will be also default job_name, if not specified in config.
@param args: cmdline args (sys.argv[1:]), but can be overrided
@@ -297,7 +297,7 @@ class BaseScript(object):
def print_ini(self):
"""Prints out ini file from doc string of the script of default for dbscript
-
+
Used by --ini option on command line.
"""
@@ -353,7 +353,7 @@ class BaseScript(object):
return skytools.Config(self.service_name, conf_file, override = self.cf_override)
def init_optparse(self, parser = None):
- """Initialize a OptionParser() instance that will be used to
+ """Initialize a OptionParser() instance that will be used to
parse command line arguments.
Note that it can be overrided both directions - either DBScript
@@ -400,11 +400,11 @@ class BaseScript(object):
def send_signal(self, sig):
if not self.pidfile:
- self.log.warning("No pidfile in config, nothing todo")
+ self.log.warning("No pidfile in config, nothing to do")
elif os.path.isfile(self.pidfile):
alive = signal_pidfile(self.pidfile, sig)
if not alive:
- self.log.warning("pidfile exist, but process not running")
+ self.log.warning("pidfile exists, but process not running")
else:
self.log.warning("No pidfile, process not running")
sys.exit(0)
@@ -456,10 +456,6 @@ class BaseScript(object):
sys.exit(1)
self.last_sigint = t
- def stat_add(self, key, value):
- """Old, deprecated function."""
- self.stat_put(key, value)
-
def stat_put(self, key, value):
"""Sets a stat value."""
self.stat_dict[key] = value
@@ -599,6 +595,10 @@ class BaseScript(object):
signal.signal(signal.SIGHUP, self.hook_sighup)
signal.signal(signal.SIGINT, self.hook_sigint)
+ # define some aliases (short-cuts / backward compatibility cruft)
+ stat_add = stat_put # Old, deprecated function.
+ stat_inc = stat_increase
+
##
## DBScript
##
@@ -638,7 +638,7 @@ class DBScript(BaseScript):
NB: in case of daemon, the __init__() and startup()/work() will be
run in different processes. So nothing fancy should be done in __init__().
-
+
@param service_name: unique name for script.
It will be also default job_name, if not specified in config.
@param args: cmdline args (sys.argv[1:]), but can be overrided
@@ -653,7 +653,7 @@ class DBScript(BaseScript):
def get_database(self, dbname, autocommit = 0, isolation_level = -1,
cache = None, connstr = None):
"""Load cached database connection.
-
+
User must not store it permanently somewhere,
as all connections will be invalidated on reset.
"""
@@ -683,7 +683,7 @@ class DBScript(BaseScript):
def close_database(self, dbname):
"""Explicitly close a cached connection.
-
+
Next call to get_database() will reconnect.
"""
if dbname in self.db_cache:
@@ -717,7 +717,7 @@ class DBScript(BaseScript):
cname = d.cursor.connection.my_name
dsn = getattr(conn, 'dsn', '?')
sql = getattr(curs, 'query', '?')
- if len(sql) > 200: # avoid logging londiste huge batched queries
+ if len(sql) > 200: # avoid logging londiste huge batched queries
sql = sql[:60] + " ..."
emsg = str(d).strip()
self.log.exception("Job %s got error on connection '%s': %s. Query: %s" % (
@@ -960,7 +960,3 @@ class DBCachedConn(object):
"""
if self.loc != connstr:
self.reset()
-
-
-
-