Example #1
0
def get_library_path(gui_runner):
    library_path = prefs['library_path']
    if library_path is None:  # Need to migrate to new database layout
        base = os.path.expanduser('~')
        if not base or not os.path.exists(base):
            from qt.core import QDir
            base = str(QDir.homePath()).replace('/', os.sep)
        candidate = gui_runner.choose_dir(base)
        if not candidate:
            candidate = os.path.join(base, 'Calibre Library')
        library_path = os.path.abspath(candidate)
    elif not os.path.exists(library_path):
        q = try_other_known_library_paths()
        if q:
            library_path = q
    if not os.path.exists(library_path):
        try:
            os.makedirs(library_path)
        except:
            gui_runner.show_error(
                _('Failed to create library'),
                _('Failed to create calibre library at: %r.\n'
                  'You will be asked to choose a new library location.') %
                library_path,
                det_msg=traceback.format_exc())
            library_path = gui_runner.choose_dir(get_default_library_path())
    return library_path
Example #2
0
    def set_initial_library_location(self):
        lp = prefs['library_path']
        self.default_library_name = None
        if not lp:
            fname = _('Calibre Library')
            try:
                base = os.path.expanduser('~')
            except ValueError:
                base = QDir.homePath().replace('/', os.sep)

            lp = os.path.join(base, fname)
            self.default_library_name = lp
            if not os.path.exists(lp):
                try:
                    self.makedirs(lp)
                except:
                    traceback.print_exc()
                    try:
                        lp = os.path.expanduser('~')
                    except ValueError:
                        lp = QDir.homePath().replace('/', os.sep)
        self.location.setText(lp)
        self.initial_library_location = lp