forked from janeczku/calibre-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'cover_images/thumbnails' into cover_thu…
…mbnail # Conflicts: # cps/admin.py # cps/config_sql.py # cps/helper.py # cps/tasks/upload.py # cps/updater.py # cps/web.py
- Loading branch information
Showing
39 changed files
with
1,673 additions
and
5,077 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ vendor/ | |
# calibre-web | ||
*.db | ||
*.log | ||
cps/cache | ||
|
||
.idea/ | ||
*.bak | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# This file is part of the Calibre-Web (https://github.com/janeczku/calibre-web) | ||
# Copyright (C) 2020 mmonkey | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
from __future__ import division, print_function, unicode_literals | ||
from . import logger | ||
from .constants import CACHE_DIR | ||
from os import makedirs, remove | ||
from os.path import isdir, isfile, join | ||
from shutil import rmtree | ||
|
||
|
||
class FileSystem: | ||
_instance = None | ||
_cache_dir = CACHE_DIR | ||
|
||
def __new__(cls): | ||
if cls._instance is None: | ||
cls._instance = super(FileSystem, cls).__new__(cls) | ||
cls.log = logger.create() | ||
return cls._instance | ||
|
||
def get_cache_dir(self, cache_type=None): | ||
if not isdir(self._cache_dir): | ||
try: | ||
makedirs(self._cache_dir) | ||
except OSError: | ||
self.log.info(f'Failed to create path {self._cache_dir} (Permission denied).') | ||
return False | ||
|
||
path = join(self._cache_dir, cache_type) | ||
if cache_type and not isdir(path): | ||
try: | ||
makedirs(path) | ||
except OSError: | ||
self.log.info(f'Failed to create path {path} (Permission denied).') | ||
return False | ||
|
||
return path if cache_type else self._cache_dir | ||
|
||
def get_cache_file_dir(self, filename, cache_type=None): | ||
path = join(self.get_cache_dir(cache_type), filename[:2]) | ||
if not isdir(path): | ||
try: | ||
makedirs(path) | ||
except OSError: | ||
self.log.info(f'Failed to create path {path} (Permission denied).') | ||
return False | ||
|
||
return path | ||
|
||
def get_cache_file_path(self, filename, cache_type=None): | ||
return join(self.get_cache_file_dir(filename, cache_type), filename) if filename else None | ||
|
||
def get_cache_file_exists(self, filename, cache_type=None): | ||
path = self.get_cache_file_path(filename, cache_type) | ||
return isfile(path) | ||
|
||
def delete_cache_dir(self, cache_type=None): | ||
if not cache_type and isdir(self._cache_dir): | ||
try: | ||
rmtree(self._cache_dir) | ||
except OSError: | ||
self.log.info(f'Failed to delete path {self._cache_dir} (Permission denied).') | ||
return False | ||
|
||
path = join(self._cache_dir, cache_type) | ||
if cache_type and isdir(path): | ||
try: | ||
rmtree(path) | ||
except OSError: | ||
self.log.info(f'Failed to delete path {path} (Permission denied).') | ||
return False | ||
|
||
def delete_cache_file(self, filename, cache_type=None): | ||
path = self.get_cache_file_path(filename, cache_type) | ||
if isfile(path): | ||
try: | ||
remove(path) | ||
except OSError: | ||
self.log.info(f'Failed to delete path {path} (Permission denied).') | ||
return False |
Oops, something went wrong.