예제 #1
0
파일: datadir.py 프로젝트: buzzworkers/tl
def makeplugs():
    from tl.lib.fleet import getfleet
    from tl.lib.plugins import plugs
    plugs.loadall(force=True)
    plugs.save()
    fleet = getfleet()
    fleet.loadall()
    fleet.save()   
예제 #2
0
파일: admin.py 프로젝트: buzzworkers/tl
def handle_loadall(bot, ievent):
    """ no arguments - load all available plugins. """
    plugs.loadall(plugin_packages, force=True)
    ievent.done()
예제 #3
0
파일: boot.py 프로젝트: buzzworkers/tl
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")