Exemplo n.º 1
0
    def method_get_all_builds(self):
        channels = self.params.get('channels', None)
        device = self.params.get('device', None)
        limit = int(self.params.get('limit', 3))
        if not channels or not device:
            self.set_status(500)
            return self.fail("Invalid Parameters")

        cache_key = 'api_all_%s_%s_%s' % (device, "_".join(sorted(channels)), str(limit))
        result = cache.get(cache_key)
        if result is not None:
            return self.success(result)

        result = []

        if 'snapshot' in channels and 'RC' not in channels:
            channels.append('RC')

        for channel in channels:
            files = File.browse(device, channel, limit)
            for file_obj in files:
                if file_obj is not None:
                    changesfile = re.sub(file_obj.filename, "CHANGES.txt", file_obj.full_path)
                    result.append({
                        'channel': channel,
                        'filename': file_obj.filename,
                        'url': "http://yauniks.dynvpn.de:86/get/%s" % file_obj.full_path,
                        'changes': "http://yauniks.dynvpn.de:86/get/%s" % changesfile,
                        'md5sum': file_obj.md5sum,
                        'timestamp': file_obj.date_created.strftime('%s')
                    })

        cache.set(cache_key, result)

        return self.success(result)
Exemplo n.º 2
0
def static_url(path):
    path = path.lstrip("/")
    cache_key = 'static_hash_%s' % path
    result = cache.get(cache_key)
    if result is not None:
        return "/static/%s?v=%s" % (path, result)
    else:
        try:
            static_path = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "static"))
            f = open(os.path.join(static_path, path))
            f_hash = hashlib.md5(f.read()).hexdigest()[:5]
            cache.set(cache_key, f_hash, expiry=3600)
            return "/static/%s?v=%s" % (path, f_hash)
        except:
            return "/static/%s" % path
Exemplo n.º 3
0
def static_url(path):
    path = path.lstrip("/")
    cache_key = 'static_hash_%s' % path
    result = cache.get(cache_key)
    if result is not None:
        return "/static/%s?v=%s" % (path, result)
    else:
        try:
            static_path = os.path.realpath(
                os.path.join(os.path.dirname(__file__), "..", "static"))
            f = open(os.path.join(static_path, path))
            f_hash = hashlib.md5(f.read()).hexdigest()[:5]
            cache.set(cache_key, f_hash, expiry=3600)
            return "/static/%s?v=%s" % (path, f_hash)
        except:
            return "/static/%s" % path
Exemplo n.º 4
0
    def get_by_md5sum(cls, md5hash):
        cache_key = "get_by_md5sum:%s" % md5hash

        def get_from_database():
            session = DBSession()
            try:
                file = session.query(cls).filter(cls.md5sum == md5hash).one()
            except NoResultFound:
                file = None

            return file

        result = cache.get(cache_key)
        if result is None:
            result = cache.set(cache_key, get_from_database())

        return result
Exemplo n.º 5
0
    def get_by_base62(cls, base62):
        cache_key = "get_by_base62_%s" % base62

        def get_from_database():
            session = DBSession()
            try:
                file = session.query(cls).filter(cls.id == base62_decode(base62)).one()
            except NoResultFound:
                file = None

            return file

        result = cache.get(cache_key)
        if result is None:
            result = cache.set(cache_key, get_from_database())

        return result
Exemplo n.º 6
0
    def get_by_fullpath(cls, filename):
        cache_key = "get_by_fullpath_%s" % filename

        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

        result = cache.get(cache_key)
        if result is None:
            result = cache.set(cache_key, get_from_database())

        return result
Exemplo n.º 7
0
    def get_latest_by_device(cls, device):
        cache_key = "get_latest_by_device_%s" % device

        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

        result = cache.get(cache_key)
        if result is None:
            result = cache.set(cache_key, get_from_database())

        return result
Exemplo n.º 8
0
    def get_all(cls):
        cache_key = "all_the_things"

        def get_from_database():
            devices = []

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

            return sorted(devices)

        result = cache.get(cache_key)
        if result is None:
            result = cache.set(cache_key, get_from_database())

        return result
Exemplo n.º 9
0
    def get_by_md5sum(cls, md5hash):
        cache_key = "get_by_md5sum:%s" % md5hash

        def get_from_database():
            session = DBSession()
            try:
                file = session.query(cls).filter(cls.md5sum == md5hash).one()
            except NoResultFound:
                file = None

            return file

        result = cache.get(cache_key)
        if result is None:
            result = cache.set(cache_key, get_from_database())

        return result
Exemplo n.º 10
0
    def get_all(cls):
        cache_key = "all_the_things"

        def get_from_database():
            devices = []

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

            return sorted(devices)

        result = cache.get(cache_key)
        if result is None:
            result = cache.set(cache_key, get_from_database())

        return result
Exemplo n.º 11
0
    def get_by_base62(cls, base62):
        cache_key = "get_by_base62_%s" % base62

        def get_from_database():
            session = DBSession()
            try:
                file = session.query(cls).filter(
                    cls.id == base62_decode(base62)).one()
            except NoResultFound:
                file = None

            return file

        result = cache.get(cache_key)
        if result is None:
            result = cache.set(cache_key, get_from_database())

        return result
Exemplo n.º 12
0
    def get_by_fullpath(cls, filename):
        cache_key = "get_by_fullpath_%s" % filename

        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

        result = cache.get(cache_key)
        if result is None:
            result = cache.set(cache_key, get_from_database())

        return result
Exemplo n.º 13
0
    def method_get_all_builds(self):
        channels = self.params.get('channels', None)
        device = self.params.get('device', None)
        limit = int(self.params.get('limit', 3))
        if not channels or not device:
            self.set_status(500)
            return self.fail("Invalid Parameters")

        cache_key = 'api_all_%s_%s_%s' % (device, "_".join(
            sorted(channels)), str(limit))
        result = cache.get(cache_key)
        if result is not None:
            return self.success(result)

        result = []

        if 'snapshot' in channels and 'RC' not in channels:
            channels.append('RC')

        for channel in channels:
            files = File.browse(device, channel, limit)
            for file_obj in files:
                if file_obj is not None:
                    changesfile = re.sub(file_obj.filename, "CHANGES.txt",
                                         file_obj.full_path)
                    result.append({
                        'channel':
                        channel,
                        'filename':
                        file_obj.filename,
                        'url':
                        "http://yauniks.dynvpn.de:86/get/%s" %
                        file_obj.full_path,
                        'changes':
                        "http://yauniks.dynvpn.de:86/get/%s" % changesfile,
                        'md5sum':
                        file_obj.md5sum,
                        'timestamp':
                        file_obj.date_created.strftime('%s')
                    })

        cache.set(cache_key, result)

        return self.success(result)
Exemplo n.º 14
0
    def get_build(cls, channel, device, after):
        cache_key = "%s_%s_%s" % (channel, device, after)

        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

        result = cache.get(cache_key)
        if result is None:
            result = cache.set(cache_key, get_from_database())

        return result
Exemplo n.º 15
0
    def get_latest_by_device(cls, device):
        cache_key = "get_latest_by_device_%s" % device

        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

        result = cache.get(cache_key)
        if result is None:
            result = cache.set(cache_key, get_from_database())

        return result
Exemplo n.º 16
0
    def get_build(cls, channel, device, after):
        cache_key = "%s_%s_%s" % (channel, device, after)

        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

        result = cache.get(cache_key)
        if result is None:
            result = cache.set(cache_key, get_from_database())

        return result
Exemplo n.º 17
0
    def browse(cls, device, type, limit=50):
        cache_key = "%s_%s_%s" % (device or "null", type or "null", limit)

        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

        result = cache.get(cache_key)
        if result is None:
            result = cache.set(cache_key, get_from_database())

        return result
Exemplo n.º 18
0
    def browse(cls, device, type, limit=50):
        cache_key = "%s_%s_%s" % (device or "null", type or "null", limit)

        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

        result = cache.get(cache_key)
        if result is None:
            result = cache.set(cache_key, get_from_database())

        return result