Ejemplo n.º 1
0
    def _add_formats(self, paths):
        added = False
        if not paths:
            return added
        bad_perms = []
        for _file in paths:
            _file = os.path.abspath(_file)
            if not os.access(_file, os.R_OK):
                bad_perms.append(_file)
                continue

            nfile = run_plugins_on_import(_file)
            if nfile is not None:
                _file = nfile
            stat = os.stat(_file)
            size = stat.st_size
            ext = os.path.splitext(_file)[1].lower().replace('.', '')
            timestamp = utcfromtimestamp(stat.st_mtime)
            for row in range(self.formats.count()):
                fmt = self.formats.item(row)
                if fmt.ext.lower() == ext:
                    self.formats.takeItem(row)
                    break
            Format(self.formats, ext, size, path=_file, timestamp=timestamp)
            self.changed = True
            added = True
        if bad_perms:
            error_dialog(self, _('No permission'),
                    _('You do not have '
                'permission to read the following files:'),
                det_msg='\n'.join(bad_perms), show=True)

        return added
Ejemplo n.º 2
0
    def restore_books(self):
        self.progress_callback(None, len(self.books))
        self.books.sort(key=itemgetter('id'))

        db = Restorer(self.library_path)

        for i, book in enumerate(self.books):
            try:
                db.restore_book(book['id'], book['mi'],
                                utcfromtimestamp(book['timestamp']),
                                book['path'], book['formats'],
                                book['annotations'])
                self.successes += 1
            except:
                self.failed_restores.append((book, traceback.format_exc()))
            self.progress_callback(book['mi'].title, i + 1)

        id_map = db.get_item_ids('authors',
                                 [author for author in self.authors_links])
        link_map = {
            aid: self.authors_links[name][0]
            for name, aid in iteritems(id_map) if aid is not None
        }
        if link_map:
            db.set_link_for_authors(link_map)
        db.close()
Ejemplo n.º 3
0
    def _add_formats(self, paths):
        added = False
        if not paths:
            return added
        bad_perms = []
        for _file in paths:
            _file = os.path.abspath(_file)
            if not os.access(_file, os.R_OK):
                bad_perms.append(_file)
                continue

            nfile = run_plugins_on_import(_file)
            if nfile is not None:
                _file = nfile
            stat = os.stat(_file)
            size = stat.st_size
            ext = os.path.splitext(_file)[1].lower().replace('.', '')
            timestamp = utcfromtimestamp(stat.st_mtime)
            for row in range(self.formats.count()):
                fmt = self.formats.item(row)
                if fmt.ext.lower() == ext:
                    self.formats.takeItem(row)
                    break
            Format(self.formats, ext, size, path=_file, timestamp=timestamp)
            self.changed = True
            added = True
        if bad_perms:
            error_dialog(self,
                         _('No permission'),
                         _('You do not have '
                           'permission to read the following files:'),
                         det_msg='\n'.join(bad_perms),
                         show=True)

        return added
Ejemplo n.º 4
0
 def mobile_css(self, *args, **kwargs):
     path = P('content_server/mobile.css')
     cherrypy.response.headers['Content-Type'] = 'text/css; charset=utf-8'
     updated = utcfromtimestamp(os.stat(path).st_mtime)
     cherrypy.response.headers['Last-Modified'] = self.last_modified(updated)
     with open(path, 'rb') as f:
         ans = f.read()
     return ans.replace('{prefix}', self.opts.url_prefix)
Ejemplo n.º 5
0
 def mobile_css(self, *args, **kwargs):
     path = P("content_server/mobile.css")
     cherrypy.response.headers["Content-Type"] = "text/css; charset=utf-8"
     updated = utcfromtimestamp(os.stat(path).st_mtime)
     cherrypy.response.headers["Last-Modified"] = self.last_modified(updated)
     with open(path, "rb") as f:
         ans = f.read()
     return ans.replace("{prefix}", self.opts.url_prefix)
Ejemplo n.º 6
0
 def mobile_css(self, *args, **kwargs):
     path = P('content_server/mobile.css')
     cherrypy.response.headers['Content-Type'] = 'text/css; charset=utf-8'
     updated = utcfromtimestamp(os.stat(path).st_mtime)
     cherrypy.response.headers['Last-Modified'] = self.last_modified(updated)
     with open(path, 'rb') as f:
         ans = f.read()
     return ans.replace('{prefix}', self.opts.url_prefix)
Ejemplo n.º 7
0
 def format_metadata(self, book_id, fmt, fname, path):
     path = self.format_abspath(book_id, fmt, fname, path)
     ans = {}
     if path is not None:
         stat = os.stat(path)
         ans['size'] = stat.st_size
         ans['mtime'] = utcfromtimestamp(stat.st_mtime)
     return ans
Ejemplo n.º 8
0
 def format_metadata(self, book_id, fmt, fname, path):
     path = self.format_abspath(book_id, fmt, fname, path)
     ans = {}
     if path is not None:
         stat = os.stat(path)
         ans['size'] = stat.st_size
         ans['mtime'] = utcfromtimestamp(stat.st_mtime)
     return ans
Ejemplo n.º 9
0
    def restore_book(self, book, db):
        db.create_book_entry(book['mi'], add_duplicates=True,
                force_id=book['id'])
        if book['mi'].uuid:
            db.set_uuid(book['id'], book['mi'].uuid, commit=False, notify=False)
        db.conn.execute('UPDATE books SET path=?,last_modified=? WHERE id=?', (book['path'],
            utcfromtimestamp(book['timestamp']), book['id']))

        for fmt, size, name in book['formats']:
            db.conn.execute('''
                INSERT INTO data (book,format,uncompressed_size,name)
                VALUES (?,?,?,?)''', (book['id'], fmt, size, name))
        db.conn.commit()
        self.successes += 1
Ejemplo n.º 10
0
    def restore_book(self, book, db):
        db.create_book_entry(book['mi'], add_duplicates=True,
                force_id=book['id'])
        if book['mi'].uuid:
            db.set_uuid(book['id'], book['mi'].uuid, commit=False, notify=False)
        db.conn.execute('UPDATE books SET path=?,last_modified=? WHERE id=?', (book['path'],
            utcfromtimestamp(book['timestamp']), book['id']))

        for fmt, size, name in book['formats']:
            db.conn.execute('''
                INSERT INTO data (book,format,uncompressed_size,name)
                VALUES (?,?,?,?)''', (book['id'], fmt, size, name))
        db.conn.commit()
        self.successes += 1
Ejemplo n.º 11
0
    def restore_books(self):
        self.progress_callback(None, len(self.books))
        self.books.sort(key=itemgetter('id'))

        db = Restorer(self.library_path)

        for i, book in enumerate(self.books):
            try:
                db.restore_book(book['id'], book['mi'], utcfromtimestamp(book['timestamp']), book['path'], book['formats'])
                self.successes += 1
            except:
                self.failed_restores.append((book, traceback.format_exc()))
            self.progress_callback(book['mi'].title, i+1)

        id_map = db.get_item_ids('authors', [author for author in self.authors_links])
        link_map = {aid:self.authors_links[name][0] for name, aid in id_map.iteritems() if aid is not None}
        if link_map:
            db.set_link_for_authors(link_map)
        db.close()
Ejemplo n.º 12
0
 def last_modified(self):
     ''' Return last modified time as a UTC datetime object '''
     return utcfromtimestamp(os.stat(self.dbpath).st_mtime)
Ejemplo n.º 13
0
 def last_modified(self):
     ''' Return last modified time as a UTC datetime object '''
     return utcfromtimestamp(os.stat(self.dbpath).st_mtime)