Example #1
0
def init():
    global todo
    global db
    if not db: db = getmaindb()
    assert db
    todo = TodoDb()
    setalias('t', 'todo')
    setalias('d', 'todo-done')
    setalias('tt', 'todo-time')
Example #2
0
def init():
    global db
    from tl.db import getmaindb
    db = getmaindb()
    setalias('k', 'karma-get')
    setalias('k-del', 'karma-del')
    setalias('whyup', 'karma-whyup')
    setalias('whydown', 'karma-whydown')
    setalias('good', 'karma-good')
    setalias('bad', 'karma-bad')
    setalias('whoup', 'karma-whoup')
    setalias('whodown', 'karma-whodown')
    setalias('k-search', 'karma-search')
    setalias('whatup', 'karma-whatup')
    setalias('whatdown', 'karma-whatdown')
Example #3
0
def init():
    global db
    from tl.db import getmaindb
    db = getmaindb()
    setalias('aq', 'quote-add')
    setalias('wq', 'quote-who')
    setalias('dq', 'quote-del')
    setalias('lq', 'quote-last')
    setalias('2q', 'quote-2')
    setalias('iq', 'quote-id')
    setalias('q', 'quote')
    setalias('sq', 'quote-search')
    setalias('cq', 'quote-count')
    setalias('q-good', 'quote-good')
    setalias('q-bad', 'quote-bad')
Example #4
0
def init():
    global db
    db = getmaindb()
Example #5
0
def init():
    global db
    from tl.db import getmaindb
    db = getmaindb()
Example #6
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
    from tl.lib.datadir import getdatadir, setdatadir
    if ddir: setdatadir(ddir)
    origdir = ddir 
    ddir = getdatadir()
    if not ddir: logging.error("can't determine datadir to boot from") ; raise Exception("can't determine datadir")
    logging.warn("starting !!")
    if not ddir in sys.path: sys.path.append(ddir)
    makedirs(ddir)
    try:
        rundir = ddir + os.sep + "run"
        k = open(rundir + os.sep + 'tl.pid','w')
        k.write(str(os.getpid()))
        k.close()
    except IOError: pass
    try:
        if not umask: checkpermissions(getdatadir(), 0o700) 
        else: checkpermissions(getdatadir(), umask)  
    except: handle_exception()
    from tl.lib.plugins import plugs
    global loaded
    global cmndtable
    global retable
    global plugins
    global callbacktable
    global shorttable
    global cmndperms
    global timestamps
    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 plugins: plugins = Persist(rundir + os.sep + 'plugins')
    if clear: plugins.data = {}
    if not plugins.data.available: plugins.data.available = []
    if not plugins.data.refused: plugins.data.refused = []
    if not plugins.data.allowed: plugins.data.allowed = []
    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 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)
    packages = find_packages(ddir + os.sep + "myplugs")
    for p in packages:
        if p not in plugin_packages: plugin_packages.append(p)
    packages = find_packages("tl" + os.sep + "plugs")
    for p in packages:
        if p not in plugin_packages: plugin_packages.append(p)
    if os.path.isdir('tl'):
        gotlocal = True
        changed = scandir('tl-myplugs')
        if changed:
            logging.warn("tl-myplugs has changed -=- %s" % ", ".join(changed))
            dosave = True
    for plug in default_plugins: plugs.reload(plug, showerror=True, force=True)
    changed = scandir(ddir + os.sep + 'myplugs')
    if changed:
        logging.warn("myplugs has changed -=- %s" % ', '.join(changed))
        dosave = True
    configchanges = checkconfig()
    if configchanges:
        logging.info("there are configuration changes: %s" % ', '.join(configchanges))
        for f in configchanges:
            if 'mainconfig' in f: force = True ; dosave = True
    if os.path.isdir('tl'):
        coreplugs = scandir("tl" + os.sep + "plugs")
        if coreplugs:
            logging.warn("core changed -=- %s" % ", ".join(coreplugs))
            dosave = True
    try:
        from tl.db import getmaindb
        from tl.db.tables import tablestxt
        db = getmaindb()
        if db: db.define(tablestxt)
    except Exception as ex: logging.warn("could not initialize database %s" % str(ex))
    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)
        saveplugins()
        savecallbacktable()
        savealiases()
    logging.warn(getfullversion(getdatadir()))
    logging.warn("READY")