Exemplo n.º 1
0
    def load_bookmarks(self):
        """ Loads persisted bookmarks from a local file.
        @return: Tuple of (bookmarks, file mtime)
        """

        path = constants.BOOKMARK_PICKLE_PATH
        bookmarks = []
        mtime = 0

        if os.path.isfile(path):
            try:
                mtime = os.stat(path).st_mtime
                with open(path, 'rb') as fd:
                    version = pickle.load(fd)
                    packs = pickle.load(fd)

                    for pack in packs:
                        # Handle old bookmarks without date_added attribute
                        if len(pack) == 5:
                            pack = pack + (datetime.datetime.now(), )

                        bookmark = bookmark_menu_item._Bookmark(
                            self._window, self._file_handler, *pack)
                        bookmarks.append(bookmark)

            except Exception:
                log.error(_('! Could not parse bookmarks file %s'), path)

        return bookmarks, mtime
    def add_bookmark_by_values(self, name, path, page, numpages, archive_type,
                               date_added):
        """Create a bookmark and add it to the list."""
        bookmark = bookmark_menu_item._Bookmark(self._window,
                                                self._file_handler, name, path,
                                                page, numpages, archive_type,
                                                date_added)

        self.add_bookmark(bookmark)
Exemplo n.º 3
0
    def add_bookmark_by_values(self, name, path, page, numpages, archive_type,
                               epoch):
        '''Create a bookmark and add it to the list.'''
        bookmark = bookmark_menu_item._Bookmark(self._window,
                                                self._file_handler, name, path,
                                                page, numpages, archive_type,
                                                epoch)

        self.add_bookmark(bookmark)
Exemplo n.º 4
0
    def load_bookmarks(self):
        """ Loads persisted bookmarks from a local file.
        @return: Tuple of (bookmarks, file mtime)
        """

        path = constants.BOOKMARK_PICKLE_PATH
        bookmarks = []
        mtime = 0L

        if os.path.isfile(path):
            fd = None
            try:
                mtime = long(os.stat(path).st_mtime)
                fd = open(path, 'rb')
                version = cPickle.load(fd)
                packs = cPickle.load(fd)

                for pack in packs:
                    # Handle old bookmarks without date_added attribute
                    if len(pack) == 5:
                        pack = pack + (datetime.datetime.now(),)

                    bookmark = bookmark_menu_item._Bookmark(self._window,
                            self._file_handler, *pack)
                    bookmarks.append(bookmark)

            except Exception:
                log.error(_('! Could not parse bookmarks file %s'), path)
            finally:
                try:
                    if fd:
                        fd.close()
                except IOError:
                    pass

        return bookmarks, mtime
Exemplo n.º 5
0
    def load_bookmarks(self):
        ''' Loads persisted bookmarks from a local file.
        @return: Tuple of (bookmarks, file mtime)
        '''

        path = constants.BOOKMARK_JSON_PATH
        bookmarks = []
        mtime = 0

        if os.path.isfile(path):
            try:
                mtime = os.stat(path).st_mtime
                with open(path, mode='rt', encoding='utf8') as fd:
                    version, packs = json.load(fd)
            except Exception:
                log.error(_('! Could not parse bookmarks file %s'), path)
            else:
                for pack in packs:
                    bookmarks.append(
                        bookmark_menu_item._Bookmark(self._window,
                                                     self._file_handler,
                                                     *pack))

        return bookmarks, mtime
Exemplo n.º 6
0
    def add_bookmark_by_values(self, name, path, page, numpages, archive_type, date_added):
        """Create a bookmark and add it to the list."""
        bookmark = bookmark_menu_item._Bookmark(self._window, self._file_handler,
            name, path, page, numpages, archive_type, date_added)

        self.add_bookmark(bookmark)