def main(opts, args, dbctx): 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
def check_action(self, ac, loc): exists = self.db.exists_at(loc) if patheq(loc, self.db.library_path): error_dialog(self, _('Same as current'), _('The location %s contains the current calibre' ' library')%loc, show=True) return False empty = not os.listdir(loc) if ac == 'existing' and not exists: error_dialog(self, _('No existing library found'), _('There is no existing calibre library at %s')%loc, show=True) return False if ac in ('new', 'move'): if not empty: error_dialog(self, _('Not empty'), _('The folder %s is not empty. Please choose an empty' ' folder')%loc, show=True) return False if (iswindows and len(loc) > LibraryDatabase2.WINDOWS_LIBRARY_PATH_LIMIT): error_dialog(self, _('Too long'), _('Path to library too long. Must be less than' ' %d characters.')%LibraryDatabase2.WINDOWS_LIBRARY_PATH_LIMIT, show=True) return False return True
def main(opts, args, dbctx): 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
def check_action(self, ac, loc): exists = self.db.exists_at(loc) base = get_portable_base() if patheq(loc, self.db.library_path): error_dialog(self, _('Same as current'), _('The location %s contains the current calibre' ' library')%loc, show=True) return False if base is not None and ac in ('new', 'move'): abase = os.path.normcase(os.path.abspath(base)) cal = os.path.normcase(os.path.abspath(os.path.join(abase, 'Calibre'))) aloc = os.path.normcase(os.path.abspath(loc)) if (aloc.startswith(cal+os.sep) or aloc == cal): error_dialog(self, _('Bad location'), _('You should not create a library inside the Calibre' ' folder as this folder is automatically deleted during upgrades.'), show=True) return False if aloc.startswith(abase) and os.path.dirname(aloc) != abase: error_dialog(self, _('Bad location'), _('You can only create libraries inside %s at the top ' 'level, not in sub-folders')%base, show=True) return False empty = not os.listdir(loc) if ac == 'existing' and not exists: error_dialog(self, _('No existing library found'), _('There is no existing calibre library at %s')%loc, show=True) return False if ac in ('new', 'move'): from calibre.db import get_db_loader LibraryDatabase = get_db_loader()[0] if not empty: error_dialog(self, _('Not empty'), _('The folder %s is not empty. Please choose an empty' ' folder')%loc, show=True) return False if (iswindows and len(loc) > LibraryDatabase.WINDOWS_LIBRARY_PATH_LIMIT): error_dialog(self, _('Too long'), _('Path to library too long. Must be less than' ' %d characters.')%LibraryDatabase.WINDOWS_LIBRARY_PATH_LIMIT, show=True) return False return True
def check_action(self, ac, loc): exists = self.db.exists_at(loc) base = get_portable_base() if patheq(loc, self.db.library_path): error_dialog(self, _('Same as current'), _('The location %s contains the current calibre' ' library')%loc, show=True) return False if base is not None and ac in ('new', 'move'): abase = os.path.normcase(os.path.abspath(base)) cal = os.path.normcase(os.path.abspath(os.path.join(abase, 'Calibre'))) aloc = os.path.normcase(os.path.abspath(loc)) if (aloc.startswith(cal+os.sep) or aloc == cal): error_dialog(self, _('Bad location'), _('You should not create a library inside the Calibre' ' folder as this folder is automatically deleted during upgrades.'), show=True) return False if aloc.startswith(abase) and os.path.dirname(aloc) != abase: error_dialog(self, _('Bad location'), _('You can only create libraries inside %s at the top ' 'level, not in sub-folders')%base, show=True) return False empty = not os.listdir(loc) if ac == 'existing' and not exists: error_dialog(self, _('No existing library found'), _('There is no existing calibre library at %s')%loc, show=True) return False if ac in ('new', 'move'): from calibre.db.legacy import LibraryDatabase if not empty: error_dialog(self, _('Not empty'), _('The folder %s is not empty. Please choose an empty' ' folder')%loc, show=True) return False if (iswindows and len(loc) > LibraryDatabase.WINDOWS_LIBRARY_PATH_LIMIT): error_dialog(self, _('Too long'), _('Path to library too long. Must be less than' ' %d characters.')%LibraryDatabase.WINDOWS_LIBRARY_PATH_LIMIT, show=True) return False return True
def commit(self, completed): oldloc = prefs['library_path'] newloc = unicode(self.location.text()) try: dln = self.default_library_name if (dln and os.path.exists(dln) and not os.listdir(dln) and newloc != dln): os.rmdir(dln) except: pass if not os.path.exists(newloc): os.mkdir(newloc) if not patheq(oldloc, newloc): move_library(oldloc, newloc, self.wizard(), completed) return True return False
def create_option_parser(args, log): if '--version' in args: from calibre.constants import __appname__, __version__, __author__ log(os.path.basename(args[0]), '('+__appname__, __version__+')') log('Created by:', __author__) raise SystemExit(0) if '--list-recipes' in args: from calibre.web.feeds.recipes.collection import get_builtin_recipe_titles log('Available recipes:') titles = sorted(get_builtin_recipe_titles()) for title in titles: try: log('\t'+title) except: log('\t'+repr(title)) log('%d recipes available'%len(titles)) raise SystemExit(0) parser = option_parser() if len(args) < 3: print_help(parser, log) if any(x in args for x in ('-h', '--help')): raise SystemExit(0) else: raise SystemExit(1) input, output = check_command_line_options(parser, args, log) from calibre.ebooks.conversion.plumber import Plumber reporter = ProgressBar(log) if patheq(input, output): raise ValueError('Input file is the same as the output file') plumber = Plumber(input, output, log, reporter) add_input_output_options(parser, plumber) add_pipeline_options(parser, plumber) return parser, plumber
def create_option_parser(args, log): if "--version" in args: from calibre.constants import __appname__, __version__, __author__ log(os.path.basename(args[0]), "(" + __appname__, __version__ + ")") log("Created by:", __author__) raise SystemExit(0) if "--list-recipes" in args: from calibre.web.feeds.recipes.collection import get_builtin_recipe_titles log("Available recipes:") titles = sorted(get_builtin_recipe_titles()) for title in titles: try: log("\t" + title) except: log("\t" + repr(title)) log("%d recipes available" % len(titles)) raise SystemExit(0) parser = option_parser() if len(args) < 3: print_help(parser, log) raise SystemExit(1) input, output = check_command_line_options(parser, args, log) from calibre.ebooks.conversion.plumber import Plumber reporter = ProgressBar(log) if patheq(input, output): raise ValueError("Input file is the same as the output file") plumber = Plumber(input, output, log, reporter) add_input_output_options(parser, plumber) add_pipeline_options(parser, plumber) return parser, plumber
def check_action(self, ac, loc): exists = self.db.exists_at(loc) base = get_portable_base() if patheq(loc, self.db.library_path): error_dialog( self, _("Same as current"), _("The location %s contains the current calibre" " library") % loc, show=True, ) return False if base is not None and ac in ("new", "move"): abase = os.path.normcase(os.path.abspath(base)) cal = os.path.normcase(os.path.abspath(os.path.join(abase, "Calibre"))) aloc = os.path.normcase(os.path.abspath(loc)) if aloc.startswith(cal + os.sep) or aloc == cal: error_dialog( self, _("Bad location"), _( "You should not create a library inside the Calibre" " folder as this folder is automatically deleted during upgrades." ), show=True, ) return False if aloc.startswith(abase) and os.path.dirname(aloc) != abase: error_dialog( self, _("Bad location"), _("You can only create libraries inside %s at the top " "level, not in sub-folders") % base, show=True, ) return False empty = not os.listdir(loc) if ac == "existing" and not exists: error_dialog( self, _("No existing library found"), _("There is no existing calibre library at %s") % loc, show=True ) return False if ac in ("new", "move"): from calibre.db.legacy import LibraryDatabase if not empty: error_dialog( self, _("Not empty"), _("The folder %s is not empty. Please choose an empty" " folder") % loc, show=True, ) return False if iswindows and len(loc) > LibraryDatabase.WINDOWS_LIBRARY_PATH_LIMIT: error_dialog( self, _("Too long"), _("Path to library too long. Must be less than" " %d characters.") % LibraryDatabase.WINDOWS_LIBRARY_PATH_LIMIT, show=True, ) return False return True