Ejemplo n.º 1
0
    def save(self):
        """
        Save message in 'Msgs' sqlite db, and record index in 'tags' db.
        """
        db_msg = DBProxy(MSGDB)
        new = self.idx is None or self._stime is None
        # persist message record to MSGDB
        db_msg.acquire()
        if new:
            self.idx = max([int(key) for key in db_msg.keys()] or [-1]) + 1
            self._stime = datetime.datetime.now()
            new = True
        db_msg["%d" % (self.idx,)] = self
        db_msg.release()

        # persist message idx to TAGDB
        db_tag = DBProxy(TAGDB)
        db_tag.acquire()
        for tag, msgs in db_tag.iteritems():
            if tag in self.tags and not self.idx in msgs:
                msgs.add(self.idx)
                db_tag[tag] = msgs
                logger.info(u"msg %s tagged '%s'", self.idx, tag)
            elif tag not in self.tags and self.idx in msgs:
                msgs.remove(self.idx)
                db_tag[tag] = msgs
                logger.info(u"msg %s untagged '%s'", self.idx, tag)
        for tag in [_tag for _tag in self.tags if not _tag in db_tag]:
            db_tag[tag] = set([self.idx])
        db_tag.release()

        # persist message as child to parent;
        if not hasattr(self, "parent"):
            self.parent = None
        assert self.parent not in self.children
        if self.parent is not None:
            parent_msg = get_msg(self.parent)
            if not hasattr(parent_msg, "children"):
                parent_msg.children = set()  # intermediary conversion; deleteme
            parent_msg.children.add(self.idx)
            parent_msg.save()

        logger.info(
            u"saved %s%s%s, addressed to '%s'.",
            "new " if new else u"",
            "public " if "public" in self.tags else u"",
            "message " if self.parent is None else u"reply ",
            self.recipient,
        )
Ejemplo n.º 2
0
    def save(self):
        """
        Save message in 'Msgs' sqlite db, and record index in 'tags' db.
        """
        db_msg = DBProxy(MSGDB)
        new = self.idx is None or self._stime is None
        # persist message record to MSGDB
        db_msg.acquire()
        if new:
            self.idx = max([int(key) for key in db_msg.keys()] or [-1]) + 1
            self._stime = datetime.datetime.now()
            new = True
        db_msg['%d' % (self.idx,)] = self
        db_msg.release()

        # persist message idx to TAGDB
        db_tag = DBProxy(TAGDB)
        db_tag.acquire()
        for tag, msgs in db_tag.iteritems():
            if tag in self.tags and not self.idx in msgs:
                msgs.add(self.idx)
                db_tag[tag] = msgs
                logger.info(u"msg %s tagged '%s'", self.idx, tag,)
            elif tag not in self.tags and self.idx in msgs:
                msgs.remove(self.idx)
                db_tag[tag] = msgs
                logger.info(u"msg %s untagged '%s'", self.idx, tag,)
        for tag in [_tag for _tag in self.tags if not _tag in db_tag]:
            db_tag[tag] = set([self.idx])
        db_tag.release()

        # persist message as child to parent;
        if not hasattr(self, 'parent'):
            self.parent = None
        assert self.parent not in self.children
        if self.parent is not None:
            parent_msg = get_msg(self.parent)
            if not hasattr(parent_msg, 'children'):
                parent_msg.children = set(
                )  # intermediary conversion; deleteme
            parent_msg.children.add(self.idx)
            parent_msg.save()

        logger.info(u"saved %s%s%s, addressed to '%s'.",
                    'new ' if new else u'',
                    'public ' if 'public' in self.tags else u'',
                    'message' if self.parent is None else u'reply',
                    self.recipient,)
Ejemplo n.º 3
0
    def save(self, send_net=True, ctime=None):
        """
        Save message in 'Msgs' sqlite db, and record index in 'tags' db.
        """
        from x84.bbs.ini import CFG
        from x84.bbs import getsession

        session = getsession()
        use_session = bool(session is not None)
        log = logging.getLogger(__name__)
        new = self.idx is None or self._stime is None

        # persist message record to MSGDB
        db_msg = DBProxy(MSGDB, use_session=use_session)
        with db_msg:
            if new:
                self.idx = max([int(key) for key in db_msg.keys()] or [-1]) + 1
                if ctime is not None:
                    self._ctime = self._stime = ctime
                else:
                    self._stime = datetime.datetime.now()
                new = True
            db_msg['%d' % (self.idx,)] = self

        # persist message idx to TAGDB
        db_tag = DBProxy(TAGDB, use_session=use_session)
        with db_tag:
            for tag in db_tag.keys():
                msgs = db_tag[tag]
                if tag in self.tags and self.idx not in msgs:
                    msgs.add(self.idx)
                    db_tag[tag] = msgs
                    log.debug("msg {self.idx} tagged '{tag}'"
                              .format(self=self, tag=tag))
                elif tag not in self.tags and self.idx in msgs:
                    msgs.remove(self.idx)
                    db_tag[tag] = msgs
                    log.info("msg {self.idx} removed tag '{tag}'"
                             .format(self=self, tag=tag))
            for tag in [_tag for _tag in self.tags if _tag not in db_tag]:
                db_tag[tag] = set([self.idx])

        # persist message as child to parent;
        if not hasattr(self, 'parent'):
            self.parent = None
        assert self.parent not in self.children
        if self.parent is not None:
            parent_msg = get_msg(self.parent)
            if self.idx != parent_msg.idx:
                parent_msg.children.add(self.idx)
                parent_msg.save()
            else:
                log.error('Parent idx same as message idx; stripping')
                self.parent = None
                with db_msg:
                    db_msg['%d' % (self.idx)] = self

        if send_net and new and CFG.has_option('msg', 'network_tags'):
            self.queue_for_network()

        log.info(
            u"saved {new}{public}msg {post}, addressed to '{self.recipient}'."
            .format(new='new ' if new else '',
                    public='public ' if 'public' in self.tags else '',
                    post='post' if self.parent is None else 'reply',
                    self=self))
Ejemplo n.º 4
0
    def save(self, send_net=True, ctime=None):
        """
        Save message in 'Msgs' sqlite db, and record index in 'tags' db.
        """
        from x84.bbs.ini import CFG
        from x84.bbs import getsession

        session = getsession()
        use_session = bool(session is not None)
        log = logging.getLogger(__name__)
        new = self.idx is None or self._stime is None

        # persist message record to MSGDB
        db_msg = DBProxy(MSGDB, use_session=use_session)
        with db_msg:
            if new:
                self.idx = max(map(int, db_msg.keys()) or [-1]) + 1
                if ctime is not None:
                    self._ctime = self._stime = ctime
                else:
                    self._stime = datetime.datetime.now()
                new = True
            db_msg['%d' % (self.idx, )] = self

        # persist message idx to TAGDB
        db_tag = DBProxy(TAGDB, use_session=use_session)
        with db_tag:
            for tag in db_tag.keys():
                msgs = db_tag[tag]
                if tag in self.tags and self.idx not in msgs:
                    msgs.add(self.idx)
                    db_tag[tag] = msgs
                    log.debug("msg {self.idx} tagged '{tag}'".format(self=self,
                                                                     tag=tag))
                elif tag not in self.tags and self.idx in msgs:
                    msgs.remove(self.idx)
                    db_tag[tag] = msgs
                    log.info("msg {self.idx} removed tag '{tag}'".format(
                        self=self, tag=tag))
            for tag in [_tag for _tag in self.tags if _tag not in db_tag]:
                db_tag[tag] = set([self.idx])

        # persist message as child to parent;
        if not hasattr(self, 'parent'):
            self.parent = None
        assert self.parent not in self.children
        if self.parent is not None:
            parent_msg = get_msg(self.parent)
            if self.idx != parent_msg.idx:
                parent_msg.children.add(self.idx)
                parent_msg.save()
            else:
                log.error('Parent idx same as message idx; stripping')
                self.parent = None
                with db_msg:
                    db_msg['%d' % (self.idx)] = self

        if send_net and new and CFG.has_option('msg', 'network_tags'):
            self.queue_for_network()

        log.info(
            u"saved {new}{public}msg {post}, addressed to '{self.recipient}'.".
            format(new='new ' if new else '',
                   public='public ' if 'public' in self.tags else '',
                   post='post' if self.parent is None else 'reply',
                   self=self))