当前位置: 首页>>代码示例>>Python>>正文


Python driver.USBMS类代码示例

本文整理汇总了Python中calibre.devices.usbms.driver.USBMS的典型用法代码示例。如果您正苦于以下问题:Python USBMS类的具体用法?Python USBMS怎么用?Python USBMS使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了USBMS类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: delete_single_book

 def delete_single_book(self, path):
     try:
         tp = self.thumbpath_from_filepath(path)
         if tp:
             try:
                 os.remove(tp)
             except EnvironmentError as err:
                 if err.errno != errno.ENOENT:
                     prints(u'Failed to delete thumbnail for {!r} at {!r} with error: {}'.format(path, tp, err))
     except Exception:
         import traceback
         traceback.print_exc()
     USBMS.delete_single_book(self, path)
开发者ID:artbycrunk,项目名称:calibre,代码行数:13,代码来源:driver.py

示例2: books

 def books(self, oncard=None, end_session=True):
     debug_print('PRS505: starting fetching books for card', oncard)
     bl = USBMS.books(self, oncard=oncard, end_session=end_session)
     c = self.initialize_XML_cache()
     c.update_booklist(bl, {'carda':1, 'cardb':2}.get(oncard, 0))
     debug_print('PRS505: finished fetching books for card', oncard)
     return bl
开发者ID:MarioJC,项目名称:calibre,代码行数:7,代码来源:driver.py

示例3: sync_booklists

    def sync_booklists(self, booklists, end_session=True):
        debug_print("PRST1: starting sync_booklists")

        opts = self.settings()
        if opts.extra_customization:
            collections = [x.strip() for x in opts.extra_customization[self.OPT_COLLECTIONS].split(",")]
        else:
            collections = []
        debug_print("PRST1: collection fields:", collections)

        if booklists[0] is not None:
            self.update_device_database(booklists[0], collections, None)
        if len(booklists) > 1 and booklists[1] is not None:
            self.update_device_database(booklists[1], collections, "carda")

        USBMS.sync_booklists(self, booklists, end_session=end_session)
        debug_print("PRST1: finished sync_booklists")
开发者ID:john-peterson,项目名称:calibre,代码行数:17,代码来源:driver.py

示例4: sync_booklists

    def sync_booklists(self, booklists, end_session=True):
        debug_print('PRS505: started sync_booklists')
        c = self.initialize_XML_cache()
        blists = {}
        for i in c.paths:
            try:
                if booklists[i] is not None:
                    blists[i] = booklists[i]
            except IndexError:
                pass
        opts = self.settings()
        if opts.extra_customization:
            collections = [x.strip() for x in
                    opts.extra_customization[self.OPT_COLLECTIONS].split(',')]
        else:
            collections = []
        debug_print('PRS505: collection fields:', collections)
        pb = None
        if self.plugboard_func:
            pb = self.plugboard_func(self.__class__.__name__,
                                     'device_db', self.plugboards)
        debug_print('PRS505: use plugboards', pb)
        c.update(blists, collections, pb)
        c.write()

        if opts.extra_customization[self.OPT_REFRESH_COVERS]:
            debug_print('PRS505: uploading covers in sync_booklists')
            for idx,bl in blists.items():
                prefix = self._card_a_prefix if idx == 1 else \
                                self._card_b_prefix if idx == 2 \
                                    else self._main_prefix
                for book in bl:
                    try:
                        p = os.path.join(prefix, book.lpath)
                        self._upload_cover(os.path.dirname(p),
                                          os.path.splitext(os.path.basename(p))[0],
                                          book, p)
                    except:
                        debug_print('FAILED to upload cover',
                                prefix, book.lpath)
        else:
            debug_print('PRS505: NOT uploading covers in sync_booklists')

        USBMS.sync_booklists(self, booklists, end_session=end_session)
        debug_print('PRS505: finished sync_booklists')
开发者ID:BobPyron,项目名称:calibre,代码行数:45,代码来源:driver.py

示例5: __init__

 def __init__(self, path):
     if not os.path.isdir(path):
         raise IOError, 'Path is not a folder'
     path = USBMS.normalize_path(path)
     if path.endswith(os.sep):
         self._main_prefix = path
     else:
         self._main_prefix = path + os.sep
     self.booklist_class = BookList
     self.is_connected = True
开发者ID:089git,项目名称:calibre,代码行数:10,代码来源:driver.py

示例6: books

 def books(self, oncard=None, end_session=True):
     bl = USBMS.books(self, oncard=oncard, end_session=end_session)
     # Read collections information
     collections = os.path.join(self._main_prefix, 'system', 'collections.json')
     if os.access(collections, os.R_OK):
         try:
             self.kindle_update_booklist(bl, collections)
         except:
             import traceback
             traceback.print_exc()
     return bl
开发者ID:GaryMMugford,项目名称:calibre,代码行数:11,代码来源:driver.py

示例7: delete_single_book

    def delete_single_book(self, path):
        if path.replace('\\', '/').endswith('.sdr/assets/metadata.kfx'):
            kfx_path = get_kfx_path(path)
            if DEBUG:
                prints('Kindle driver: Attempting to delete kfx: %r -> %r' % (path, kfx_path))
            if os.path.exists(kfx_path):
                os.unlink(kfx_path)
            sdr_path = kfx_path.rpartition('.')[0] + '.sdr'
            if os.path.exists(sdr_path):
                shutil.rmtree(sdr_path)
            try:
                os.removedirs(os.path.dirname(kfx_path))
            except Exception:
                pass

        else:
            return USBMS.delete_single_book(self, path)
开发者ID:AEliu,项目名称:calibre,代码行数:17,代码来源:driver.py

示例8: books

    def books(self, oncard=None, end_session=True):
        import sqlite3 as sqlite

        dummy_bl = BookList(None, None, None)

        if (
                (oncard == 'carda' and not self._card_a_prefix) or
                (oncard and oncard != 'carda')
            ):
            self.report_progress(1.0, _('Getting list of books on device...'))
            return dummy_bl

        prefix = self._card_a_prefix if oncard == 'carda' else self._main_prefix

        # Let parent driver get the books
        self.booklist_class.rebuild_collections = self.rebuild_collections
        bl = USBMS.books(self, oncard=oncard, end_session=end_session)

        dbpath = self.normalize_path(prefix + DBPATH)
        debug_print("SQLite DB Path: " + dbpath)

        with closing(sqlite.connect(dbpath)) as connection:
            # Replace undecodable characters in the db instead of erroring out
            connection.text_factory = lambda x: unicode(x, "utf-8", "replace")

            cursor = connection.cursor()
            # Query collections
            query = '''
                SELECT books._id, collection.title
                    FROM collections
                    LEFT OUTER JOIN books
                    LEFT OUTER JOIN collection
                    WHERE collections.content_id = books._id AND
                    collections.collection_id = collection._id
                '''
            cursor.execute(query)

            bl_collections = {}
            for i, row in enumerate(cursor):
                bl_collections.setdefault(row[0], [])
                bl_collections[row[0]].append(row[1])

            # collect information on offsets, but assume any
            # offset we already calculated is correct
            if self.device_offset is None:
                query = 'SELECT file_path, modified_date FROM books'
                cursor.execute(query)

                time_offsets = {}
                for i, row in enumerate(cursor):
                    try:
                        comp_date = int(os.path.getmtime(self.normalize_path(prefix + row[0])) * 1000)
                    except (OSError, IOError, TypeError):
                        # In case the db has incorrect path info
                        continue
                    device_date = int(row[1])
                    offset = device_date - comp_date
                    time_offsets.setdefault(offset, 0)
                    time_offsets[offset] = time_offsets[offset] + 1

                try:
                    device_offset = max(time_offsets, key=lambda a: time_offsets.get(a))
                    debug_print("Device Offset: %d ms"%device_offset)
                    self.device_offset = device_offset
                except ValueError:
                    debug_print("No Books To Detect Device Offset.")

            for idx, book in enumerate(bl):
                query = 'SELECT _id, thumbnail FROM books WHERE file_path = ?'
                t = (book.lpath,)
                cursor.execute(query, t)

                for i, row in enumerate(cursor):
                    book.device_collections = bl_collections.get(row[0], None)
                    thumbnail = row[1]
                    if thumbnail is not None:
                        thumbnail = self.normalize_path(prefix + thumbnail)
                        book.thumbnail = ImageWrapper(thumbnail)

            cursor.close()

        return bl
开发者ID:BobPyron,项目名称:calibre,代码行数:82,代码来源:driver.py

示例9: formats_to_scan_for

 def formats_to_scan_for(self):
     ans = USBMS.formats_to_scan_for(self) | {'azw3'}
     return ans
开发者ID:GaryMMugford,项目名称:calibre,代码行数:3,代码来源:driver.py

示例10: initialize

 def initialize(self):
     self.plugin_needs_delayed_initialization = True
     USBMS.initialize(self)
开发者ID:GaryMMugford,项目名称:calibre,代码行数:3,代码来源:driver.py

示例11: create_upload_path

 def create_upload_path(self, path, mdata, fname, create_dirs=True):
     is_news = mdata.tags and _('News') in mdata.tags
     subdir = 'Magazines' if is_news else 'Books'
     path = os.path.join(path, subdir)
     return USBMS.create_upload_path(self, path, mdata, fname,
             create_dirs=create_dirs)
开发者ID:MarioJC,项目名称:calibre,代码行数:6,代码来源:driver.py


注:本文中的calibre.devices.usbms.driver.USBMS类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。