def update_library(self, ebooks): new_ebook_count = 0 bookdb = Factory.connect_bookdb() formatdb = Factory.connect_formatdb() versiondb = Factory.connect_versiondb() for authortitle in ebooks.keys(): # check for this in the library key = hashlib.md5(authortitle).hexdigest() b = bookdb.get_item(key) if b is None: self.create_book_entry(authortitle, ebooks[authortitle].keys()) # create format and version entries for fmt in ebooks[authortitle].keys(): self.create_format_entry(authortitle, fmt) self.create_version_entry(authortitle, fmt, 1, ebooks[authortitle][fmt]['size'], ebooks[authortitle][fmt]['filehash']) new_ebook_count += 1 # update an existing book else: # add user to set of owners if self.user.username not in b['users']: b.add_value("users", self.user.username) # check if supplied formats already exist for fmt in ebooks[authortitle].keys(): key = hashlib.md5(authortitle).hexdigest() f = formatdb.get_item(key) # append to the set of this book's formats if fmt not in b['formats']: b.add_value("formats", fmt) if f is None: # create the new format and version entries self.create_format_entry(authortitle, fmt) self.create_version_entry(authortitle, fmt, 1, ebooks[authortitle][fmt]['size'], ebooks[authortitle][fmt]['filehash']) new_ebook_count += 1 else: # format exists; ensure this exact version hasn't already been uploaded if self.check_version_exists(ebooks[authortitle][fmt]['filehash']): # increment the count of different versions of this format f['version_count'] = int(f['version_count']) + 1 f.save() # create the new version entry self.create_version_entry(authortitle, fmt, f['version_count'], ebooks[authortitle][fmt]['size'], ebooks[authortitle][fmt]['filehash']) new_ebook_count += 1 else: print "ignoring exact duplicate %s" % authortitle return new_ebook_count
def create_version_entry(self, authortitle, fmt, version, size, filehash): versiondb = Factory.connect_versiondb() key = hashlib.md5(authortitle + '-' + str(version) + fmt).hexdigest() v = versiondb.new_item(key) v.add_value("authortitle", authortitle) v.add_value("version", version) v.add_value("format", fmt) v.add_value("user", self.user.username) v.add_value("size", size) v.add_value("filehash", filehash) v.add_value("sdbkey", key) v.save() return key
def update_library(self, ebooks): new_ebook_count = 0 bookdb = Factory.connect_bookdb() formatdb = Factory.connect_formatdb() versiondb = Factory.connect_versiondb() for authortitle in ebooks.keys(): # check for this in the library key = hashlib.md5(authortitle).hexdigest() b = bookdb.get_item(key) if b is None: self.create_book_entry(authortitle, ebooks[authortitle].keys()) # create format and version entries for fmt in ebooks[authortitle].keys(): self.create_format_entry(authortitle, fmt) self.create_version_entry( authortitle, fmt, 1, ebooks[authortitle][fmt]['size'], ebooks[authortitle][fmt]['filehash']) new_ebook_count += 1 # update an existing book else: # add user to set of owners if self.user.username not in b['users']: b.add_value("users", self.user.username) # check if supplied formats already exist for fmt in ebooks[authortitle].keys(): key = hashlib.md5(authortitle).hexdigest() f = formatdb.get_item(key) # append to the set of this book's formats if fmt not in b['formats']: b.add_value("formats", fmt) if f is None: # create the new format and version entries self.create_format_entry(authortitle, fmt) self.create_version_entry( authortitle, fmt, 1, ebooks[authortitle][fmt]['size'], ebooks[authortitle][fmt]['filehash']) new_ebook_count += 1 else: # format exists; ensure this exact version hasn't already been uploaded if self.check_version_exists( ebooks[authortitle][fmt]['filehash']): # increment the count of different versions of this format f['version_count'] = int(f['version_count']) + 1 f.save() # create the new version entry self.create_version_entry( authortitle, fmt, f['version_count'], ebooks[authortitle][fmt]['size'], ebooks[authortitle][fmt]['filehash']) new_ebook_count += 1 else: print "ignoring exact duplicate %s" % authortitle return new_ebook_count
def set_dedrm_flag(self, sdbkey): versiondb = Factory.connect_versiondb() v = versiondb.get_item(sdbkey) v.add_value("dedrm", True) v.save()
def set_uploaded(self, sdbkey): versiondb = Factory.connect_versiondb() v = versiondb.get_item(sdbkey) v.add_value("uploaded", True) v.save()