Exemplo n.º 1
0
        def get_from_database():
            session = DBSession()
            try:
                file = session.query(cls).filter(cls.full_path == filename).order_by(cls.id.desc()).first()
            except NoResultFound:
                file = None

            return file
Exemplo n.º 2
0
        def get_from_database():
            session = DBSession()
            try:
                file = session.query(cls).filter(cls.id == base62_decode(base62)).one()
            except NoResultFound:
                file = None

            return file
Exemplo n.º 3
0
        def get_from_database():
            devices = []

            session = DBSession()
            for device in session.query(File.device).distinct():
                devices.append(device[0])

            return sorted(devices)
Exemplo n.º 4
0
 def get_from_database():
     session = DBSession()
     try:
         file = session.query(cls).filter(cls.device == device).order_by(cls.date_created.desc()).first()
     except NoResultFound:
         file = None
     
     return file
Exemplo n.º 5
0
        def get_from_database():
            session = DBSession()
            try:
                file = session.query(cls).filter(cls.md5sum == md5hash).one()
            except NoResultFound:
                file = None

            return file
Exemplo n.º 6
0
        def get_from_database():
            session = DBSession()
            query = session.query(cls)

            query = query.select_from(File).filter(cls.type == channel)
            query = query.filter(cls.device == device)
            query = query.filter(cls.date_created >= datetime.fromtimestamp(after))
            query = query.order_by(cls.date_created.desc()).first()

            return query
Exemplo n.º 7
0
        def get_from_database():
            session = DBSession()
            query = session.query(cls)

            if device is not None:
                query = query.select_from(File).filter(File.device == device)

            if type is not None:
                query = query.filter(cls.type == type)

            # Limit the query and order it
            query = query.order_by(cls.date_created.desc())[:limit]

            return query
Exemplo n.º 8
0
def process_file(args):
    init_database(create_engine(args.db_uri))
    session = DBSession()

    md5hash = md5sum(args.file)
    new = File.get_by_md5sum(md5hash)
    if new is None:
        new = File()
        new.md5sum = md5hash

    if args.url:
        new.filename = os.path.basename(args.url)
    else:
        new.filename = os.path.basename(args.file)

    if args.full_path:
        new.full_path = args.full_path
    else:
        new.full_path = args.file.replace(args.base_path, "")

    new.type = args.type
    new.size = os.path.getsize(args.file)
    new.device = args.device
    if args.timestamp is not None:
        new.date_created = datetime.fromtimestamp(args.timestamp)
    else:
        new.date_created = datetime.fromtimestamp(os.path.getmtime(args.file))

    logging.debug("Filename = %s", new.filename)
    logging.debug("Type = %s", new.type)
    logging.debug("Device = %s", new.device)
    logging.debug("MD5 = %s", new.md5sum)

    try:
        session.add(new)
        session.commit()
        logging.info("File added successfully!")
    except IntegrityError:
        session.rollback()
        logging.error("File already exists: '%s'", new.filename)

    if args.url:
        logging.info("Removing temporary file '%s'", args.file)
        os.remove(args.file)
Exemplo n.º 9
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