示例#1
0
 def create_format_entry(self, authortitle, fmt):
     formatdb = Factory.connect_formatdb()
     key = hashlib.md5(authortitle + fmt).hexdigest()
     f = formatdb.new_item(key)
     f.add_value("authortitle", authortitle)
     f.add_value("format", fmt)
     f.add_value("version_count", 1)
     f.add_value("sdbkey", key)
     f.save()
     return key
示例#2
0
文件: datastore.py 项目: cssharp/ogre
 def create_format_entry(self, authortitle, fmt):
     formatdb = Factory.connect_formatdb()
     key = hashlib.md5(authortitle + fmt).hexdigest()
     f = formatdb.new_item(key)
     f.add_value("authortitle", authortitle)
     f.add_value("format", fmt)
     f.add_value("version_count", 1)
     f.add_value("sdbkey", key)
     f.save()
     return key
示例#3
0
文件: datastore.py 项目: cssharp/ogre
    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
示例#4
0
    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