Add JCL console
JCL console can be used to access a SQLObject preconfigured context with usual JCL config file darcs-hash:20080307155037-86b55-39e5ac88498f37d4fe4ed4850d23b75c7c8a3490.gz
This commit is contained in:
@@ -32,12 +32,14 @@ import jcl.model as model
|
|||||||
from jcl.model.account import Account, PresenceAccount, User, LegacyJID
|
from jcl.model.account import Account, PresenceAccount, User, LegacyJID
|
||||||
|
|
||||||
class JCLRunner(object):
|
class JCLRunner(object):
|
||||||
|
|
||||||
def __init__(self, component_name, component_version):
|
def __init__(self, component_name, component_version):
|
||||||
"""
|
"""
|
||||||
options: list of tuples:
|
options: list of tuples:
|
||||||
- short_opt: same as getopt
|
- short_opt: same as getopt
|
||||||
- long_opt: same as getopt
|
- long_opt: same as getopt
|
||||||
"""
|
"""
|
||||||
|
self.component_short_name = "JCL"
|
||||||
self.component_name = component_name
|
self.component_name = component_name
|
||||||
self.component_version = component_version
|
self.component_version = component_version
|
||||||
self.config_file = "jcl.conf"
|
self.config_file = "jcl.conf"
|
||||||
@@ -50,6 +52,7 @@ class JCLRunner(object):
|
|||||||
self.pid_file = "/var/run/jabber/jcl.pid"
|
self.pid_file = "/var/run/jabber/jcl.pid"
|
||||||
self.log_stdout = False
|
self.log_stdout = False
|
||||||
self.log_file = None
|
self.log_file = None
|
||||||
|
self.console = False
|
||||||
self.options = [("c:", "config-file=", None,
|
self.options = [("c:", "config-file=", None,
|
||||||
" FILE\t\t\t\tConfiguration file to use",
|
" FILE\t\t\t\tConfiguration file to use",
|
||||||
lambda arg: self.set_attr("config_file", arg)),
|
lambda arg: self.set_attr("config_file", arg)),
|
||||||
@@ -77,6 +80,9 @@ class JCLRunner(object):
|
|||||||
("d", "debug", None,
|
("d", "debug", None,
|
||||||
"\t\t\t\t\tEnable debug traces",
|
"\t\t\t\t\tEnable debug traces",
|
||||||
lambda arg: self.set_attr("debug", True)),
|
lambda arg: self.set_attr("debug", True)),
|
||||||
|
("C", "console", None,
|
||||||
|
"\t\t\t\t\tRun in console mode",
|
||||||
|
lambda arg: self.set_attr("console", True)),
|
||||||
("o", "log-stdout", None,
|
("o", "log-stdout", None,
|
||||||
"\t\t\t\t\tLog on stdout",
|
"\t\t\t\t\tLog on stdout",
|
||||||
lambda arg: self.set_attr("log_stdout", True)),
|
lambda arg: self.set_attr("log_stdout", True)),
|
||||||
@@ -198,21 +204,24 @@ class JCLRunner(object):
|
|||||||
pidfile.close()
|
pidfile.close()
|
||||||
|
|
||||||
def _run(self, run_func):
|
def _run(self, run_func):
|
||||||
try:
|
if self.console:
|
||||||
self.setup_pidfile()
|
self.run_console()
|
||||||
model.db_connection_str = self.db_url
|
else:
|
||||||
model.db_connect()
|
try:
|
||||||
self.setup_db()
|
self.setup_pidfile()
|
||||||
model.db_disconnect()
|
model.db_connection_str = self.db_url
|
||||||
self.logger.debug(self.component_name + " v" +
|
model.db_connect()
|
||||||
self.component_version + " is starting ...")
|
self.setup_db()
|
||||||
restart = True
|
model.db_disconnect()
|
||||||
while restart:
|
self.logger.debug(self.component_name + " v" +
|
||||||
restart = run_func()
|
self.component_version + " is starting ...")
|
||||||
self.logger.debug(self.component_name + " is exiting")
|
restart = True
|
||||||
finally:
|
while restart:
|
||||||
if os.path.exists(self.pid_file):
|
restart = run_func()
|
||||||
os.remove(self.pid_file)
|
self.logger.debug(self.component_name + " is exiting")
|
||||||
|
finally:
|
||||||
|
if os.path.exists(self.pid_file):
|
||||||
|
os.remove(self.pid_file)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
def run_func():
|
def run_func():
|
||||||
@@ -226,6 +235,22 @@ class JCLRunner(object):
|
|||||||
return component.run()
|
return component.run()
|
||||||
self._run(run_func)
|
self._run(run_func)
|
||||||
|
|
||||||
|
def run_console(self):
|
||||||
|
"""
|
||||||
|
Run JCL console. Used to access SQLObject connection
|
||||||
|
"""
|
||||||
|
from IPython.Shell import IPShellEmbed
|
||||||
|
# pre-import jcl.model.account to be used in the shell
|
||||||
|
import jcl.model.account as account
|
||||||
|
model.db_connection_str = self.db_url
|
||||||
|
model.db_connect()
|
||||||
|
self.setup_db()
|
||||||
|
ipshell = IPShellEmbed(["-pi1", self.component_short_name + "[\\#]: "],
|
||||||
|
"Starting " + self.component_name + " v" \
|
||||||
|
+ self.component_version + " console.",
|
||||||
|
"Ending " + self.component_name + " v" \
|
||||||
|
+ self.component_version + " console.")
|
||||||
|
ipshell()
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
import sys
|
import sys
|
||||||
|
|||||||
Reference in New Issue
Block a user