diff --git a/src/calibre/library/cli.py b/src/calibre/library/cli.py index 1d81ac2bd6..7f181edc38 100644 --- a/src/calibre/library/cli.py +++ b/src/calibre/library/cli.py @@ -10,7 +10,8 @@ Command line interface to the calibre database. import sys, os, cStringIO, re from textwrap import TextWrapper -from calibre import terminal_controller, preferred_encoding, prints +from calibre import terminal_controller, preferred_encoding, prints, \ + isbytestring from calibre.utils.config import OptionParser, prefs, tweaks from calibre.ebooks.metadata.meta import get_metadata from calibre.library.database2 import LibraryDatabase2 @@ -901,6 +902,12 @@ def command_restore_database(args, dbpath): parser.print_help() return 1 + if opts.library_path is not None: + dbpath = opts.library_path + + if isbytestring(dbpath): + dbpath = dbpath.decode(preferred_encoding) + class Progress(object): def __init__(self): self.total = 1 @@ -918,6 +925,7 @@ def command_restore_database(args, dbpath): prints(r.tb) else: prints('Restoring database succeeded') + prints('old database saved as', r.olddb) if r.errors_occurred: name = 'calibre_db_restore_report.txt' open('calibre_db_restore_report.txt', diff --git a/src/calibre/library/restore.py b/src/calibre/library/restore.py index 0381366810..63cd152ae9 100644 --- a/src/calibre/library/restore.py +++ b/src/calibre/library/restore.py @@ -61,7 +61,7 @@ class Restore(Thread): self.failed_restores] if failures: ans += 'Failed to restore the books in the following folders:\n' - wrap = TextWrapper(initial_indent='\t\t', width=85) + wrap = TextWrapper(initial_indent='\t\t', width=1085) for dirpath, tb in failures: ans += '\t' + dirpath + ' with error:\n' ans += wrap.fill(tb) @@ -103,7 +103,7 @@ class Restore(Thread): self.process_dir(dirpath, filenames, book_id) except: self.failed_dirs.append((dirpath, traceback.format_exc())) - self.progress_callback(_('Processed') + repr(dirpath), i+1) + self.progress_callback(_('Processed') + ' ' + dirpath, i+1) def is_ebook_file(self, filename): ext = os.path.splitext(filename)[1] @@ -183,14 +183,14 @@ class Restore(Thread): for fmt, size, name in book['formats']: db.conn.execute(''' INSERT INTO data (book,format,uncompressed_size,name) - VALUES (?,?,?,?)''', (id, fmt, size, name)) + VALUES (?,?,?,?)''', (book['id'], fmt, size, name)) db.conn.commit() def replace_db(self): dbpath = os.path.join(self.src_library_path, 'metadata.db') ndbpath = os.path.join(self.library_path, 'metadata.db') - save_path = os.path.splitext(dbpath)[0]+'_pre_restore.db' + save_path = self.olddb = os.path.splitext(dbpath)[0]+'_pre_restore.db' if os.path.exists(save_path): os.remove(save_path) os.rename(dbpath, save_path)