mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Port calibredb clone
This commit is contained in:
parent
f8fbcfdef3
commit
704b6b1b63
@ -4,19 +4,60 @@
|
|||||||
|
|
||||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||||
|
|
||||||
readonly = False
|
import os
|
||||||
|
|
||||||
|
from calibre import patheq
|
||||||
|
from calibre.constants import iswindows
|
||||||
|
from calibre.db.legacy import LibraryDatabase
|
||||||
|
|
||||||
|
readonly = True
|
||||||
version = 0 # change this if you change signature of implementation()
|
version = 0 # change this if you change signature of implementation()
|
||||||
|
|
||||||
|
|
||||||
def implementation(db, notify_changes, *args):
|
def implementation(db, notify_changes):
|
||||||
is_remote = notify_changes is not None
|
return db.backend.prefs.copy(), db.backend.library_path
|
||||||
is_remote
|
|
||||||
|
|
||||||
|
|
||||||
def option_parser(get_parser, args):
|
def option_parser(get_parser, args):
|
||||||
pass
|
return get_parser(
|
||||||
|
_(
|
||||||
|
'''\
|
||||||
|
%prog clone path/to/new/library
|
||||||
|
|
||||||
|
Create a clone of the current library. This creates a new, empty library that has all the
|
||||||
|
same custom columns, virtual libraries and other settings as the current library.
|
||||||
|
|
||||||
|
The cloned library will contain no books. If you want to create a full duplicate, including
|
||||||
|
all books, then simply use your filesystem tools to copy the library folder.
|
||||||
|
'''
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def main(opts, args, dbctx):
|
def main(opts, args, dbctx):
|
||||||
raise NotImplementedError('TODO: implement this')
|
if len(args) < 1:
|
||||||
|
raise SystemExit(_('Error: You must specify the path to the cloned library'))
|
||||||
|
prefs, library_path = dbctx.run('clone')
|
||||||
|
loc = os.path.abspath(args[0])
|
||||||
|
if not os.path.exists(loc):
|
||||||
|
os.makedirs(loc)
|
||||||
|
|
||||||
|
if patheq(loc, library_path):
|
||||||
|
raise SystemExit(
|
||||||
|
_('The location for the new library is the same as the current library')
|
||||||
|
)
|
||||||
|
empty = not os.listdir(loc)
|
||||||
|
if not empty:
|
||||||
|
raise SystemExit(
|
||||||
|
_(
|
||||||
|
'%s is not empty. You must choose an empty directory for the new library.'
|
||||||
|
) % loc
|
||||||
|
)
|
||||||
|
if iswindows and len(loc) > LibraryDatabase.WINDOWS_LIBRARY_PATH_LIMIT:
|
||||||
|
raise SystemExit(
|
||||||
|
_('Path to library too long. Must be less than'
|
||||||
|
' %d characters.') % LibraryDatabase.WINDOWS_LIBRARY_PATH_LIMIT
|
||||||
|
)
|
||||||
|
LibraryDatabase(loc, default_prefs=prefs)
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
@ -22,8 +22,8 @@ COMMANDS = (
|
|||||||
'list', 'add', 'remove', 'add_format', 'remove_format', 'show_metadata',
|
'list', 'add', 'remove', 'add_format', 'remove_format', 'show_metadata',
|
||||||
'set_metadata', 'export', 'catalog', 'saved_searches', 'add_custom_column',
|
'set_metadata', 'export', 'catalog', 'saved_searches', 'add_custom_column',
|
||||||
'custom_columns', 'remove_custom_column', 'set_custom', 'restore_database',
|
'custom_columns', 'remove_custom_column', 'set_custom', 'restore_database',
|
||||||
'check_library', 'list_categories', 'backup_metadata',
|
'check_library', 'list_categories', 'backup_metadata', 'clone',
|
||||||
# 'clone', 'embed_metadata', 'search'
|
# 'embed_metadata', 'search'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user