import wsgiref.handlers import logging import google ## vars periodicals = ['jsb.plugs.common.rss', 'jsb.plugs.core.botevent'] mountpoints = ['rss', 'botevent'] ## logging.info(getversion('TASK')) for plugin in periodicals: plugs.reload(plugin) class TaskHandler(webapp.RequestHandler): """ the bots task handler. """ def get(self): try: """ this is where the task gets dispatched. """ path = self.request.path if path.endswith('/'): path = path[:-1] taskname = path.split('/')[-1].strip() logging.debug("using taskname: %s" % taskname)
def boot(ddir=None, force=False, encoding="utf-8", umask=None, saveperms=True, fast=False, clear=False, loadall=False): """ initialize the bot. """ global plugin_packages try: if os.getuid() == 0: print "don't run the bot as root" os._exit(1) except AttributeError: pass from jsb.lib.datadir import getdatadir, setdatadir if ddir: setdatadir(ddir) origdir = ddir ddir = ddir or getdatadir() if not ddir: logging.error("can't determine datadir to boot from") raise Exception("can't determine datadir") if not ddir in sys.path: sys.path.append(ddir) makedirs(ddir) if os.path.isdir("/var/run/jsb") and botuser() == "jsb": rundir = "/var/run/jsb" else: rundir = ddir + os.sep + "run" try: k = open(rundir + os.sep + 'jsb.pid', 'w') k.write(str(os.getpid())) k.close() except IOError: pass try: reload(sys) sys.setdefaultencoding(encoding) except (AttributeError, IOError): handle_exception() try: if not umask: checkpermissions(getdatadir(), 0700) else: checkpermissions(getdatadir(), umask) except: handle_exception() from jsb.lib.plugins import plugs global loaded global cmndtable global retable global pluginlist global callbacktable global shorttable global cmndperms global timestamps global plugwhitelist global plugblacklist if not retable: retable = Persist(rundir + os.sep + 'retable') if clear: retable.data = {} if not cmndtable: cmndtable = Persist(rundir + os.sep + 'cmndtable') if clear: cmndtable.data = {} if not pluginlist: pluginlist = Persist(rundir + os.sep + 'pluginlist') if clear: pluginlist.data = [] if not callbacktable: callbacktable = Persist(rundir + os.sep + 'callbacktable') if clear: callbacktable.data = {} if not shorttable: shorttable = Persist(rundir + os.sep + 'shorttable') if clear: shorttable.data = {} if not timestamps: timestamps = Persist(rundir + os.sep + 'timestamps') if not plugwhitelist: plugwhitelist = Persist(rundir + os.sep + 'plugwhitelist') if not plugwhitelist.data: plugwhitelist.data = [] if not plugblacklist: plugblacklist = Persist(rundir + os.sep + 'plugblacklist') if not plugblacklist.data: plugblacklist.data = [] if not cmndperms: cmndperms = Config('cmndperms', ddir=ddir) changed = [] gotlocal = False dosave = clear or False maincfg = getmainconfig(ddir=ddir) logging.warn("mainconfig used is %s" % maincfg.cfile) if os.path.isdir('jsb'): gotlocal = True packages = find_packages("jsb" + os.sep + "plugs") pluglist = [x for x in packages if not 'db' in x] for p in pluglist: if p not in plugin_packages: plugin_packages.append(p) for plug in default_plugins: plugs.reload(plug, showerror=True, force=True) changed = scandir(getdatadir() + os.sep + 'myplugs', dbenable=maincfg.dbenable) if changed: logging.debug("myplugs has changed -=- %s" % str(changed)) for plugfile in changed: if "gae" in plugfile: continue try: plugs.reloadfile(plugfile, force=True) except Exception, ex: handle_exception() dosave = True
import wsgiref.handlers import logging import google ## vars periodicals = ['jsb.plugs.common.rss', 'jsb.plugs.core.botevent'] mountpoints = ['rss', 'botevent'] ## logging.info(getversion('TASK')) for plugin in periodicals: plugs.reload(plugin) class TaskHandler(webapp.RequestHandler): """ the bots task handler. """ def get(self): try: """ this is where the task gets dispatched. """ path = self.request.path if path.endswith('/'): path = path[:-1] taskname = path.split('/')[-1].strip() logging.debug("using taskname: %s" % taskname) inputdict = {} for name, value in self.request.environ.iteritems():
def boot(ddir=None, force=False, encoding="utf-8", umask=None, saveperms=True, fast=False): """ initialize the bot. """ logging.info("booting ..") from jsb.lib.datadir import getdatadir, setdatadir if ddir: setdatadir(ddir) origdir = ddir ddir = ddir or getdatadir() if not ddir: logging.error("can't determine datadir to boot from") os._exit(1) if not ddir in sys.path: sys.path.append(ddir) makedirs(ddir) if os.path.isdir("/var/run/jsb") and botuser() == "jsb": rundir = "/var/run/jsb" else: rundir = ddir + os.sep + "run" try: if os.getuid() == 0: print "don't run the bot as root" os._exit(1) except AttributeError: pass try: k = open(rundir + os.sep + 'jsb.pid', 'w') k.write(str(os.getpid())) k.close() except IOError: pass try: if not ongae: reload(sys) sys.setdefaultencoding(encoding) except (AttributeError, IOError): pass try: if not umask: checkpermissions(getdatadir(), 0700) else: checkpermissions(getdatadir(), umask) except: handle_exception() global loaded global cmndtable global pluginlist global callbacktable global cmndperms global plugcommands if not cmndtable: cmndtable = Persist(rundir + os.sep + 'cmndtable') if not pluginlist: pluginlist = Persist(rundir + os.sep + 'pluginlist') if not callbacktable: callbacktable = Persist(rundir + os.sep + 'callbacktable') if not cmndperms: cmndperms = Config('cmndperms', ddir=ddir) from jsb.lib.plugins import plugs if not cmndtable.data or force: plugs.loadall(plugin_packages, force=True) loaded = True savecmndtable(saveperms=saveperms) if not pluginlist.data or force: if not loaded: plugs.loadall(plugin_packages, force=True) loaded = True savepluginlist() if not callbacktable.data or force: if not loaded: plugs.loadall(plugin_packages, force=True) loaded = True savecallbacktable() if not loaded: logging.info("boot - plugins not loaded .. loading defaults") for plug in default_plugins: plugs.reload(plug, showerror=True, force=True) if not fast: if ongae: plugs.loadall(["myplugs.gae", "jsb.plugs.myplugs"], force=True) else: plugs.loadall(["myplugs.socket", "jsb.plugs.myplugs"], force=True) else: logging.error("skipped loading of myplugs") logging.warn("boot - done")
def boot(ddir=None, force=False, encoding="utf-8", umask=None, saveperms=True, fast=False, clear=False, loadall=False): """ initialize the bot. """ global plugin_packages try: if os.getuid() == 0: print "don't run the bot as root" os._exit(1) except AttributeError: pass logging.warn("starting!") from jsb.lib.datadir import getdatadir, setdatadir if ddir: setdatadir(ddir) origdir = ddir ddir = ddir or getdatadir() if not ddir: logging.error("can't determine datadir to boot from") ; raise Exception("can't determine datadir") if not ddir in sys.path: sys.path.append(ddir) makedirs(ddir) if os.path.isdir("/var/run/jsb") and botuser() == "jsb": rundir = "/var/run/jsb" else: rundir = ddir + os.sep + "run" try: k = open(rundir + os.sep + 'jsb.pid','w') k.write(str(os.getpid())) k.close() except IOError: pass try: reload(sys) sys.setdefaultencoding(encoding) except (AttributeError, IOError): handle_exception() try: if not umask: checkpermissions(getdatadir(), 0700) else: checkpermissions(getdatadir(), umask) except: handle_exception() from jsb.lib.plugins import plugs global loaded global cmndtable global retable global pluginlist global callbacktable global shorttable global cmndperms global timestamps global plugwhitelist global plugblacklist if not retable: retable = Persist(rundir + os.sep + 'retable') if clear: retable.data = {} if not cmndtable: cmndtable = Persist(rundir + os.sep + 'cmndtable') if clear: cmndtable.data = {} if not pluginlist: pluginlist = Persist(rundir + os.sep + 'pluginlist') if clear: pluginlist.data = [] if not callbacktable: callbacktable = Persist(rundir + os.sep + 'callbacktable') if clear: callbacktable.data = {} if not shorttable: shorttable = Persist(rundir + os.sep + 'shorttable') if clear: shorttable.data = {} if not timestamps: timestamps = Persist(rundir + os.sep + 'timestamps') #if clear: timestamps.data = {} if not plugwhitelist: plugwhitelist = Persist(rundir + os.sep + 'plugwhitelist') if not plugwhitelist.data: plugwhitelist.data = [] if not plugblacklist: plugblacklist = Persist(rundir + os.sep + 'plugblacklist') if not plugblacklist.data: plugblacklist.data = [] if not cmndperms: cmndperms = Config('cmndperms', ddir=ddir) changed = [] gotlocal = False dosave = clear or False maincfg = getmainconfig(ddir=ddir) logging.warn("mainconfig used is %s" % maincfg.cfile) if os.path.isdir('jsb'): gotlocal = True packages = find_packages("jsb" + os.sep + "plugs") pluglist = [x for x in packages if not 'db' in x] for p in pluglist: if p not in plugin_packages: plugin_packages.append(p) for plug in default_plugins: plugs.reload(plug, showerror=True, force=True) changed = scandir(getdatadir() + os.sep + 'myplugs', dbenable=maincfg.dbenable) if changed: logging.debug("myplugs has changed -=- %s" % str(changed)) for plugfile in changed: if "gae" in plugfile: continue try: plugs.reloadfile(plugfile, force=True) except Exception, ex: handle_exception() dosave = True configchanges = checkconfig() if configchanges: logging.info("there are configuration changes: %s" % str(configchanges)) for f in configchanges: if 'mainconfig' in f: force = True ; dosave = True if os.path.isdir('jsb'): corechanges = scandir("jsb" + os.sep + "plugs", dbenable=maincfg.dbenable) if corechanges: logging.debug("core changed -=- %s" % str(corechanges)) for plugfile in corechanges: if not maincfg.dbenable and "db" in plugfile: continue if "gae" in plugfile: continue try: plugs.reloadfile(plugfile, force=True) except Exception, ex: handle_exception() dosave = True if maincfg.dbenable: if not 'jsb.plugs.db' in plugin_packages: plugin_packages.append("jsb.plugs.db") try: from jsb.db import getmaindb from jsb.db.tables import tablestxt db = getmaindb() if db: db.define(tablestxt) except Exception, ex: logging.warn("could not initialize database %s" % str(ex)) else: logging.warn("db not enabled, set dbenable = 1 in %s to enable" % getmainconfig().cfile) try: plugin_packages.remove("jsb.plugs.db") except ValueError: pass if force or dosave or not cmndtable.data or len(cmndtable.data) < 100: logging.debug("using target %s" % str(plugin_packages)) plugs.loadall(plugin_packages, force=True) savecmndtable(saveperms=saveperms) savepluginlist() savecallbacktable() savealiases() logging.warn("ready")
def boot(ddir=None, force=False, encoding="utf-8", umask=None, saveperms=True, fast=False, clear=False): """ initialize the bot. """ try: if os.getuid() == 0: print "don't run the bot as root" os._exit(1) except AttributeError: pass logging.info("booting ..") from jsb.lib.datadir import getdatadir, setdatadir if ddir: setdatadir(ddir) origdir = ddir ddir = ddir or getdatadir() if not ddir: logging.error("can't determine datadir to boot from") os._exit(1) if not ddir in sys.path: sys.path.append(ddir) makedirs(ddir) if os.path.isdir("/var/run/jsb") and botuser() == "jsb": rundir = "/var/run/jsb" else: rundir = ddir + os.sep + "run" try: k = open(rundir + os.sep + "jsb.pid", "w") k.write(str(os.getpid())) k.close() except IOError: pass try: if not ongae: reload(sys) sys.setdefaultencoding(encoding) except (AttributeError, IOError): pass try: if not umask: checkpermissions(getdatadir(), 0700) else: checkpermissions(getdatadir(), umask) except: handle_exception() global loaded global cmndtable global pluginlist global callbacktable global cmndperms global plugcommands global timestamps global plugwhitelist global plugblacklist if not cmndtable: cmndtable = Persist(rundir + os.sep + "cmndtable") if clear: cmndtable.data = {} if not pluginlist: pluginlist = Persist(rundir + os.sep + "pluginlist") if clear: pluginlist.data = [] if not callbacktable: callbacktable = Persist(rundir + os.sep + "callbacktable") if clear: callbacktable.data = {} if not timestamps: timestamps = Persist(rundir + os.sep + "timestamps") if clear: timestamps.data = {} if not plugwhitelist: plugwhitelist = Persist(rundir + os.sep + "plugwhitelist") if not plugwhitelist.data or clear: plugwhitelist.data = [] if not plugblacklist: plugblacklist = Persist(rundir + os.sep + "plugblacklist") if not plugblacklist.data or clear: plugblacklist.data = [] if not cmndperms: cmndperms = Config("cmndperms", ddir=ddir) from jsb.lib.plugins import plugs if not cmndtable.data or force: plugs.loadall(plugin_packages, force=True) loaded = True savecmndtable(saveperms=saveperms) if not pluginlist.data or force: if not loaded: plugs.loadall(plugin_packages, force=True) loaded = True savepluginlist() if not callbacktable.data or force: if not loaded: plugs.loadall(plugin_packages, force=True) loaded = True savecallbacktable() if not loaded: logging.info("boot - plugins not loaded .. loading defaults") for plug in default_plugins: plugs.reload(plug, showerror=True, force=True) if not fast: if ongae: plugs.loadall( ["myplugs.common", "myplugs.gae", "jsb.plugs.myplugs.gae", "jsb.plugs.myplugs.common"], force=True ) else: plugs.loadall( ["myplugs.common", "myplugs.socket", "jsb.plugs.myplugs.socket", "jsb.plugs.myplugs.common"], force=True, ) else: logging.error("skipped loading of myplugs") try: changed = checktimestamps() if changed: logging.warn("boot - files changed %s" % str(changed)) for plugfile in changed: plugs.reloadfile(plugfile, force=True) except Exception, ex: logging.error("boot - can't read myplugs dir.")
def boot(ddir=None, force=False, encoding="utf-8", umask=None, saveperms=True, fast=False): """ initialize the bot. """ logging.info("booting ..") from jsb.lib.datadir import getdatadir, setdatadir if ddir: setdatadir(ddir) origdir = ddir ddir = ddir or getdatadir() if not ddir: logging.error("can't determine datadir to boot from") ; os._exit(1) if not ddir in sys.path: sys.path.append(ddir) makedirs(ddir) if os.path.isdir("/var/run/jsb") and botuser() == "jsb": rundir = "/var/run/jsb" else: rundir = ddir + os.sep + "run" try: if os.getuid() == 0: print "don't run the bot as root" os._exit(1) except AttributeError: pass try: k = open(rundir + os.sep + 'jsb.pid','w') k.write(str(os.getpid())) k.close() except IOError: pass try: if not ongae: reload(sys) sys.setdefaultencoding(encoding) except (AttributeError, IOError): pass try: if not umask: checkpermissions(getdatadir(), 0700) else: checkpermissions(getdatadir(), umask) except: handle_exception() global loaded global cmndtable global pluginlist global callbacktable global cmndperms global plugcommands if not cmndtable: cmndtable = Persist(rundir + os.sep + 'cmndtable') if not pluginlist: pluginlist = Persist(rundir + os.sep + 'pluginlist') if not callbacktable: callbacktable = Persist(rundir + os.sep + 'callbacktable') if not cmndperms: cmndperms = Config('cmndperms', ddir=ddir) from jsb.lib.plugins import plugs if not cmndtable.data or force: plugs.loadall(plugin_packages, force=True) loaded = True savecmndtable(saveperms=saveperms) if not pluginlist.data or force: if not loaded: plugs.loadall(plugin_packages, force=True) loaded = True savepluginlist() if not callbacktable.data or force: if not loaded: plugs.loadall(plugin_packages, force=True) loaded = True savecallbacktable() if not loaded: logging.info("boot - plugins not loaded .. loading defaults") for plug in default_plugins: plugs.reload(plug, showerror=True, force=True) if not fast: if ongae: plugs.loadall(["myplugs.gae", "jsb.plugs.myplugs"], force=True) else: plugs.loadall(["myplugs.socket", "jsb.plugs.myplugs"], force=True) else: logging.error("skipped loading of myplugs") logging.warn("boot - done")