Ejemplo n.º 1
0
 def __delitem__(self, key):
     # pylint: disable=C0111,
     #        Missing docstring
     uadb = DBProxy(USERDB, 'attrs')
     uadb.acquire()
     attrs = uadb[self.handle]
     if key in attrs:
         attrs.__delitem__(key)
         uadb[self.handle] = attrs
     uadb.release()
     logger.info("del attr %r for user '%s'.", key, self.handle)
Ejemplo n.º 2
0
 def __delitem__(self, key):
     # pylint: disable=C0111,
     #        Missing docstring
     uadb = DBProxy(USERDB, 'attrs')
     uadb.acquire()
     attrs = uadb[self.handle]
     if key in attrs:
         attrs.__delitem__(key)
         uadb[self.handle] = attrs
     uadb.release()
     logger.info("del attr %r for user '%s'.", key, self.handle)
Ejemplo n.º 3
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.º 4
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.º 5
0
 def __setitem__(self, key, value):
     # pylint: disable=C0111,
     #        Missing docstring
     if self.handle == 'anonymous':
         logger.debug("set attr %r not possible for 'anonymous'", key)
         return
     adb = DBProxy(USERDB, 'attrs')
     adb.acquire()
     if not self.handle in adb:
         adb[self.handle] = dict([(key, value), ])
     else:
         attrs = adb[self.handle]
         attrs.__setitem__(key, value)
         adb[self.handle] = attrs
     adb.release()
     logger.info("set attr %r for user '%s'.", key, self.handle)
Ejemplo n.º 6
0
 def __setitem__(self, key, value):
     # pylint: disable=C0111,
     #        Missing docstring
     if self.handle == 'anonymous':
         logger.debug("set attr %r not possible for 'anonymous'", key)
         return
     adb = DBProxy(USERDB, 'attrs')
     adb.acquire()
     if not self.handle in adb:
         adb[self.handle] = dict([
             (key, value),
         ])
     else:
         attrs = adb[self.handle]
         attrs.__setitem__(key, value)
         adb[self.handle] = attrs
     adb.release()
     logger.info("set attr %r for user '%s'.", key, self.handle)
Ejemplo n.º 7
0
 def get(self, key, default=None):
     # pylint: disable=C0111,
     #        Missing docstring
     adb = DBProxy(USERDB, 'attrs')
     adb.acquire()
     if not self.handle in adb:
         logger.debug('%r GET %r: default; missing attrs.', self.handle,
                      key)
         val = default
     else:
         attrs = adb[self.handle]
         if not key in attrs:
             logger.debug('%r GET %r: default', self.handle, key)
             val = default
         else:
             logger.debug('%r GET %r%s.' %
                          (self.handle, key, ' (size: %d)' %
                           (len(attrs[key]), ) if hasattr(
                               attrs[key], '__len__') else '(1)'))
             val = attrs[key]
     adb.release()
     return val
Ejemplo n.º 8
0
 def get(self, key, default=None):
     # pylint: disable=C0111,
     #        Missing docstring
     adb = DBProxy(USERDB, 'attrs')
     adb.acquire()
     if not self.handle in adb:
         logger.debug(
             '%r GET %r: default; missing attrs.', self.handle, key)
         val = default
     else:
         attrs = adb[self.handle]
         if not key in attrs:
             logger.debug('%r GET %r: default', self.handle, key)
             val = default
         else:
             logger.debug('%r GET %r%s.' % (
                 self.handle, key,
                 ' (size: %d)' % (len(attrs[key]),)
                 if hasattr(attrs[key], '__len__')
                 else '(1)'))
             val = attrs[key]
     adb.release()
     return val
Ejemplo n.º 9
0
 def save(self):
     """
     (re-)Save user record to databases. Changes to user record to not
     automaticly persist. a call to the .save method must be done.
     """
     assert type(self._handle) is unicode, ('handle must be unicode')
     assert len(self._handle) > 0, ('handle must be non-zero length')
     assert (None, None) != self._password, ('password must be set')
     assert self._handle != u'anonymous', (
         'anonymous user my not be saved.')
     udb = DBProxy(USERDB)
     udb.acquire()
     if 0 == len(udb) and self.is_sysop is False:
         logger.warn('%s: First new user becomes sysop.', self.handle)
         self.group_add(u'sysop')
     udb[self.handle] = self
     adb = DBProxy(USERDB, 'attrs')
     adb.acquire()
     if not self.handle in adb:
         adb[self.handle] = dict()
     adb.release()
     self._apply_groups(DBProxy(GROUPDB))
     udb.release()
     logger.info("saved user '%s'.", self.handle)
Ejemplo n.º 10
0
 def save(self):
     """
     (re-)Save user record to databases. Changes to user record to not
     automaticly persist. a call to the .save method must be done.
     """
     assert type(self._handle) is unicode, ('handle must be unicode')
     assert len(self._handle) > 0, ('handle must be non-zero length')
     assert (None, None) != self._password, ('password must be set')
     assert self._handle != u'anonymous', (
         'anonymous user may not be saved.')
     udb = DBProxy(USERDB)
     udb.acquire()
     if 0 == len(udb) and self.is_sysop is False:
         logger.warn('%s: First new user becomes sysop.', self.handle)
         self.group_add(u'sysop')
     udb[self.handle] = self
     adb = DBProxy(USERDB, 'attrs')
     adb.acquire()
     if not self.handle in adb:
         adb[self.handle] = dict()
     adb.release()
     self._apply_groups(DBProxy(GROUPDB))
     udb.release()
     logger.info("saved user '%s'.", self.handle)