~ubuntu-branches/ubuntu/oneiric/calibre/oneiric

« back to all changes in this revision

Viewing changes to src/calibre/library/sqlite.py

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2010-06-21 10:18:08 UTC
  • mfrom: (1.3.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20100621101808-aue828f532tmo4zt
Tags: 0.7.2+dfsg-1
* New major upstream version. See http://calibre-ebook.com/new-in/seven for
  details.
* Refresh patches to apply cleanly.
* debian/control: Bump python-cssutils to >= 0.9.7~ to ensure the existence
  of the CSSRuleList.rulesOfType attribute. This makes epub conversion work
  again. (Closes: #584756)
* Add debian/local/calibre-mount-helper: Simple and safe replacement for
  upstream's calibre-mount-helper, using udisks --mount and eject.
  (Closes: #584915, LP: #561958)

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
from datetime import datetime
16
16
 
17
17
from calibre.ebooks.metadata import title_sort
 
18
from calibre.utils.config import tweaks
18
19
from calibre.utils.date import parse_date, isoformat
19
20
 
20
21
global_lock = RLock()
36
37
sqlite.register_adapter(bool, lambda x : 1 if x else 0)
37
38
sqlite.register_converter('bool', convert_bool)
38
39
 
 
40
class DynamicFilter(object):
 
41
 
 
42
    def __init__(self, name):
 
43
        self.name = name
 
44
        self.ids = frozenset([])
 
45
 
 
46
    def __call__(self, id_):
 
47
        return int(id_ in self.ids)
 
48
 
 
49
    def change(self, ids):
 
50
        self.ids = frozenset(ids)
 
51
 
39
52
 
40
53
class Concatenate(object):
41
54
    '''String concatenation aggregator for sqlite'''
103
116
        self.conn.create_aggregate('concat', 1, Concatenate)
104
117
        self.conn.create_aggregate('sortconcat', 2, SortedConcatenate)
105
118
        self.conn.create_aggregate('sort_concat', 2, SafeSortedConcatenate)
106
 
        self.conn.create_function('title_sort', 1, title_sort)
 
119
        if tweaks['title_series_sorting'] == 'library_order':
 
120
            self.conn.create_function('title_sort', 1, title_sort)
 
121
        else:
 
122
            self.conn.create_function('title_sort', 1, lambda x:x)
107
123
        self.conn.create_function('uuid4', 0, lambda : str(uuid.uuid4()))
 
124
        # Dummy functions for dynamically created filters
 
125
        self.conn.create_function('books_list_filter', 1, lambda x: 1)
108
126
 
109
127
    def run(self):
110
128
        try:
119
137
                        ok, res = True, tuple(self.conn.iterdump())
120
138
                    except Exception, err:
121
139
                        ok, res = False, (err, traceback.format_exc())
 
140
                elif func == 'create_dynamic_filter':
 
141
                    try:
 
142
                        f = DynamicFilter(args[0])
 
143
                        self.conn.create_function(args[0], 1, f)
 
144
                        ok, res = True, f
 
145
                    except Exception, err:
 
146
                        ok, res = False, (err, traceback.format_exc())
122
147
                else:
123
148
                    func = getattr(self.conn, func)
124
149
                    try:
203
228
    @proxy
204
229
    def dump(self): pass
205
230
 
 
231
    @proxy
 
232
    def create_dynamic_filter(self): pass
 
233
 
206
234
def connect(dbpath, row_factory=None):
207
235
    conn = ConnectionProxy(DBThread(dbpath, row_factory))
208
236
    conn.proxy.start()