9 c.execute('SELECT metadata.SortStr(%s)', (name))
10 return c.fetchone()[0]
12 print "No connection to DB"
15 def SortAuthorName(name):
18 c.execute('SELECT metadata.SortAuthor(%s)', (name))
19 return c.fetchone()[0]
21 print "No connection to DB"
24 def GetOrCreateAuthor(name):
27 c.execute('SELECT metadata.GetOrCreateAuthor(%s)', (name))
28 return c.fetchone()[0]
30 print "No connection to DB"
33 def GetOrCreateLang(name):
36 c.execute('SELECT metadata.GetOrCreateLang(%s)', (name))
37 return c.fetchone()[0]
39 print "No connection to DB"
42 def GetOrCreatePublisher(name):
45 c.execute('SELECT metadata.GetOrCreatePublisher(%s)', (name))
46 return c.fetchone()[0]
48 print "No connection to DB"
51 def GetOrCreateSeries(name):
54 c.execute('SELECT metadata.GetOrCreateSeries(%s)', (name))
55 return c.fetchone()[0]
57 print "No connection to DB"
60 def GetOrCreateTag(name):
63 c.execute('SELECT metadata.GetOrCreateTag(%s)', (name))
64 return c.fetchone()[0]
66 print "No connection to DB"
69 def CreateBook(title,pubdate,series_index,isbn):
72 c.execute('SELECT metadata.CreateBook(%s,%s,%s,%s)', (title,pubdate,series_index,isbn))
73 return c.fetchone()[0]
75 print "No connection to DB"
78 def LinkBookToAuthors(book_id,author_ids):
81 for author_id in author_ids:
82 c.execute('INSERT INTO metadata.books_authors_link(book,author) VALUES (%s,%s)', (book_id,author_id))
84 print "No connection to DB"
87 def LinkBookToLangs(book_id,lang_ids):
91 for lang_id in lang_ids:
93 c.execute('INSERT INTO metadata.books_languages_link(book,lang_code,item_order) VALUES (%s,%s,%s)', (book_id,lang_id,io))
95 print "No connection to DB"
98 def LinkBookToPublishers(book_id,pub_id):
100 c = database.cursor()
101 c.execute('INSERT INTO metadata.books_publishers_link(book,publisher) VALUES (%s,%s)', (book_id,pub_id))
103 print "No connection to DB"
106 def LinkBookToSeries(book_id,ser_id):
108 c = database.cursor()
109 c.execute('INSERT INTO metadata.books_series_link(book,series) VALUES (%s,%s)', (book_id,ser_id))
111 print "No connection to DB"
114 def LinkBookToTags(book_id,tag_ids):
116 c = database.cursor()
117 for tag_id in tag_ids:
118 c.execute('INSERT INTO metadata.books_tags_link(book,tag) VALUES (%s,%s)', (book_id,tag_id))
120 print "No connection to DB"
123 def SetPath(book_id,path,dataname,filesize,cover):
125 c = database.cursor()
126 c.execute('UPDATE metadata.books SET path=%s, has_cover=%s WHERE id=%s', (path,cover,book_id))
127 c.execute('INSERT INTO metadata.data(book,format,uncompressed_size,name) values (%s,%s,%s,%s)',(book_id,'FB2',filesize,dataname))
129 print "No connection to DB"
132 def StoreComment(book_id,comment):
134 c = database.cursor()
135 c.execute('INSERT INTO metadata.comments(book,text) values (%s,%s)',(book_id,comment))
137 print "No connection to DB"
140 def PathByID(book_id):
142 c = database.cursor()
143 c.execute('SELECT path FROM metadata.books WHERE id=%s',(book_id))
144 return c.fetchone()[0]
146 print "No connection to DB"
149 def DataByID(book_id,format):
151 c = database.cursor()
152 c.execute('SELECT name FROM metadata.data WHERE book=%s and format=%s',(book_id,format))
153 return c.fetchone()[0]+'.'+format.lower()
155 print "No connection to DB"
158 def DelBook(book_id):
160 c = database.cursor()
161 c.execute('DELETE FROM metadata.books WHERE id=%s',(book_id))
163 print "No connection to DB"
166 def ChangeBookFormat(book_id,old_format,new_format):
168 c = database.cursor()
169 c.execute('UPDATE metadata.data SET format=%s WHERE book=%s and format=%s',(new_format,book_id,old_format))
171 print "No connection to DB"
174 def TestArchive(name):
176 c = database.cursor()
177 c.execute('SELECT count(*) from metadata.processed_archives WHERE filename=%s',(name))
178 return c.fetchone()[0]
180 print "No connection to DB"
183 def MarkArchive(name):
185 c = database.cursor()
186 c.execute('insert into metadata.processed_archives(filename) values (%s)',(name))
188 print "No connection to DB"
191 def ListByFormat(format,limit=100):
193 c = database.cursor()
194 c.execute('SELECT DISTINCT book FROM metadata.data WHERE format=%s ORDER BY book LIMIT 0,%s',(format,limit))
197 print "No connection to DB"
204 print "No connection to DB"
211 print "No connection to DB"
217 cfg = ConfigParser.RawConfigParser(allow_no_value=True)
218 cfg.readfp(open('/etc/openlib.conf'))
219 dbhost = cfg.get("mysql","host")
220 dbuser = cfg.get("mysql","user")
221 dbpasswd = cfg.get("mysql","passwd")
222 file_root = cfg.get("storage","files")
223 tmp_files = cfg.get("storage","temp")
224 failed_files = cfg.get("storage","failed")
225 upload_files = cfg.get("storage","upload")
229 print "Error reading configuration file"
234 database = MySQLdb.connect(host=dbhost,user=dbuser,passwd=dbpasswd,use_unicode=True)
235 database.set_character_set('utf8')
236 c = database.cursor()
237 c.execute('SET NAMES utf8;')
241 print "Error connecting database"