Ejemplo n.º 1
0
Archivo: config.py Proyecto: code2u/jsb
 def __init__(self, filename, verbose=False, input={}, ddir=None, *args, **kw):
     assert filename
     LazyDict.__init__(self, input, *args, **kw)
     self.filename = filename or 'mainconfig'
     self.datadir = ddir or getdatadir()
     self.dir = self.datadir + os.sep + 'config'
     self.cfile = self.dir + os.sep + self.filename
     logging.debug("filename is %s" % self.cfile)
     self.jsondb = None
     try: import waveapi ; self.isdb = True
     except ImportError: self.isdb = False
     if not self.comments: self.comments = {}
     try:
         try: self.fromfile(self.cfile)
         except IOError:
             logging.warn("can't read config from %s" % self.cfile) 
             import waveapi
             from persist import Persist
             self.jsondb = Persist(self.cfile)
             self.update(self.jsondb.data)
             self.isdb = True
             logging.debug("fromdb - %s - %s" % (self.cfile, str(self)))
     except ImportError:
         handle_exception()
         self.isdb = False
     self.init()
     self.datadir = ddir or getdatadir()
     self.dir = self.datadir + os.sep + 'config'
     self.cfile = self.dir + os.sep + self.filename
     if not self.owner: self.owner = []
     dosave = False
     if not self.uuid: self.uuid = str(uuid.uuid4()) ; dosave = True
     if not self.cfile: self.cfile = self.dir + os.sep + self.filename ; dosave = True
     if dosave: self.save()
     assert self.cfile
Ejemplo n.º 2
0
Archivo: users.py Proyecto: code2u/jsb
 def __init__(self, name, userhosts=[], perms=[], permits=[], status=[], email=[]):
     assert name
     name = stripname(name.lower())
     Persist.__init__(self, getdatadir() + os.sep + 'users' + os.sep + name)
     self.data.datadir = self.data.datadir or getdatadir()
     self.data.name = self.data.name or name
     self.data.userhosts = self.data.userhosts or userhosts
     self.data.perms = self.data.perms or perms
     self.data.permits = self.data.permits or permits
     self.data.status = self.data.status or status
     self.data.email = self.data.email or email
     self.state = UserState(name)
Ejemplo n.º 3
0
 def __init__(self, filename, verbose=False, input={}, ddir=None, nolog=False, *args, **kw):
     assert filename
     LazyDict.__init__(self, input, *args, **kw)
     self.origname = filename
     self.origdir = ddir or getdatadir()
     self.setcfile(ddir, filename)
     self.jsondb = None
     if not self._comments: self._comments = {}
     try:
         import waveapi
         self.isdb = True
         self.isgae = True
     except ImportError:
         self.isgae = False
         self.isdb = False
     dodb = False
     try:
         logging.info("fromfile - %s from %s" % (self.origname, whichmodule(2)))
         self.fromfile(self.cfile)
     except IOError, ex: handle_exception() ; dodb = True
     if dodb or (self.isgae and not "mainconfig" in filename):
         try:
             from persist import Persist
             self.jsondb = Persist(self.cfile)
             if self.jsondb: self.merge(self.jsondb.data)
             logging.warn("fromdb - %s" % self.cfile)
         except ImportError:
             logging.warn("can't read config from %s - %s" % (self.cfile, str(ex))) 
     self.init()
     if self.owner: logging.info("owner is %s" % self.owner)
     if not self.has_key("uuid"): self.setuuid()
     if not self.has_key("cfile"): self.cfile = self.setcfile(self.origdir, self.origname) 
     assert self.cfile
Ejemplo n.º 4
0
 def __init__(self, filename=None, verbose=False, input={}, ddir=None, *args, **kw):
     LazyDict.__init__(self, input, *args, **kw)
     filename = filename or 'mainconfig'
     datadir = ddir or getdatadir()
     dir = datadir + os.sep + 'config'
     if datadir not in filename: cfile = dir + os.sep + filename
     else: cfile = filename
     logging.debug("config - filename is %s" % cfile)
     self.jsondb = None
     try: import waveapi ; self.isdb = True
     except ImportError: self.isdb = False
     if not self.comments: self.comments = {}
     try:
         try: self.fromfile(cfile)
         except IOError:
             logging.warn("can't read config from %s" % self.cfile) 
             import waveapi
             from persist import Persist
             self.jsondb = Persist(cfile)
             self.update(self.jsondb.data)
             self.isdb = True
             logging.debug("config - fromdb - %s - %s" % (self.cfile, str(self)))
     except ImportError:
         handle_exception()
         self.isdb = False
     self.cfile = cfile
     self.dir = dir
     self.filename = filename
     self.init()
     if not self.owner: self.owner = []
     if not self.uuid: self.uuid = str(uuid.uuid4())
Ejemplo n.º 5
0
def set(target, txtlist):
    """ set target entry to list. """
    cache = Persist(getdatadir() + os.sep + 'run' + os.sep + 'outputcache' +
                    os.sep + stripname(target))
    if not cache.data.has_key('msg'): cache.data['msg'] = []
    cache.data['msg'] = txtlist
    cache.save()
Ejemplo n.º 6
0
 def __init__(self, ddir=None, filename=None):
     self.datadir = ddir or getdatadir()
     self.filename = filename or 'mainusers'
     self.udir = self.datadir + os.sep + self.filename
     Persist.__init__(self, self.udir)
     if not self.data: self.data = LazyDict()
     self.data.names = self.data.names or {}
     logging.warn("users object created from %s" % self.udir)
Ejemplo n.º 7
0
 def __init__(self, ddir=None, filename=None):
     self.datadir = ddir or getdatadir()
     self.filename = filename or 'mainusers'
     self.udir = self.datadir + os.sep + self.filename
     Persist.__init__(self, self.udir)
     if not self.data: self.data = LazyDict()
     self.data.names = self.data.names or {}
     logging.warn("users object created from %s" % self.udir)
Ejemplo n.º 8
0
def clear(target):
    """ clear target's outputcache. """
    cache = Persist(getdatadir() + os.sep + 'run' + os.sep + 'outputcache' + os.sep + stripname(target))
    try:
        cache.data['msg'] = []
        cache.save()
    except KeyError: pass
    return []
Ejemplo n.º 9
0
def getfleet(datadir=None, new=False):
    if not datadir:
        from jsb.lib.datadir import getdatadir 
        datadir = getdatadir()
    global fleet
    if not fleet or new:
        fleet = Fleet(datadir)
    return fleet
Ejemplo n.º 10
0
 def __init__(self,
              name,
              userhosts=[],
              perms=[],
              permits=[],
              status=[],
              email=[]):
     assert name
     name = stripname(name.lower())
     Persist.__init__(self, getdatadir() + os.sep + 'users' + os.sep + name)
     self.data.datadir = self.data.datadir or getdatadir()
     self.data.name = self.data.name or name
     self.data.userhosts = self.data.userhosts or list(userhosts)
     self.data.perms = self.data.perms or list(perms)
     self.data.permits = self.data.permits or list(permits)
     self.data.status = self.data.status or list(status)
     self.data.email = self.data.email or list(email)
     self.state = UserState(name)
Ejemplo n.º 11
0
def get(target):
    """ get output for target. """
    logging.warn("get target is %s" % target)
    cache = Persist(getdatadir() + os.sep + 'run' + os.sep + 'outputcache' + os.sep + stripname(target))
    try:
        result = cache.data['msg']
        if result: return result
    except KeyError: pass
    return []
Ejemplo n.º 12
0
def get(target):
    """ get output for target. """
    cache = Persist(getdatadir() + os.sep + 'run' + os.sep + 'outputcache' +
                    os.sep + stripname(target))
    try:
        result = cache.data['msg']
        if result: return result
    except KeyError:
        pass
    return []
Ejemplo n.º 13
0
def clear(target):
    """ clear target's outputcache. """
    cache = Persist(getdatadir() + os.sep + 'run' + os.sep + 'outputcache' +
                    os.sep + stripname(target))
    try:
        cache.data['msg'] = []
        cache.save()
    except KeyError:
        pass
    return []
Ejemplo n.º 14
0
 def __init__(self, filename, verbose=False, input={}, ddir=None, nolog=False, *args, **kw):
     assert filename
     LazyDict.__init__(self, input, *args, **kw)
     a = "%s%s" % (os.sep, os.sep)
     filename = filename.replace(a, os.sep)
     self.origname = filename
     self.origdir = ddir or getdatadir()
     self.setcfile(ddir or getdatadir(), filename)
     self.jsondb = None
     if not self._comments: self._comments = {}
     logging.info("fromfile - %s from %s" % (self.origname, whichmodule(2)))
     self.fromfile(self.cfile)
     self.origdir = ddir or getdatadir()
     self.setcfile(ddir or getdatadir(), filename)
     self.init()
     if self.owner: logging.info("owner is %s" % self.owner)
     if not self.has_key("uuid"): self.setuuid()
     if not self.has_key("cfile"): self.cfile = self.setcfile(self.origdir, self.origname) 
     assert self.cfile
     if not self.origdir in self.cfile: raise WrongFileName("%s not in %s" % (self.origdir, self.cfile))
Ejemplo n.º 15
0
 def boot(self, botnames=[], exclude=[], all=False):
     if not botnames and all: botnames = self.getenabled(exclude)
     bots = self.loadall(botnames)
     todo = []
     done = []
     for bot in bots:
         if not bot: continue
         logging.debug("%s bot type is %s" % (bot.cfg.name, bot.type))
         if bot.type not in exclude: todo.append(bot) ; done.append(bot.cfg.name)
     if todo: start_new_thread(self.startall, (todo, ))
     if done: logging.warn("fleet bots are %s" % ", ".join(done))
     else: logging.warn("no fleet bots are enabled, see %s" % getdatadir() + os.sep + "config" + os.sep +'fleet')
Ejemplo n.º 16
0
def add(target, txtlist):
    """ add list of txt to target entry. """
    logging.warn("outputcache - adding %s lines" % len(txtlist))
    t = []
    for item in txtlist:
        t.append("[%s] %s" % (hourmin(time.time()), item))
    cache = Persist(getdatadir() + os.sep + 'run' + os.sep + 'outputcache' + os.sep + stripname(target))
    d = cache.data
    if not d.has_key('msg'): d['msg'] = []
    d['msg'].extend(t)
    while len(d['msg']) > 10: d['msg'].pop(0)
    cache.save()
Ejemplo n.º 17
0
def add(target, txtlist):
    """ add list of txt to target entry. """
    logging.warn("outputcache - adding %s lines" % len(txtlist))
    t = []
    for item in txtlist:
        t.append("[%s] %s" % (hourmin(time.time()), item))
    cache = Persist(getdatadir() + os.sep + 'run' + os.sep + 'outputcache' +
                    os.sep + stripname(target))
    d = cache.data
    if not d.has_key('msg'): d['msg'] = []
    d['msg'].extend(t)
    while len(d['msg']) > 10:
        d['msg'].pop(0)
    cache.save()
Ejemplo n.º 18
0
def makedefaultconfig(type, ddir=None):
    filename = 'config'
    datadir = ddir or getdatadir()
    dir = datadir + os.sep + 'config'
    ttype = "default-%s" % type
    cfile = dir + os.sep + "fleet" + os.sep + ttype + os.sep + filename
    splitted = cfile.split(os.sep)
    mdir = "" 
    for i in splitted[:-1]:
        mdir += "%s%s" % (i, os.sep)
        if not os.path.isdir(mdir): os.mkdir(mdir)
    logging.debug("config - filename is %s" % cfile)
    f = open(cfile, "w")
    if type == "irc": f.write(irctemplate) ; f.close()
    elif type == "sxmpp": f.write(xmpptemplate) ; f.close()
    else: raise Exception("no such bot type: %s" % type)
Ejemplo n.º 19
0
 def __init__(self, ddir=None, filename=None):
     self.datadir = ddir or getdatadir()
     self.filename = filename or 'mainusers'
     Persist.__init__(self, self.datadir + os.sep + self.filename)
     if not self.data: self.data = LazyDict()
     self.data.names = self.data.names or {}
Ejemplo n.º 20
0
Archivo: users.py Proyecto: code2u/jsb
 def __init__(self, ddir=None, filename=None):
     self.datadir = ddir or getdatadir()
     self.filename = filename or 'mainusers'
     Persist.__init__(self, self.datadir + os.sep + self.filename)
     if not self.data: self.data = LazyDict()
     self.data.names = self.data.names or {}
Ejemplo n.º 21
0
 def setcfile(self, ddir, filename):
     self.filename = filename or 'mainconfig'
     self.datadir = ddir or getdatadir()
     self.dir = self.datadir + os.sep + 'config'
     self.cfile = self.dir + os.sep + filename
Ejemplo n.º 22
0
def set(target, txtlist):
    """ set target entry to list. """
    cache = Persist(getdatadir() + os.sep + 'run' + os.sep + 'outputcache' + os.sep + stripname(target))
    if not cache.data.has_key('msg'): cache.data['msg'] = []
    cache.data['msg'] = txtlist
    cache.save()