예제 #1
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
예제 #2
0
파일: commands.py 프로젝트: Petraea/jsonbot
 def __init__(self,
              modname,
              cmnd,
              func,
              perms=[],
              threaded=False,
              wait=False,
              orig=None,
              how=None,
              speed=None,
              needcc=False):
     LazyDict.__init__(self)
     if not modname: raise Exception("modname is not set - %s" % cmnd)
     self.modname = cpy(modname)
     self.plugname = self.modname.split('.')[-1]
     self.cmnd = cpy(cmnd)
     self.orig = cpy(orig)
     self.func = func
     if type(perms) == types.StringType: perms = [
             perms,
     ]
     self.perms = cpy(perms)
     self.plugin = self.plugname
     self.threaded = cpy(threaded)
     self.wait = cpy(wait)
     self.enable = True
     self.how = how or "overwrite"
     self.regex = None
     self.speed = speed
     self.needcc = needcc
예제 #3
0
파일: config.py 프로젝트: 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
예제 #4
0
파일: config.py 프로젝트: melmothx/jsonbot
 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())
예제 #5
0
 def __init__(self, cfg=None, usersin=None, plugs=None, botname=None, nick=None, bottype=None, nocbs=None, *args, **kwargs):
     logging.debug("type is %s" % str(type(self)))
     if cfg: self.cfg = cfg ; botname = botname or self.cfg.name
     if not botname: botname = u"default-%s" % str(type(self)).split('.')[-1][:-2]
     if not botname: raise Exception("can't determine  botname")
     self.fleetdir = u'fleet' + os.sep + stripname(botname)
     if not self.cfg: self.cfg = Config(self.fleetdir + os.sep + u'config')
     self.cfg.name = botname or self.cfg.name
     if not self.cfg.name: raise Exception("name is not set in %s config file" % self.fleetdir)
     logging.debug("name is %s" % self.cfg.name)
     LazyDict.__init__(self)
     logging.debug("created bot with config %s" % self.cfg.tojson(full=True))
     self.ecounter = 0
     self.ids = []
     self.aliases = getaliases()
     self.reconnectcount = 0
     self.plugs = coreplugs
     self.gatekeeper = GateKeeper(self.cfg.name)
     self.gatekeeper.allow(self.user or self.jid or self.cfg.server or self.cfg.name)
     self.starttime = time.time()
     self.type = bottype or "base"
     self.status = "init"
     self.networkname = self.cfg.networkname or self.cfg.name or ""
     from jsb.lib.datadir import getdatadir
     datadir = getdatadir()
     self.datadir = datadir + os.sep + self.fleetdir
     self.maincfg = getmainconfig()
     self.owner = self.cfg.owner
     if not self.owner:
         logging.debug(u"owner is not set in %s - using mainconfig" % self.cfg.cfile)
         self.owner = self.maincfg.owner
     self.users = usersin or getusers()
     logging.debug(u"owner is %s" % self.owner)
     self.users.make_owner(self.owner)
     self.outcache = outcache
     self.userhosts = LazyDict()
     self.nicks = LazyDict()
     self.connectok = threading.Event()
     self.reconnectcount = 0
     self.cfg.nick = nick or self.cfg.nick or u'jsb'
     try:
         if not os.isdir(self.datadir): os.mkdir(self.datadir)
     except: pass
     self.setstate()
     self.outputlock = thread.allocate_lock()
     try:
         self.outqueue = Queue.PriorityQueue()
         self.eventqueue = Queue.PriorityQueue()
     except AttributeError:
         self.outqueue = Queue.Queue()
         self.eventqueue = Queue.Queue()
     self.laterqueue = Queue.Queue()
     self.encoding = self.cfg.encoding or "utf-8"
     self.cmndperms = getcmndperms()
     self.outputmorphs = outputmorphs
     self.inputmorphs = inputmorphs
     try:
         if nocbs: self.nocbs = nocbs.split(",")
     except ValueError: logging.error("cannot determine %s nocbs argument" % self.nocbs)
     self.lastiter = 0
예제 #6
0
 def __init__(self, url="", name=""):
     LazyDict.__init__(self)
     self.url = url
     self.name = name
     self.data = None
     self.error = None
     self.status = None
     self.reason = ""
예제 #7
0
 def __init__(self, url="", name=""):
     LazyDict.__init__(self)
     self.url = url
     self.name = name
     self.data = None
     self.error = None
     self.status = None
     self.reason = ""
예제 #8
0
 def __init__(self, input={}, bot=None):
     LazyDict.__init__(self)
     if bot: self.bot = bot
     self.ctime = time.time()
     self.speed = self.speed or 5
     self.nrout = self.nrout or 0
     if input: self.copyin(input)
     if not self.token: self.setup()
예제 #9
0
 def __init__(self, botname='default', i=0, nick="", ttime=time.time(), txt="", printto=None, d={}):
     if not d: LazyDict.__init__(self)
     else: LazyDict.__init__(self, d)
     self.botname = self.botname or botname
     self.idnr = self.idnr or i
     self.nick = self.nick or nick
     self.time = self.ttime or ttime
     self.txt = self.txt or txt
     self.printto = self.printto or printto or nick or ""
예제 #10
0
 def __init__(self, input={}, bot=None):
     LazyDict.__init__(self)
     if bot: self.bot = bot
     self.threaded = False
     self.untildone = False
     self.ctime = time.time()
     self.speed = self.speed or 5
     self.nrout = self.nrout or 0
     if input: self.copyin(input)
     if not self.token: self.setup()
예제 #11
0
 def __init__(self, modname, cmnd, func, perms=[], threaded=False, wait=False, orig=None, how=None):
     LazyDict.__init__(self)
     if not modname: raise Exception("modname is not set - %s" % cmnd)
     self.modname = modname
     self.plugname = self.modname.split('.')[-1]
     self.cmnd = cmnd
     self.orig = orig
     self.func = func
     if type(perms) == types.StringType: perms = [perms, ]
     self.perms = perms
     self.plugin = self.plugname
     self.threaded = threaded
     self.wait = wait
     self.enable = True
     self.how = how or "channel"
예제 #12
0
파일: alarm.py 프로젝트: Petraea/jsonbot
 def __init__(self,
              botname='default',
              i=0,
              nick="",
              ttime=time.time(),
              txt="",
              printto=None,
              d={}):
     if not d: LazyDict.__init__(self)
     else: LazyDict.__init__(self, d)
     self.botname = self.botname or botname
     self.idnr = self.idnr or i
     self.nick = self.nick or nick
     self.time = self.ttime or ttime
     self.txt = self.txt or txt
     self.printto = self.printto or printto or nick or ""
예제 #13
0
파일: commands.py 프로젝트: code2u/jsb
 def __init__(self, modname, cmnd, func, perms=[], threaded=False, wait=False, orig=None, how=None):
     LazyDict.__init__(self)
     if not modname: raise Exception("modname is not set - %s" % cmnd)
     self.modname = cpy(modname)
     self.plugname = self.modname.split('.')[-1]
     self.cmnd = cpy(cmnd)
     self.orig = cpy(orig)
     self.func = func
     if type(perms) == types.StringType: perms = [perms, ]
     self.perms = cpy(perms)
     self.plugin = self.plugname
     self.threaded = cpy(threaded)
     self.wait = cpy(wait)
     self.enable = True
     self.how = how or "overwrite"
     self.regex = None
예제 #14
0
파일: config.py 프로젝트: Petraea/jsonbot
 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))
예제 #15
0
파일: eventbase.py 프로젝트: code2u/jsb
 def __init__(self, input={}, bot=None):
     LazyDict.__init__(self)
     if bot: self.bot = bot
     self.txt = ""
     self.usercmnd = ""
     self.bottype = "botbase"
     self.relayed = []
     self.path = []
     self.cbs = []
     self.result = []
     self.waiting = []
     self.threads = self.threads or []
     self.queues = self.queues or []
     self.finished = self.finished or threading.Event()
     self.resqueue = self.resqueue or Queue.Queue()
     self.inqueue = self.inqueue or Queue.Queue()
     self.outqueue = self.outqueue or Queue.Queue()
     self.stop = False
     self.bonded = False
     self.copyin(input)
     self.ctime = time.time()
예제 #16
0
 def __init__(self, input={}, bot=None):
     LazyDict.__init__(self)
     if bot: self.bot = bot
     self.bottype = "botbase"
     self.relayed = []
     self.copyin(input)
예제 #17
0
 def __init__(self, input={}, bot=None):
     LazyDict.__init__(self)
     if bot: self.bot = bot
     self.bottype = "botbase"
     self.relayed = []
     self.copyin(input)
예제 #18
0
 def __init__(self,
              cfg=None,
              usersin=None,
              plugs=None,
              botname=None,
              nick=None,
              bottype=None,
              nocbs=None,
              *args,
              **kwargs):
     logging.debug("type is %s" % str(type(self)))
     if cfg:
         self.cfg = cfg
         botname = botname or self.cfg.name
     if not botname:
         botname = u"default-%s" % str(type(self)).split('.')[-1][:-2]
     if not botname: raise Exception("can't determine  botname")
     self.fleetdir = u'fleet' + os.sep + stripname(botname)
     if not self.cfg: self.cfg = Config(self.fleetdir + os.sep + u'config')
     self.cfg.name = botname or self.cfg.name
     if not self.cfg.name:
         raise Exception("name is not set in %s config file" %
                         self.fleetdir)
     logging.debug("name is %s" % self.cfg.name)
     LazyDict.__init__(self)
     logging.debug("created bot with config %s" %
                   self.cfg.tojson(full=True))
     self.ecounter = 0
     self.ids = []
     self.aliases = getaliases()
     self.reconnectcount = 0
     self.plugs = coreplugs
     self.gatekeeper = GateKeeper(self.cfg.name)
     self.gatekeeper.allow(self.user or self.jid or self.cfg.server
                           or self.cfg.name)
     self.starttime = time.time()
     self.type = bottype or "base"
     self.status = "init"
     self.networkname = self.cfg.networkname or self.cfg.name or ""
     from jsb.lib.datadir import getdatadir
     datadir = getdatadir()
     self.datadir = datadir + os.sep + self.fleetdir
     self.maincfg = getmainconfig()
     self.owner = self.cfg.owner
     if not self.owner:
         logging.debug(u"owner is not set in %s - using mainconfig" %
                       self.cfg.cfile)
         self.owner = self.maincfg.owner
     self.users = usersin or getusers()
     logging.debug(u"owner is %s" % self.owner)
     self.users.make_owner(self.owner)
     self.outcache = outcache
     self.userhosts = LazyDict()
     self.nicks = LazyDict()
     self.connectok = threading.Event()
     self.reconnectcount = 0
     self.cfg.nick = nick or self.cfg.nick or u'jsb'
     try:
         if not os.isdir(self.datadir): os.mkdir(self.datadir)
     except:
         pass
     self.setstate()
     self.outputlock = thread.allocate_lock()
     try:
         self.outqueue = Queue.PriorityQueue()
         self.eventqueue = Queue.PriorityQueue()
     except AttributeError:
         self.outqueue = Queue.Queue()
         self.eventqueue = Queue.Queue()
     self.laterqueue = Queue.Queue()
     self.encoding = self.cfg.encoding or "utf-8"
     self.cmndperms = getcmndperms()
     self.outputmorphs = outputmorphs
     self.inputmorphs = inputmorphs
     try:
         if nocbs: self.nocbs = nocbs.split(",")
     except ValueError:
         logging.error("cannot determine %s nocbs argument" % self.nocbs)
     self.lastiter = 0
예제 #19
0
 def __init__(self,
              cfg=None,
              usersin=None,
              plugs=None,
              botname=None,
              nick=None,
              *args,
              **kwargs):
     if not botname and cfg and cfg.botname: botname = cfg.botname
     if botname: self.botname = botname
     else:
         self.botname = u"default-%s" % str(type(self)).split('.')[-1][:-2]
     logging.info("botbase - name is %s" % self.botname)
     self.fleetdir = u'fleet' + os.sep + stripname(self.botname)
     if cfg:
         self.cfg = Config(self.fleetdir + os.sep + u'config', input=cfg)
     else:
         self.cfg = Config(self.fleetdir + os.sep + u'config')
     LazyDict.__init__(self)
     self.update(self.cfg)
     self.ignore = []
     self.aliases = getaliases()
     self.curevent = None
     self.inqueue = Queue.Queue()
     self.outqueue = Queue.Queue()
     self.reconnectcount = 0
     self.stopped = False
     self.plugs = coreplugs
     self.gatekeeper = GateKeeper(self.botname)
     self.gatekeeper.allow(self.user or self.jid or self.server
                           or self.botname)
     self.closed = False
     try:
         import waveapi
         self.isgae = True
         logging.debug("botbase - bot is a GAE bot (%s)" % self.botname)
     except ImportError:
         self.isgae = False
         logging.debug("botbase - bot is a shell bot (%s)" % self.botname)
     self.starttime = time.time()
     self.type = "base"
     self.status = "init"
     self.networkname = self.cfg.networkname or self.botname or ""
     if not self.uuid:
         if self.cfg and self.cfg.uuid: self.uuid = self.cfg.uuid
         else:
             self.uuid = self.cfg.uuid = uuid.uuid4()
             self.cfg.save()
     if self.cfg and not self.cfg.followlist:
         self.cfg.followlist = []
         self.cfg.save()
     from jsb.lib.datadir import getdatadir
     datadir = getdatadir()
     self.datadir = datadir + os.sep + self.fleetdir
     self.name = self.botname
     self.owner = self.cfg.owner
     if not self.owner:
         logging.debug(u"owner is not set in %s - using mainconfig" %
                       self.cfg.cfile)
         self.owner = Config().owner
     self.setusers(usersin)
     logging.info(u"botbase - owner is %s" % self.owner)
     self.users.make_owner(self.owner)
     self.outcache = outcache
     self.userhosts = {}
     self.connectok = threading.Event()
     if not self.nick: self.nick = (nick or self.cfg.nick or u'jsb')
     try:
         if not os.isdir(self.datadir): os.mkdir(self.datadir)
     except:
         pass
     self.setstate()
     self.stopreadloop = False
     self.stopoutloop = False
     self.outputlock = thread.allocate_lock()
     self.outqueues = [Queue.Queue() for i in range(10)]
     self.tickqueue = Queue.Queue()
     self.encoding = self.cfg.encoding or "utf-8"
     self.cmndperms = getcmndperms()
     self.outputmorphs = outputmorphs
     self.inputmorphs = inputmorphs
     fleet = getfleet(datadir)
     if not fleet.byname(self.name): fleet.bots.append(self)
     if not self.isgae:
         defaultrunner.start()
         tickloop.start(self)
예제 #20
0
파일: botbase.py 프로젝트: code2u/jsb
 def __init__(self, cfg=None, usersin=None, plugs=None, botname=None, nick=None, *args, **kwargs):
     logging.debug("type is %s" % str(type(self)))
     if cfg: cfg = LazyDict(cfg)
     if cfg and not botname: botname = cfg.name
     if not botname: botname = u"default-%s" % str(type(self)).split('.')[-1][:-2]
     if not botname: raise Exception("can't determine type")
     self.fleetdir = u'fleet' + os.sep + stripname(botname)
     self.cfg = Config(self.fleetdir + os.sep + u'config')
     if cfg: self.cfg.merge(cfg)
     self.cfg.name = botname
     if not self.cfg.name: raise Exception(" name is not set in %s config file" % self.fleetdir)
     logging.debug("name is %s" % self.cfg.name)
     LazyDict.__init__(self)
     self.ignore = []
     self.ids = []
     self.started = False
     self.aliases = getaliases()
     self.curevent = None
     self.inqueue = Queue.Queue()
     self.outqueue = Queue.Queue()
     self.reconnectcount = 0
     self.stopped = False
     self.plugs = coreplugs
     self.gatekeeper = GateKeeper(self.cfg.name)
     self.gatekeeper.allow(self.user or self.jid or self.cfg.server or self.cfg.name)
     self.closed = False
     try:
         import waveapi
         self.isgae = True
         logging.debug("bot is a GAE bot (%s)" % self.cfg.name)
     except ImportError:
         self.isgae = False
         logging.debug("bot is a shell bot (%s)" % self.cfg.name)
     self.starttime = time.time()
     self.type = "base"
     self.status = "init"
     self.networkname = self.cfg.networkname or self.cfg.name or ""
     if not self.uuid:
         if self.cfg and self.cfg.uuid: self.uuid = self.cfg.uuid
         else:
             self.uuid = self.cfg.uuid = uuid.uuid4()
             self.cfg.save()
     if self.cfg and not self.cfg.followlist: self.cfg.followlist = [] ; self.cfg.save()
     from jsb.lib.datadir import getdatadir
     datadir = getdatadir()
     self.datadir = datadir + os.sep + self.fleetdir
     self.owner = self.cfg.owner
     if not self.owner:
         logging.debug(u"owner is not set in %s - using mainconfig" % self.cfg.cfile)
         self.owner = getmainconfig().owner
     self.setusers(usersin)
     logging.debug(u"owner is %s" % self.owner)
     self.users.make_owner(self.owner)
     self.outcache = outcache
     self.userhosts = LazyDict()
     self.connectok = threading.Event()
     self.reconnectcount = 0
     self.cfg.nick = nick or self.cfg.nick or u'jsb'
     try:
         if not os.isdir(self.datadir): os.mkdir(self.datadir)
     except: pass
     self.setstate()
     self.stopreadloop = False
     self.stopoutloop = False
     self.outputlock = thread.allocate_lock()
     self.outqueues = [Queue.Queue() for i in range(10)]
     self.tickqueue = Queue.Queue()
     self.encoding = self.cfg.encoding or "utf-8"
     self.cmndperms = getcmndperms()
     self.outputmorphs = outputmorphs
     self.inputmorphs = inputmorphs
     if not self.isgae:
         defaultrunner.start()
         callbackrunner.start()
         waitrunner.start()
         tickloop.start(self)