Ejemplo n.º 1
0
class RecentQueue(list):

    def __init__(self):
        super(RecentQueue, self).__init__()
        self.clear_cache()
        self.history = HistoryFactory().create()

    def append(self, photo):
        self.remove(photo['filename'])
        super(RecentQueue, self).append(photo)

        # print photo.get('page_url') or photo.get('url')
        self.history.add(photo)
        num = SETTINGS_RECENTS.get_int('queue-number')
        if len(self) > num:
            self.pop(0)

    def remove(self, url):
        for i, queue_photo in enumerate(self):
            if queue_photo['url'] == url:
                super(RecentQueue, self).pop(i)

    def pop(self, num):
        pop_photo = super(RecentQueue, self).pop(num)

        url = pop_photo['url']
        cache_filename = url.replace('/', '_')
        thumb_filename = 'thumb_' + cache_filename

        for path in [cache_filename, thumb_filename]:
            cache_fullpath = os.path.join(CACHE_DIR, path)
            if os.access(cache_fullpath, os.R_OK):
                os.remove(cache_fullpath)
        
    def menu_item(self):
        num = SETTINGS_RECENTS.get_int('queue-menu-number') * -1
        return self[num:]

    def clear_cache(self):
        cache_files = []

        for table in ['photoframe', 'screensaver']:
            recents = History(table).get(10)
            cache_files += [photo[1].replace('/', '_') for photo in recents]

        all_caches = cache_files + ['thumb_' + file for file in cache_files]

        for fullpath in glob.iglob(os.path.join(CACHE_DIR, '*')):
            filename = os.path.basename(fullpath).decode('utf-8')
            if filename not in all_caches:
                os.remove(fullpath)
Ejemplo n.º 2
0
class RecentQueue(list):
    def __init__(self):
        super(RecentQueue, self).__init__()
        self.clear_cache()
        self.history = HistoryFactory().create()

    def append(self, photo):
        self.remove(photo['filename'])
        super(RecentQueue, self).append(photo)

        # print photo.get('page_url') or photo.get('url')
        self.history.add(photo)
        num = SETTINGS_RECENTS.get_int('queue-number')
        if len(self) > num:
            self.pop(0)

    def remove(self, url):
        for i, queue_photo in enumerate(self):
            if queue_photo['url'] == url:
                super(RecentQueue, self).pop(i)

    def pop(self, num):
        pop_photo = super(RecentQueue, self).pop(num)

        url = pop_photo['url']
        cache_filename = url.replace('/', '_')
        thumb_filename = 'thumb_' + cache_filename

        for path in [cache_filename, thumb_filename]:
            cache_fullpath = os.path.join(CACHE_DIR, path)
            if os.access(cache_fullpath, os.R_OK):
                os.remove(cache_fullpath)

    def menu_item(self):
        num = SETTINGS_RECENTS.get_int('queue-menu-number') * -1
        return self[num:]

    def clear_cache(self):
        cache_files = []

        for table in ['photoframe', 'screensaver']:
            recents = History(table).get(10)
            cache_files += [photo[1].replace('/', '_') for photo in recents]

        all_caches = cache_files + ['thumb_' + file for file in cache_files]

        for fullpath in glob.iglob(os.path.join(CACHE_DIR, '*')):
            filename = os.path.basename(fullpath).decode('utf-8')
            if filename not in all_caches:
                os.remove(fullpath)
Ejemplo n.º 3
0
 def __init__(self):
     super(RecentQueue, self).__init__()
     self.clear_cache()
     self.history = HistoryFactory().create()
Ejemplo n.º 4
0
 def __init__(self):
     super(RecentQueue, self).__init__()
     self.clear_cache()
     self.history = HistoryFactory().create()