mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
IGN:Add --migrate option to calibre-debug
This commit is contained in:
parent
7fefb01f35
commit
817feebbc8
@ -21,6 +21,8 @@ Run an embedded python interpreter.
|
|||||||
'Module specifications are of the form full.name.of.module,path_to_module.py', default=None
|
'Module specifications are of the form full.name.of.module,path_to_module.py', default=None
|
||||||
)
|
)
|
||||||
parser.add_option('-c', '--command', help='Run python code.', default=None)
|
parser.add_option('-c', '--command', help='Run python code.', default=None)
|
||||||
|
parser.add_option('--migrate', action='store_true', default=False,
|
||||||
|
help='Migrate old database. Needs two arguments. Path to library1.db and path to new library folder.', default=False)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def update_zipfile(zipfile, mod, path):
|
def update_zipfile(zipfile, mod, path):
|
||||||
@ -45,6 +47,29 @@ def update_module(mod, path):
|
|||||||
else:
|
else:
|
||||||
raise ValueError('Updating modules is not supported on this platform.')
|
raise ValueError('Updating modules is not supported on this platform.')
|
||||||
|
|
||||||
|
def migrate(old, new):
|
||||||
|
from calibre.utils.config import prefs
|
||||||
|
from calibre.library.database import LibraryDatabase
|
||||||
|
from calibre.library.database2 import LibraryDatabase2
|
||||||
|
from calibre.utils.terminfo import ProgressBar
|
||||||
|
from calibre import terminal_controller
|
||||||
|
class Dummy(ProgressBar):
|
||||||
|
def setLabelText(self, x): pass
|
||||||
|
def setAutoReset(self, y): pass
|
||||||
|
def reset(self): pass
|
||||||
|
def setRange(self, min, max):
|
||||||
|
self.min = min
|
||||||
|
self.max = max
|
||||||
|
def setValue(self, val):
|
||||||
|
self.update(float(val)/getattr(self, 'max', 1))
|
||||||
|
|
||||||
|
db = LibraryDatabase(old)
|
||||||
|
db2 = LibraryDatabase2(new)
|
||||||
|
db2.migrate_old(db, Dummy(terminal_controller, 'Migrating database...'))
|
||||||
|
prefs['library_path'] = os.path.abspath(new)
|
||||||
|
print 'Database migrated to', os.path.abspath(new)
|
||||||
|
|
||||||
|
|
||||||
def main(args=sys.argv):
|
def main(args=sys.argv):
|
||||||
opts, args = option_parser().parse_args(args)
|
opts, args = option_parser().parse_args(args)
|
||||||
if opts.update_module:
|
if opts.update_module:
|
||||||
@ -53,6 +78,11 @@ def main(args=sys.argv):
|
|||||||
elif opts.command:
|
elif opts.command:
|
||||||
sys.argv = args[:1]
|
sys.argv = args[:1]
|
||||||
exec opts.command
|
exec opts.command
|
||||||
|
elif opts.migrate:
|
||||||
|
if len(args) < 3:
|
||||||
|
print 'You must specify the path to library1.db and the path to the new library folder'
|
||||||
|
return 1
|
||||||
|
migrate(args[1], args[2])
|
||||||
else:
|
else:
|
||||||
from IPython.Shell import IPShellEmbed
|
from IPython.Shell import IPShellEmbed
|
||||||
ipshell = IPShellEmbed()
|
ipshell = IPShellEmbed()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user