Exemplo n.º 1
0
def find_portable_library():
    base = get_portable_base()
    if base is None:
        return
    import glob
    candidates = [os.path.basename(os.path.dirname(x)) for x in glob.glob(
        os.path.join(base, u'*%smetadata.db'%os.sep))]
    if not candidates:
        candidates = [u'Calibre Library']
    lp = prefs['library_path']
    if not lp:
        lib = os.path.join(base, candidates[0])
    else:
        lib = None
        q = os.path.basename(lp)
        for c in candidates:
            c = c
            if c.lower() == q.lower():
                lib = os.path.join(base, c)
                break
        if lib is None:
            lib = os.path.join(base, candidates[0])

    if len(lib) > 74:
        error_dialog(None, _('Path too long'),
            _("Path to Calibre Portable (%s) "
                'too long. Must be less than 59 characters.')%base, show=True)
        raise AbortInit()

    prefs.set('library_path', lib)
    if not os.path.exists(lib):
        os.mkdir(lib)
Exemplo n.º 2
0
def find_portable_library():
    base = get_portable_base()
    if base is None:
        return
    import glob
    candidates = [os.path.basename(os.path.dirname(x)) for x in glob.glob(
        os.path.join(base, u'*%smetadata.db'%os.sep))]
    if not candidates:
        candidates = [u'Calibre Library']
    lp = prefs['library_path']
    if not lp:
        lib = os.path.join(base, candidates[0])
    else:
        lib = None
        q = os.path.basename(lp)
        for c in candidates:
            c = c
            if c.lower() == q.lower():
                lib = os.path.join(base, c)
                break
        if lib is None:
            lib = os.path.join(base, candidates[0])

    if len(lib) > 74:
        error_dialog(None, _('Path too long'),
            _("Path to Calibre Portable (%s) "
                'too long. Must be less than 59 characters.')%base, show=True)
        raise AbortInit()

    prefs.set('library_path', lib)
    if not os.path.exists(lib):
        os.mkdir(lib)
Exemplo n.º 3
0
 def choose_loc(self, *args):
     base = get_portable_base()
     if base is None:
         loc = choose_dir(self, "choose library location", _("Choose location for calibre library"))
     else:
         name = force_unicode("choose library loc at" + base, filesystem_encoding)
         loc = choose_dir(self, name, _("Choose location for calibre library"), default_dir=base, no_save_dir=True)
     if loc is not None:
         self.location.setText(loc)
Exemplo n.º 4
0
 def look_for_portable_lib(self, db, location):
     base = get_portable_base()
     if base is None:
         return False, None
     loc = location.replace('/', os.sep)
     candidate = os.path.join(base, os.path.basename(loc))
     if db.exists_at(candidate):
         newloc = candidate.replace(os.sep, '/')
         self.stats.rename(location, newloc)
         return True, newloc
     return False, None
Exemplo n.º 5
0
 def look_for_portable_lib(self, db, location):
     base = get_portable_base()
     if base is None:
         return False, None
     loc = location.replace('/', os.sep)
     candidate = os.path.join(base, os.path.basename(loc))
     if db.exists_at(candidate):
         newloc = candidate.replace(os.sep, '/')
         self.stats.rename(location, newloc)
         return True, newloc
     return False, None
Exemplo n.º 6
0
 def choose_loc(self, *args):
     base = get_portable_base()
     if base is None:
         loc = choose_dir(self, 'choose library location',
                 _('Choose location for calibre library'))
     else:
         name = force_unicode('choose library loc at' + base,
                 filesystem_encoding)
         loc = choose_dir(self, name,
                 _('Choose location for calibre library'), default_dir=base,
                 no_save_dir=True)
     if loc is not None:
         self.location.setText(loc)
Exemplo n.º 7
0
 def __init__(self):
     self.stats = {}
     self.read_stats()
     base = get_portable_base()
     if base is not None:
         lp = prefs['library_path']
         if lp:
             # Rename the current library. Renaming of other libraries is
             # handled by the switch function
             q = os.path.basename(lp)
             for loc in list(self.stats):
                 bn = posixpath.basename(loc)
                 if bn.lower() == q.lower():
                     self.rename(loc, lp)
Exemplo n.º 8
0
 def __init__(self):
     self.stats = {}
     self.read_stats()
     base = get_portable_base()
     if base is not None:
         lp = prefs['library_path']
         if lp:
             # Rename the current library. Renaming of other libraries is
             # handled by the switch function
             q = os.path.basename(lp)
             for loc in list(self.stats.iterkeys()):
                 bn = posixpath.basename(loc)
                 if bn.lower() == q.lower():
                     self.rename(loc, lp)
Exemplo n.º 9
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
Exemplo n.º 10
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.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
Exemplo n.º 11
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.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