Ejemplo n.º 1
0
 def run(self, **kwargs):
     try:
         self.func(*self.args, **self.kwargs)
     except:
         logging.error(get_exception())
         return
     self.start()
Ejemplo n.º 2
0
 def dccloop(self, event, s):
     sockfile = s.makefile('rw')
     #s.setblocking(True)
     self.register_fd(s)
     while 1:
         try:
             res = sockfile.readline()
             if not res: break
             res = res.rstrip()
             logging.info("< %s %s" % (event.origin, res))
             e = Event()
             e.btype = "DCC"
             e.txt = res
             e.outer = sockfile
             e.origin = event.origin
             super().dispatch(e)
         except socket.timeout:
             time.sleep(0.01)
         except socket.error as ex:
             if ex.errno in [
                     socket.EAGAIN,
             ]: continue
             else: raise
         except Exception as ex:
             logging.error(get_exception())
     sockfile.close()
Ejemplo n.º 3
0
def mbox(event):
    if not event._parsed.rest:
        event.reply("mbox <path>")
        return
    fn = os.path.expanduser(event._parsed.args[0])
    nr = 0
    if os.path.isdir(fn): thing = mailbox.Maildir(fn, create=False)
    elif os.path.isfile(fn): thing = mailbox.mbox(fn, create=False)
    else:
        event.reply("need a mbox or maildir.")
        return
    for m in thing:
        try:
            o = Object()
            o.update(m.items())
            try:
                sdate = os.sep.join(to_date(o.Date).split())
            except AttributeError:
                sdate = None
            o.text = ""
            for load in m.walk():
                if load.get_content_type() == 'text/plain':
                    o.text += load.get_payload()
            o.text = o.text.replace("\\n", "\n")
            o.prefix = "email"
            o.email = o.From
            if sdate: o.save(sdate)
            else: o.save()
            nr += 1
        except:
            logging.error(get_exception())
    if nr: event.ok(nr)
Ejemplo n.º 4
0
def touch(fname):
    try:
        fd = os.open(fname, os.O_RDONLY | os.O_CREAT)
        os.close(fd)
    except TypeError:
        pass
    except Exception as ex:
        logging.error(get_exception())
Ejemplo n.º 5
0
 def scheduling(self, timeout=None):
     logging.info("! start %s" % sname(self))
     self._connected.wait()
     while self._status:
         event = self._queue.get(timeout=timeout)
         if not event: break
         try:
             self.handle_event(event)
         except:
             logging.error(get_exception())
     logging.info("! stop %s" % sname(self))
     self.ready()
Ejemplo n.º 6
0
def cdir(path):
    res = ""
    for p in path.split(os.sep):
        res += "%s%s" % (p, os.sep)
        padje = os.path.abspath(os.path.normpath(res))
        if os.path.isdir(padje): continue
        try:
            os.mkdir(padje)
        except FileExistsError:
            pass
        except OSError as ex:
            logging.error(get_exception())
    return True
Ejemplo n.º 7
0
 def dccconnect(self, event):
     event.parse()
     try:
         addr = event._parsed.args[2]
         port = event._parsed.args[3][:-1]
         port = int(port)
         if re.search(':', addr):
             s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
         else:
             s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         s.connect((addr, port))
     except Exception as ex:
         logging.error(get_exception())
         return
     self.dcced(event, s)
Ejemplo n.º 8
0
def get_feed(url):
    from meds.object import Object
    if not gotparser:
        logging.error("no feedparser available")
        return []
    if not "http" in url:
        logging.error("%s is not an url." % url)
        return []
    try:
        result = feedparser.parse(get_url(url))
    except Exception as ex:
        logging.error(get_exception(url))
        return
    if "entries" in result:
        for entry in result["entries"][::-1]:
            yield Object(entry)
Ejemplo n.º 9
0
 def run(self, **kwargs):
     try:
         self.func(*self.args, **self.kwargs)
     except:
         logging.error(get_exception())
     self._timer._status = "done"