Exemplo n.º 1
0
def init():
    global db
    from jsb.db import getmaindb
    db = getmaindb()
    setalias('aq', 'quote2-add')
    setalias('wq', 'quote2-who')
    setalias('dq', 'quote2-del')
    setalias('lq', 'quote2-last')
    setalias('2q', 'quote2-2')
    setalias('iq', 'quote2-id')
    setalias('q', 'quote2')
    setalias('sq', 'quote2-search')
    setalias('cq', 'quote2-count')
    setalias('q-good', 'quote2-good')
    setalias('q-bad', 'quote2-bad')
Exemplo n.º 2
0
def init():
    global db
    from jsb.db import getmaindb
    db = getmaindb()
    setalias('k', 'karma2-get')
    setalias('k-del', 'karma2-del')
    setalias('whyup', 'karma2-whyup')
    setalias('whydown', 'karma2-whydown')
    setalias('good', 'karma2-good')
    setalias('bad', 'karma2-bad')
    setalias('whoup', 'karma2-whoup')
    setalias('whodown', 'karma2-whodown')
    setalias('k-search', 'karma2-search')
    setalias('whatup', 'karma2-whatup')
    setalias('whatdown', 'karma2-whatdown')
Exemplo n.º 3
0
def init():
    global db
    from jsb.db import getmaindb
    db = getmaindb()
    setalias('k', 'karma2-get')
    setalias('k-del', 'karma2-del')
    setalias('whyup', 'karma2-whyup')
    setalias('whydown', 'karma2-whydown')
    setalias('good', 'karma2-good')
    setalias('bad', 'karma2-bad')
    setalias('whoup', 'karma2-whoup')
    setalias('whodown', 'karma2-whodown')
    setalias('k-search', 'karma2-search')
    setalias('whatup', 'karma2-whatup')
    setalias('whatdown', 'karma2-whatdown')
Exemplo n.º 4
0
def init():
    global db
    from jsb.db import getmaindb
    db = getmaindb()
    setalias('aq', 'quote2-add')
    setalias('wq', 'quote2-who')
    setalias('dq', 'quote2-del')
    setalias('lq', 'quote2-last')
    setalias('2q', 'quote2-2')
    setalias('iq', 'quote2-id')
    setalias('q', 'quote2')
    setalias('sq', 'quote2-search')
    setalias('cq', 'quote2-count')
    setalias('q-good', 'quote2-good')
    setalias('q-bad', 'quote2-bad')
Exemplo n.º 5
0
         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()
Exemplo n.º 6
0
def init():
    global db
    if not db: db = getmaindb()
    setalias('d', 't-done')
    setalias('tt', 't-time')
Exemplo n.º 7
0
def init():
    global db
    from jsb.db import getmaindb
    db = getmaindb()
Exemplo n.º 8
0
def init():
    global db
    if not db: db = getmaindb()
    setalias('d', 't-done')
    setalias('tt', 't-time')
Exemplo n.º 9
0
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")
Exemplo n.º 10
0
def init():
    global db
    from jsb.db import getmaindb
    db = getmaindb()
Exemplo n.º 11
0
def init():
    global db
    db = getmaindb()