Пример #1
0
 def setup(self):
     try:
         new_attrs = {}
         new_attrs.update(self.attrs)
         new_attrs.update(self.do_get_dependencies())
         self.obj = self.klass(**new_attrs)
         DBSession.add(self.obj)
         DBSession.flush()
         return self.obj
     except:
         DBSession.rollback()
         raise
Пример #2
0
    def update(mini_cls, access):
        proxy_status = access.proxy_status.text
        if proxy_status.startswith("UDP_") or proxy_status == "NONE":
            return
        if access.proxy_status.text == "TCP_DENIED":
            status = mini_cls.denied
        else:
            status = mini_cls.allowed

        mini = (
            DBSession.query(mini_cls)
            .join(Address)
            .join(Domain)
            .join(ProxyUser)
            .filter(
                and_(
                    Address.text == access.address.text,
                    Domain.text == access.domain.text,
                    ProxyUser.text == access.proxy_user.text,
                    mini_cls.date == access.date,
                    mini_cls.status == status,
                )
            )
            .all()
        )

        if len(mini) == 0:
            mini = mini_cls()
            mini.date = access.date
            mini.address = access.address
            mini.domain = access.domain
            mini.proxy_user = access.proxy_user
            mini.upload_bytes = int(access.request_size)
            mini.download_bytes = int(access.reply_size)
            mini.count = 1
            mini.status = status
            DBSession.add(mini)
        else:
            mini = mini[0]
            mini.upload_bytes += int(access.request_size)
            mini.download_bytes += int(access.reply_size)
            mini.count += 1
Пример #3
0
    def get(cls, text):
        cls.check(text)

        if fk_cache.has_key(cls) and fk_cache[cls].has_key(text):
            return fk_cache[cls][text]

        query = DBSession.query(cls)
        query._autoflush = False
        data = query.filter(cls.text == text).all()
        if len(data) == 0:
            data = cls()
            data.text = text
            DBSession.add(data)
        elif len(data) == 1:
            data = data[0]
        else:
            # XXX: do this better
            raise Exception()

        if not fk_cache.has_key(cls):
            fk_cache[cls] = {}
        fk_cache[cls][text] = data
        return data