Exemplo n.º 1
0
        def get_from_database():
            session = DBSession()

            q = session.query(func.count(cls.name), cls.name) \
                .group_by(cls.name).all()

            q = sorted(q, key=lambda x: x[0], reverse=True)

            return q
Exemplo n.º 2
0
     def get_from_database():
         session = DBSession()
 
         q = session.query(func.count(cls.name), cls.name) \
             .group_by(cls.name).all()
 
         q = sorted(q, key=lambda x: x[0], reverse=True)
 
         return q
Exemplo n.º 3
0
     def get_from_database():
         session = DBSession()
 
         q = session.query(func.count(cls.version), cls.version) \
             .filter(cls.kang == False) \
             .group_by(cls.version).all()
 
         q = sorted(q, key=lambda x: x[0], reverse=True)
 
         return q
Exemplo n.º 4
0
        def get_from_database():
            session = DBSession()

            q = session.query(func.count(cls.version), cls.version) \
                .filter(cls.kang == False) \
                .group_by(cls.version).all()

            q = sorted(q, key=lambda x: x[0], reverse=True)

            return q
Exemplo n.º 5
0
    def add(cls, **kwargs):
        # Clean up the version.
        version = parse_modversion(kwargs['version'])

        # Grab a session
        session = DBSession()

        # Grab device record, if it already exists.
        try:
            obj = session.query(cls).filter(cls.hash == kwargs['hash']).one()
        except:
            obj = cls()
            obj.date_added = func.now()

        # Flag this as a KANG if necessary.
        if version == None:
            version = kwargs['version']
            obj.kang = True
        else:
            obj.kang = False

        # Populate the rest of the records.
        obj.hash = kwargs['hash']
        obj.name = kwargs['name']
        obj.version = version
        obj.version_raw = kwargs['version']
        obj.country = kwargs['country']
        obj.carrier_id = kwargs['carrier_id']
        obj.date_updated = func.now()

        logging.info("Saving: %s" % obj)

        session.add(obj)
        session.commit()
Exemplo n.º 6
0
    def add(cls, **kwargs):
        # Clean up the version.
        version = parse_modversion(kwargs['version'])

        # Grab a session
        session = DBSession()

        # Grab device record, if it already exists.
        try:
            obj = session.query(cls).filter(cls.hash == kwargs['hash']).one()
        except:
            obj = cls()
            obj.date_added = func.now()

        # Flag this as a KANG if necessary.
        if version == None:
            version = kwargs['version']
            obj.kang = True
        else:
            obj.kang = False

        # Populate the rest of the records.
        obj.hash = kwargs['hash']
        obj.name = kwargs['name']
        obj.version = version
        obj.version_raw = kwargs['version']
        obj.country = kwargs['country']
        obj.carrier_id = kwargs['carrier_id']
        obj.date_updated = func.now()

        logging.info("Saving: %s" % obj)

        session.add(obj)
        session.commit()
Exemplo n.º 7
0
    def get(self, key):
        value, expires = self.store.get(key, (None, None))
        if expires is not None and expires > time.time():
            logging.info("Cache Hit for '%s', expires in %s seconds" %
                         (key, expires - time.time()))
            return value
        else:
            if value is not None:
                if isinstance(value, list):
                    for obj in value:
                        try:
                            DBSession().expunge(obj)
                            logging.info("Expunged %s", obj)
                        except:
                            pass

            logging.info("Cache Miss for '%s'" % (key))
            return None
Exemplo n.º 8
0
 def get_from_database():
    session = DBSession()
    q = session.query(cls.country, func.count('*').label('count')).group_by(cls.country).all()
    return q
Exemplo n.º 9
0
 def get_from_database():
     session = DBSession()
     q = session.query(func.count(cls.id)).filter(cls.kang == False).one()[0]
     return q
Exemplo n.º 10
0
 def get_from_database():
     timestamp = datetime.datetime.now() - datetime.timedelta(hours=24)
     session = DBSession()
     q = session.query(cls).filter(cls.date_added > timestamp).count()
     return q
Exemplo n.º 11
0
 def get_from_database():
     session = DBSession()
     q = session.query(func.count(
         cls.id)).filter(cls.kang == False).one()[0]
     return q
Exemplo n.º 12
0
 def get_from_database():
     timestamp = datetime.datetime.now() - datetime.timedelta(hours=24)
     session = DBSession()
     q = session.query(cls).filter(cls.date_added > timestamp).count()
     return q
Exemplo n.º 13
0
 def get_from_database():
     session = DBSession()
     q = session.query(cls.country,
                       func.count('*').label('count')).group_by(
                           cls.country).all()
     return q