예제 #1
0
파일: main.py 프로젝트: shamray/calibre
    def initialize_db(self):
        from calibre.db import get_db_loader
        db = None
        self.db_class, errs = get_db_loader()
        try:
            db = self.db_class(self.library_path)
        except errs:
            repair = question_dialog(self.splash_screen, _('Corrupted database'),
                    _('The library database at %s appears to be corrupted. Do '
                    'you want calibre to try and rebuild it automatically? '
                    'The rebuild may not be completely successful. '
                    'If you say No, a new empty calibre library will be created.')
                    % force_unicode(self.library_path, filesystem_encoding),
                    det_msg=traceback.format_exc()
                    )
            if repair:
                if repair_library(self.library_path):
                    db = self.db_class(self.library_path)
        except:
            error_dialog(self.splash_screen, _('Bad database location'),
                    _('Bad database location %r. Will start with '
                    ' a new, empty calibre library')%self.library_path,
                    det_msg=traceback.format_exc(), show=True)

        self.initialize_db_stage2(db, None)
예제 #2
0
파일: main.py 프로젝트: Pipeliner/calibre
    def initialize_db(self):
        from calibre.db import get_db_loader
        db = None
        self.db_class, errs = get_db_loader()
        try:
            db = self.db_class(self.library_path)
        except errs:
            repair = question_dialog(self.splash_screen, _('Corrupted database'),
                    _('The library database at %s appears to be corrupted. Do '
                    'you want calibre to try and rebuild it automatically? '
                    'The rebuild may not be completely successful. '
                    'If you say No, a new empty calibre library will be created.')
                    % force_unicode(self.library_path, filesystem_encoding),
                    det_msg=traceback.format_exc()
                    )
            if repair:
                if repair_library(self.library_path):
                    db = self.db_class(self.library_path)
        except:
            error_dialog(self.splash_screen, _('Bad database location'),
                    _('Bad database location %r. Will start with '
                    ' a new, empty calibre library')%self.library_path,
                    det_msg=traceback.format_exc(), show=True)

        self.initialize_db_stage2(db, None)
예제 #3
0
 def doit(self):
     from calibre.db import get_db_loader
     newdb = get_db_loader()[0](self.loc, is_second_db=True)
     with closing(newdb):
         self._doit(newdb)
     newdb.break_cycles()
     del newdb
예제 #4
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
예제 #5
0
파일: main.py 프로젝트: Pipeliner/calibre
def main(args=sys.argv):
    from calibre.db import get_db_loader
    parser = option_parser()
    opts, args = parser.parse_args(args)
    if opts.daemonize and not iswindows:
        daemonize()
    if opts.pidfile is not None:
        from cherrypy.process.plugins import PIDFile
        PIDFile(cherrypy.engine, opts.pidfile).subscribe()
    cherrypy.log.screen = True
    from calibre.utils.config import prefs
    if opts.with_library is None:
        opts.with_library = prefs['library_path']
    if not opts.with_library:
        print('No saved library path. Use the --with-library option'
                ' to specify the path to the library you want to use.')
        return 1
    db = get_db_loader()[0](opts.with_library)
    server = LibraryServer(db, opts, show_tracebacks=opts.develop)
    server.start()
    return 0
예제 #6
0
def main(args=sys.argv):
    from calibre.db import get_db_loader
    parser = option_parser()
    opts, args = parser.parse_args(args)
    if opts.daemonize and not iswindows:
        daemonize()
    if opts.pidfile is not None:
        from cherrypy.process.plugins import PIDFile
        PIDFile(cherrypy.engine, opts.pidfile).subscribe()
    cherrypy.log.screen = True
    from calibre.utils.config import prefs
    if opts.with_library is None:
        opts.with_library = prefs['library_path']
    if not opts.with_library:
        print('No saved library path. Use the --with-library option'
              ' to specify the path to the library you want to use.')
        return 1
    db = get_db_loader()[0](opts.with_library)
    server = LibraryServer(db, opts, show_tracebacks=opts.develop)
    server.start()
    return 0
예제 #7
0
def db_class():
    from calibre.db import get_db_loader
    return get_db_loader()[0]
예제 #8
0
파일: __init__.py 프로젝트: shamray/calibre
def db(path=None, read_only=False):
    from calibre.db import get_db_loader
    from calibre.utils.config import prefs
    return get_db_loader()[0](path if path else prefs['library_path'],
            read_only=read_only)
예제 #9
0
def db_class():
    from calibre.db import get_db_loader
    return get_db_loader()[0]
예제 #10
0
파일: ui.py 프로젝트: Pipeliner/calibre
    def library_moved(self, newloc, copy_structure=False, call_close=True,
            allow_rebuild=False):
        if newloc is None:
            return
        default_prefs = None
        try:
            olddb = self.library_view.model().db
            if copy_structure:
                default_prefs = olddb.prefs

            from calibre.utils.formatter_functions import unload_user_template_functions
            unload_user_template_functions(olddb.library_id)
        except:
            olddb = None
        db_class, errs = get_db_loader()
        try:
            db = db_class(newloc, default_prefs=default_prefs)
        except errs:
            if not allow_rebuild:
                raise
            import traceback
            repair = question_dialog(self, _('Corrupted database'),
                    _('The library database at %s appears to be corrupted. Do '
                    'you want calibre to try and rebuild it automatically? '
                    'The rebuild may not be completely successful.')
                    % force_unicode(newloc, filesystem_encoding),
                    det_msg=traceback.format_exc()
                    )
            if repair:
                from calibre.gui2.dialogs.restore_library import repair_library_at
                if repair_library_at(newloc, parent=self):
                    db = db_class(newloc, default_prefs=default_prefs)
                else:
                    return
            else:
                return
        if self.content_server is not None:
            self.content_server.set_database(db)
        self.library_path = newloc
        prefs['library_path'] = self.library_path
        self.book_on_device(None, reset=True)
        db.set_book_on_device_func(self.book_on_device)
        self.library_view.set_database(db)
        self.tags_view.set_database(db, self.alter_tb)
        self.library_view.model().set_book_on_device_func(self.book_on_device)
        self.status_bar.clear_message()
        self.search.clear()
        self.saved_search.clear()
        self.book_details.reset_info()
        #self.library_view.model().count_changed()
        db = self.library_view.model().db
        self.iactions['Choose Library'].count_changed(db.count())
        self.set_window_title()
        self.apply_named_search_restriction('')  # reset restriction to null
        self.saved_searches_changed(recount=False)  # reload the search restrictions combo box
        if db.prefs['virtual_lib_on_startup']:
            self.apply_virtual_library(db.prefs['virtual_lib_on_startup'])
        for action in self.iactions.values():
            action.library_changed(db)
        if olddb is not None:
            try:
                if call_close:
                    olddb.close()
            except:
                import traceback
                traceback.print_exc()
            olddb.break_cycles()
        if self.device_connected:
            self.set_books_in_library(self.booklists(), reset=True)
            self.refresh_ondevice()
            self.memory_view.reset()
            self.card_a_view.reset()
            self.card_b_view.reset()
        self.device_manager.set_current_library_uuid(db.library_id)
        self.library_view.set_current_row(0)
        # Run a garbage collection now so that it does not freeze the
        # interface later
        gc.collect()
예제 #11
0
파일: ui.py 프로젝트: shamray/calibre
    def library_moved(self,
                      newloc,
                      copy_structure=False,
                      call_close=True,
                      allow_rebuild=False):
        if newloc is None:
            return
        default_prefs = None
        try:
            olddb = self.library_view.model().db
            if copy_structure:
                default_prefs = olddb.prefs

            from calibre.utils.formatter_functions import unload_user_template_functions
            unload_user_template_functions(olddb.library_id)
        except:
            olddb = None
        db_class, errs = get_db_loader()
        try:
            db = db_class(newloc, default_prefs=default_prefs)
        except errs:
            if not allow_rebuild:
                raise
            import traceback
            repair = question_dialog(
                self,
                _('Corrupted database'),
                _('The library database at %s appears to be corrupted. Do '
                  'you want calibre to try and rebuild it automatically? '
                  'The rebuild may not be completely successful.') %
                force_unicode(newloc, filesystem_encoding),
                det_msg=traceback.format_exc())
            if repair:
                from calibre.gui2.dialogs.restore_library import repair_library_at
                if repair_library_at(newloc, parent=self):
                    db = db_class(newloc, default_prefs=default_prefs)
                else:
                    return
            else:
                return
        if self.content_server is not None:
            self.content_server.set_database(db)
        self.library_path = newloc
        prefs['library_path'] = self.library_path
        self.book_on_device(None, reset=True)
        db.set_book_on_device_func(self.book_on_device)
        self.library_view.set_database(db)
        self.tags_view.set_database(db, self.alter_tb)
        self.library_view.model().set_book_on_device_func(self.book_on_device)
        self.status_bar.clear_message()
        self.search.clear()
        self.saved_search.clear()
        self.book_details.reset_info()
        #self.library_view.model().count_changed()
        db = self.library_view.model().db
        self.iactions['Choose Library'].count_changed(db.count())
        self.set_window_title()
        self.apply_named_search_restriction('')  # reset restriction to null
        self.saved_searches_changed(
            recount=False)  # reload the search restrictions combo box
        if db.prefs['virtual_lib_on_startup']:
            self.apply_virtual_library(db.prefs['virtual_lib_on_startup'])
        self.rebuild_vl_tabs()
        for action in self.iactions.values():
            action.library_changed(db)
        if olddb is not None:
            try:
                if call_close:
                    olddb.close()
            except:
                import traceback
                traceback.print_exc()
            olddb.break_cycles()
        if self.device_connected:
            self.set_books_in_library(self.booklists(), reset=True)
            self.refresh_ondevice()
            self.memory_view.reset()
            self.card_a_view.reset()
            self.card_b_view.reset()
        self.device_manager.set_current_library_uuid(db.library_id)
        self.library_view.set_current_row(0)
        # Run a garbage collection now so that it does not freeze the
        # interface later
        gc.collect()
예제 #12
0
파일: move.py 프로젝트: Pipeliner/calibre
def move_library(from_, to, notification=lambda x:x):
    from calibre.db import get_db_loader
    time.sleep(1)
    old = get_db_loader()[0](from_)
    old.move_library_to(to, notification)
    return True
예제 #13
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
예제 #14
0
파일: move.py 프로젝트: shamray/calibre
def move_library(from_, to, notification=lambda x: x):
    from calibre.db import get_db_loader
    time.sleep(1)
    old = get_db_loader()[0](from_)
    old.move_library_to(to, notification)
    return True