Exemple #1
0
    def prepare(self):
        self.db = FSpotDB()
        self.period = self.options.get('period')

        if self.db:
            self.sql = FSpotPhotoSQL(self.target, self.period)
            self.photos = self.rate_list = RateList(self, FSpotDB)
    def prepare(self):
        self.db = FSpotDB()
        self.period = self.options.get('period')

        if self.db:
            self.sql = FSpotPhotoSQL(self.target, self.period)
            self.photos = self.rate_list = RateList(self, FSpotDB)
class FSpotPhotoList(base.LocalPhotoList):

    delay_for_prepare = False

    def prepare(self):
        self.db = FSpotDB()
        self.period = self.options.get('period')

        if self.db:
            self.sql = FSpotPhotoSQL(self.target, self.period)
            self.photos = self.rate_list = RateList(self, FSpotDB)

    def get_photo(self, cb):
        rate = self.rate_list.get_random_weight()
        columns = 'base_uri, filename, P.id, default_version_id'
        sql = self.sql.get_statement(columns, rate.name)
        sql += ' ORDER BY random() LIMIT 1;'

        photo = self.db.fetchall(sql)
        if not photo: return False
        base_url, filename, id, version = photo[0]
        base_url =  base_url.rstrip('/') + '/'

        if version != 1:
            sql = ("SELECT filename FROM photo_versions WHERE photo_id=%s "
                   "AND version_id=(SELECT default_version_id "
                   "FROM photos WHERE id=%s)") % (id, id)
            filename = self.db.fetchone(sql)

        base_url = self._unquote(base_url)
        filename = self._unquote(filename)
        url = base_url + filename

        fullpath = url.replace('file://', '')
        data = { 'info': FSpotPlugin,
                 'url' : url,
                 'rate' : rate.name,
                 'filename' : fullpath,
                 'title' : filename, # without path
                 'id' : id,
                 'fav' : FSpotFav(rate.name, id, self.rate_list),
                 'version' : version,
                 'trash' : FSpotTrash(self.photolist) }

        self.photo = base.MyPhoto(data)
        cb(None, self.photo)

    def _unquote(self, text):
        result = text if text.find('%') < 0 else \
            urllib.unquote(text).encode('raw_unicode_escape').decode('utf8')
        return result

    def get_tooltip(self):
        period_days = self.sql.get_period_days(self.period)
        period = _('Last %s days') % period_days if period_days else _("All")

        rate_min = self.options.get('rate_min', 0)
        rate_max = self.options.get('rate_max', 5)

        tip = "%s: %s-%s\n%s: %s" % (
            _('Rate'), rate_min, rate_max, _('Period'), period)
        return tip
Exemple #4
0
class FSpotPhotoList(base.LocalPhotoList):

    delay_for_prepare = False

    def prepare(self):
        self.db = FSpotDB()
        self.period = self.options.get('period')

        if self.db:
            self.sql = FSpotPhotoSQL(self.target, self.period)
            self.photos = self.rate_list = RateList(self, FSpotDB)

    def get_photo(self, cb):
        rate = self.rate_list.get_random_weight()
        columns = 'base_uri, filename, P.id, default_version_id'
        sql = self.sql.get_statement(columns, rate.name)
        sql += ' ORDER BY random() LIMIT 1;'

        photo = self.db.fetchall(sql)
        if not photo: return False
        base_url, filename, id, version = photo[0]
        base_url = base_url.rstrip('/') + '/'

        if version != 1:
            sql = ("SELECT filename FROM photo_versions WHERE photo_id=%s "
                   "AND version_id=(SELECT default_version_id "
                   "FROM photos WHERE id=%s)") % (id, id)
            filename = self.db.fetchone(sql)

        base_url = self._unquote(base_url)
        filename = self._unquote(filename)
        url = base_url + filename

        fullpath = url.replace('file://', '')
        data = {
            'info': FSpotPlugin,
            'url': url,
            'rate': rate.name,
            'filename': fullpath,
            'title': filename,  # without path
            'id': id,
            'fav': FSpotFav(rate.name, id, self.rate_list),
            'version': version,
            'trash': FSpotTrash(self.photolist)
        }

        self.photo = base.MyPhoto(data)
        cb(None, self.photo)

    def _unquote(self, text):
        result = text if text.find('%') < 0 else \
            urllib.unquote(text).encode('raw_unicode_escape').decode('utf8')
        return result

    def get_tooltip(self):
        period_days = self.sql.get_period_days(self.period)
        period = _('Last %s days') % period_days if period_days else _("All")

        rate_min = self.options.get('rate_min', 0)
        rate_max = self.options.get('rate_max', 5)

        tip = "%s: %s-%s\n%s: %s" % (_('Rate'), rate_min, rate_max,
                                     _('Period'), period)
        return tip