Browse Source

Merge branch 'feature/ChangeFuncName' into develop

develop
JackDandy 4 years ago
parent
commit
fc12b120b5
  1. 542
      lib/sg_helpers.py
  2. 4
      lib/tvinfo_base/base.py
  3. 2
      sickbeard/__init__.py
  4. 4
      sickbeard/anime.py
  5. 4
      sickbeard/db.py
  6. 4
      sickbeard/helpers.py
  7. 2
      sickbeard/image_cache.py
  8. 2
      sickbeard/indexers/indexer_api.py
  9. 2
      sickbeard/postProcessor.py
  10. 2
      sickbeard/scene_exceptions.py
  11. 6
      sickbeard/webserve.py

542
lib/sg_helpers.py

@ -24,8 +24,8 @@ import traceback
from exceptions_helper import ex, ConnectionSkipException from exceptions_helper import ex, ConnectionSkipException
from lib.cachecontrol import CacheControl, caches from lib.cachecontrol import CacheControl, caches
from lib.tmdbsimple.configuration import Configuration # from lib.tmdbsimple.configuration import Configuration
from lib.tmdbsimple.genres import Genres # from lib.tmdbsimple.genres import Genres
from cfscrape import CloudflareScraper from cfscrape import CloudflareScraper
from send2trash import send2trash from send2trash import send2trash
@ -1043,107 +1043,63 @@ def save_failure(url, domain, log_failure_url, post_data, post_json):
_log_failure_url(url, post_data, post_json) _log_failure_url(url, post_data, post_json)
def file_bit_filter(mode): def scantree(path, # type: AnyStr
for bit in [stat.S_IXUSR, stat.S_IXGRP, stat.S_IXOTH, stat.S_ISUID, stat.S_ISGID]: exclude=None, # type: Optional[AnyStr, List[AnyStr]]
if mode & bit: include=None, # type: Optional[AnyStr, List[AnyStr]]
mode -= bit follow_symlinks=False, # type: bool
filter_kind=None, # type: Optional[bool]
return mode recurse=True # type: bool
):
# type: (...) -> Generator[DirEntry, None, None]
def chmod_as_parent(child_path): """Yield DirEntry objects for given path. Returns without yield if path fails sanity check
"""
:param child_path: path :param path: Path to scan, sanity check is_dir and exists
:type child_path: AnyStr :param exclude: Escaped regex string(s) to exclude
:return: :param include: Escaped regex string(s) to include
:rtype: None :param follow_symlinks: Follow symlinks
:param filter_kind: None to yield everything, True yields directories, False yields files
:param recurse: Recursively scan the tree
""" """
if os.name in ('nt', 'ce'): if isinstance(path, string_types) and path and ek.ek(os.path.isdir, path):
return rc_exc, rc_inc = [re.compile(rx % '|'.join(
[x for x in (param, ([param], [])[None is param])[not isinstance(param, list)]]))
parent_path = ek.ek(os.path.dirname, child_path) for rx, param in ((r'(?i)^(?:(?!%s).)*$', exclude), (r'(?i)%s', include))]
for entry in ek.ek(scandir, path):
if not parent_path: is_dir = entry.is_dir(follow_symlinks=follow_symlinks)
logger.debug(u'No parent path provided in %s, unable to get permissions from it' % child_path) is_file = entry.is_file(follow_symlinks=follow_symlinks)
return no_filter = any([None is filter_kind, filter_kind and is_dir, not filter_kind and is_file])
if (rc_exc.search(entry.name), True)[not exclude] and (rc_inc.search(entry.name), True)[not include] \
parent_path_stat = ek.ek(os.stat, parent_path) and (no_filter or (not filter_kind and is_dir and recurse)):
parent_mode = stat.S_IMODE(parent_path_stat[stat.ST_MODE]) if recurse and is_dir:
for subentry in scantree(entry.path, exclude, include, follow_symlinks, filter_kind, recurse):
yield subentry
if no_filter:
yield entry
child_path_stat = ek.ek(os.stat, child_path)
child_path_mode = stat.S_IMODE(child_path_stat[stat.ST_MODE])
if ek.ek(os.path.isfile, child_path): def copy_file(src_file, dest_file):
child_mode = file_bit_filter(parent_mode) if os.name.startswith('posix'):
ek.ek(subprocess.call, ['cp', src_file, dest_file])
else: else:
child_mode = parent_mode ek.ek(shutil.copyfile, src_file, dest_file)
if child_path_mode == child_mode:
return
child_path_owner = child_path_stat.st_uid
user_id = os.geteuid() # only available on UNIX
if 0 != user_id and user_id != child_path_owner:
logger.debug(u'Not running as root or owner of %s, not trying to set permissions' % child_path)
return
try: try:
ek.ek(os.chmod, child_path, child_mode) ek.ek(shutil.copymode, src_file, dest_file)
logger.debug(u'Setting permissions for %s to %o as parent directory has %o'
% (child_path, child_mode, parent_mode))
except OSError: except OSError:
logger.error(u'Failed to set permission for %s to %o' % (child_path, child_mode)) pass
def make_dirs(path, syno=False):
"""
Creates any folders that are missing and assigns them the permissions of their
parents
:param path: path
:type path: AnyStr
:param syno: whether to trigger a syno library update for path
:type syno: bool
:return: success
:rtype: bool
"""
if not ek.ek(os.path.isdir, path):
# Windows, create all missing folders
if os.name in ('nt', 'ce'):
try:
logger.debug(u'Path %s doesn\'t exist, creating it' % path)
ek.ek(os.makedirs, path)
except (OSError, IOError) as e:
logger.error(u'Failed creating %s : %s' % (path, ex(e)))
return False
# not Windows, create all missing folders and set permissions
else:
sofar = ''
folder_list = path.split(os.path.sep)
# look through each sub folder and make sure they all exist
for cur_folder in folder_list:
sofar += cur_folder + os.path.sep
# if it exists then just keep walking down the line
if ek.ek(os.path.isdir, sofar):
continue
try:
logger.debug(u'Path %s doesn\'t exist, creating it' % sofar)
ek.ek(os.mkdir, sofar)
# use normpath to remove end separator, otherwise checks permissions against itself
chmod_as_parent(ek.ek(os.path.normpath, sofar))
if syno:
# do the library update for synoindex
NOTIFIERS.NotifierFactory().get('SYNOINDEX').addFolder(sofar)
except (OSError, IOError) as e:
logger.error(u'Failed creating %s : %s' % (sofar, ex(e)))
return False
return True def move_file(src_file, dest_file, raise_exceptions=False):
try:
ek.ek(shutil.move, src_file, dest_file)
fix_set_group_id(dest_file)
except OSError:
copy_file(src_file, dest_file)
if ek.ek(os.path.exists, dest_file):
fix_set_group_id(dest_file)
ek.ek(os.unlink, src_file)
elif raise_exceptions:
raise OSError('Destination file could not be created: %s' % dest_file)
def fix_set_group_id(child_path): def fix_set_group_id(child_path):
@ -1184,31 +1140,6 @@ def fix_set_group_id(child_path):
% (child_path, parent_gid)) % (child_path, parent_gid))
def copy_file(src_file, dest_file):
if os.name.startswith('posix'):
ek.ek(subprocess.call, ['cp', src_file, dest_file])
else:
ek.ek(shutil.copyfile, src_file, dest_file)
try:
ek.ek(shutil.copymode, src_file, dest_file)
except OSError:
pass
def move_file(src_file, dest_file, raise_exceptions=False):
try:
ek.ek(shutil.move, src_file, dest_file)
fix_set_group_id(dest_file)
except OSError:
copy_file(src_file, dest_file)
if ek.ek(os.path.exists, dest_file):
fix_set_group_id(dest_file)
ek.ek(os.unlink, src_file)
elif raise_exceptions:
raise OSError('Destination file could not be created: %s' % dest_file)
def remove_file_perm(filepath, log_err=True): def remove_file_perm(filepath, log_err=True):
# type: (AnyStr, Optional[bool]) -> Optional[bool] # type: (AnyStr, Optional[bool]) -> Optional[bool]
""" """
@ -1277,20 +1208,136 @@ def remove_file(filepath, tree=False, prefix_failure='', log_level=logging.INFO)
return (None, result)[filepath and not ek.ek(os.path.exists, filepath)] return (None, result)[filepath and not ek.ek(os.path.exists, filepath)]
def replace_extension(filename, new_ext): def touch_file(name, atime=None, dir_name=None):
# type: (AnyStr, int, AnyStr) -> bool
""" """
create an empty named file and set access time of file
:param filename: filename :param name: filename to touch with time
:type filename: AnyStr :param atime: access time as epoch
:param new_ext: new extension :param dir_name: create empty file and directory if file doesn't exist
:type new_ext: AnyStr :return: success
:return: filename with new extension
:rtype: AnyStr
""" """
sepFile = filename.rpartition('.') if None is not dir_name:
if sepFile[0] == '': name = ek.ek(os.path.join, dir_name, name)
return filename if make_path(dir_name):
return sepFile[0] + '.' + new_ext if not ek.ek(os.path.exists, name):
with io.open(name, 'w') as fh:
fh.flush()
if None is atime:
return True
if None is not atime:
try:
with open(name, 'a'):
ek.ek(os.utime, name, (atime, atime))
return True
except (BaseException, Exception):
logger.debug('File air date stamping not available on your OS')
return False
def make_path(name, syno=False):
# type: (AnyStr, bool) -> bool
"""
Create an entire directory path and
assign each subdir the parent permission
:param name: directory to create
:param syno: whether to trigger a syno library update for path
:return: success or dir exists
"""
if not ek.ek(os.path.isdir, name):
# Windows, create all missing folders
if os.name in ('nt', 'ce'):
try:
logger.debug(u'Path %s doesn\'t exist, creating it' % name)
ek.ek(os.makedirs, name)
except (OSError, IOError) as e:
logger.error(u'Failed creating %s : %s' % (name, ex(e)))
return False
# not Windows, create all missing folders and set permissions
else:
sofar = ''
folder_list = name.split(os.path.sep)
# look through each sub folder and make sure they all exist
for cur_folder in folder_list:
sofar += cur_folder + os.path.sep
# if it exists then just keep walking down the line
if ek.ek(os.path.isdir, sofar):
continue
try:
logger.debug(u'Path %s doesn\'t exist, creating it' % sofar)
ek.ek(os.mkdir, sofar)
# use normpath to remove end separator, otherwise checks permissions against itself
chmod_as_parent(ek.ek(os.path.normpath, sofar))
if syno:
# do the library update for synoindex
NOTIFIERS.NotifierFactory().get('SYNOINDEX').addFolder(sofar)
except (OSError, IOError) as e:
logger.error(u'Failed creating %s : %s' % (sofar, ex(e)))
return False
return True
def chmod_as_parent(child_path):
"""
:param child_path: path
:type child_path: AnyStr
:return:
:rtype: None
"""
if os.name in ('nt', 'ce'):
return
parent_path = ek.ek(os.path.dirname, child_path)
if not parent_path:
logger.debug(u'No parent path provided in %s, unable to get permissions from it' % child_path)
return
parent_path_stat = ek.ek(os.stat, parent_path)
parent_mode = stat.S_IMODE(parent_path_stat[stat.ST_MODE])
child_path_stat = ek.ek(os.stat, child_path)
child_path_mode = stat.S_IMODE(child_path_stat[stat.ST_MODE])
if ek.ek(os.path.isfile, child_path):
child_mode = file_bit_filter(parent_mode)
else:
child_mode = parent_mode
if child_path_mode == child_mode:
return
child_path_owner = child_path_stat.st_uid
user_id = os.geteuid() # only available on UNIX
if 0 != user_id and user_id != child_path_owner:
logger.debug(u'Not running as root or owner of %s, not trying to set permissions' % child_path)
return
try:
ek.ek(os.chmod, child_path, child_mode)
logger.debug(u'Setting permissions for %s to %o as parent directory has %o'
% (child_path, child_mode, parent_mode))
except OSError:
logger.error(u'Failed to set permission for %s to %o' % (child_path, child_mode))
def file_bit_filter(mode):
for bit in [stat.S_IXUSR, stat.S_IXGRP, stat.S_IXOTH, stat.S_ISUID, stat.S_ISGID]:
if mode & bit:
mode -= bit
return mode
def write_file(filepath, # type: AnyStr def write_file(filepath, # type: AnyStr
@ -1312,7 +1359,7 @@ def write_file(filepath, # type: AnyStr
""" """
result = False result = False
if make_dirs(ek.ek(os.path.dirname, filepath)): if make_path(ek.ek(os.path.dirname, filepath)):
try: try:
if raw: if raw:
with ek.ek(io.FileIO, filepath, 'wb') as fh: with ek.ek(io.FileIO, filepath, 'wb') as fh:
@ -1353,6 +1400,40 @@ def write_file(filepath, # type: AnyStr
return result return result
def sanitize_filename(name):
"""
:param name: filename
:type name: AnyStr
:return: sanitized filename
:rtype: AnyStr
"""
# remove bad chars from the filename
name = re.sub(r'[\\/*]', '-', name)
name = re.sub(r'[:"<>|?]', '', name)
# remove leading/trailing periods and spaces
name = name.strip(' .')
for char in REMOVE_FILENAME_CHARS or []:
name = name.replace(char, '')
return name
def replace_extension(filename, new_ext):
# type: (AnyStr, AnyStr) -> AnyStr
"""
:param filename: filename
:param new_ext: new extension
:return: filename with new extension
"""
sep_file = filename.rpartition('.')
if '' == sep_file[0]:
return filename
return '%s.%s' % (sep_file[0], new_ext)
def long_path(path): def long_path(path):
# type: (AnyStr) -> AnyStr # type: (AnyStr) -> AnyStr
"""add long path prefix for Windows""" """add long path prefix for Windows"""
@ -1361,6 +1442,64 @@ def long_path(path):
return path return path
def compress_file(target, filename, prefer_7z=True, remove_source=True):
# type: (AnyStr, AnyStr, bool, bool) -> bool
"""
compress given file to zip or 7z archive
:param target: file to compress with full path
:param filename: filename inside the archive
:param prefer_7z: prefer 7z over zip compression if available
:param remove_source: remove source file after successful creation of archive
:return: success of compression
"""
try:
if prefer_7z and None is not py7zr:
z_name = '%s.7z' % target.rpartition('.')[0]
# noinspection PyUnresolvedReferences
with py7zr.SevenZipFile(z_name, 'w') as z_file:
z_file.write(target, filename)
else:
zip_name = '%s.zip' % target.rpartition('.')[0]
with zipfile.ZipFile(zip_name, 'w', zipfile.ZIP_DEFLATED) as zip_fh:
zip_fh.write(target, filename)
except (BaseException, Exception) as e:
logger.error('error compressing %s' % target)
logger.debug('traceback: %s' % ex(e))
return False
if remove_source:
remove_file_perm(target)
return True
def cmdline_runner(cmd, shell=False, suppress_stderr=False):
# type: (Union[AnyStr, List[AnyStr]], bool, bool) -> Tuple[AnyStr, Optional[AnyStr], int]
""" Execute a child program in a new process.
Can raise an exception to be caught in callee
:param cmd: A string, or a sequence of program arguments
:param shell: If true, the command will be executed through the shell.
:param suppress_stderr: Suppress stderr output if True
"""
# noinspection PyUnresolvedReferences
kw = dict(cwd=PROG_DIR, shell=shell, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=(open(os.devnull, 'w') if PY2 else subprocess.DEVNULL, subprocess.STDOUT)[not suppress_stderr])
if not PY2:
kw.update(dict(encoding=ek.SYS_ENCODING, text=True, bufsize=0))
if 'win32' == sys.platform:
kw['creationflags'] = 0x08000000 # CREATE_NO_WINDOW (needed for py2exe)
with Popen(cmd, **kw) as p:
out, err = p.communicate()
if out:
out = out.strip()
return out, err, p.returncode
def md5_for_text(text): def md5_for_text(text):
""" """
@ -1449,97 +1588,6 @@ def indent_xml(elem, level=0):
elem.tail = i elem.tail = i
def compress_file(target, filename, prefer_7z=True, remove_source=True):
# type: (AnyStr, AnyStr, bool, bool) -> bool
"""
compress given file to zip or 7z archive
:param target: file to compress with full path
:param filename: filename inside the archive
:param prefer_7z: prefer 7z over zip compression if available
:param remove_source: remove source file after successful creation of archive
:return: success of compression
"""
try:
if prefer_7z and None is not py7zr:
z_name = '%s.7z' % target.rpartition('.')[0]
with py7zr.SevenZipFile(z_name, 'w') as z_file:
z_file.write(target, filename)
else:
zip_name = '%s.zip' % target.rpartition('.')[0]
with zipfile.ZipFile(zip_name, 'w', zipfile.ZIP_DEFLATED) as zip_fh:
zip_fh.write(target, filename)
except (BaseException, Exception) as e:
logger.error('error compressing %s' % target)
logger.debug('traceback: %s' % ex(e))
return False
if remove_source:
remove_file_perm(target)
return True
def scantree(path, # type: AnyStr
exclude=None, # type: Optional[AnyStr, List[AnyStr]]
include=None, # type: Optional[AnyStr, List[AnyStr]]
follow_symlinks=False, # type: bool
filter_kind=None, # type: Optional[bool]
recurse=True # type: bool
):
# type: (...) -> Generator[DirEntry, None, None]
"""Yield DirEntry objects for given path. Returns without yield if path fails sanity check
:param path: Path to scan, sanity check is_dir and exists
:param exclude: Escaped regex string(s) to exclude
:param include: Escaped regex string(s) to include
:param follow_symlinks: Follow symlinks
:param filter_kind: None to yield everything, True yields directories, False yields files
:param recurse: Recursively scan the tree
"""
if isinstance(path, string_types) and path and ek.ek(os.path.isdir, path):
rc_exc, rc_inc = [re.compile(rx % '|'.join(
[x for x in (param, ([param], [])[None is param])[not isinstance(param, list)]]))
for rx, param in ((r'(?i)^(?:(?!%s).)*$', exclude), (r'(?i)%s', include))]
for entry in ek.ek(scandir, path):
is_dir = entry.is_dir(follow_symlinks=follow_symlinks)
is_file = entry.is_file(follow_symlinks=follow_symlinks)
no_filter = any([None is filter_kind, filter_kind and is_dir, not filter_kind and is_file])
if (rc_exc.search(entry.name), True)[not exclude] and (rc_inc.search(entry.name), True)[not include] \
and (no_filter or (not filter_kind and is_dir and recurse)):
if recurse and is_dir:
for subentry in scantree(entry.path, exclude, include, follow_symlinks, filter_kind, recurse):
yield subentry
if no_filter:
yield entry
def cmdline_runner(cmd, shell=False, suppress_stderr=False):
# type: (Union[AnyStr, List[AnyStr]], bool, bool) -> Tuple[AnyStr, Optional[AnyStr], int]
""" Execute a child program in a new process.
Can raise an exception to be caught in callee
:param cmd: A string, or a sequence of program arguments
:param shell: If true, the command will be executed through the shell.
:param suppress_stderr: Suppress stderr output if True
"""
# noinspection PyUnresolvedReferences
kw = dict(cwd=PROG_DIR, shell=shell, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=(open(os.devnull, 'w') if PY2 else subprocess.DEVNULL, subprocess.STDOUT)[not suppress_stderr])
if not PY2:
kw.update(dict(encoding=ek.SYS_ENCODING, text=True, bufsize=0))
if 'win32' == sys.platform:
kw['creationflags'] = 0x08000000 # CREATE_NO_WINDOW (needed for py2exe)
with Popen(cmd, **kw) as p:
out, err = p.communicate()
if out:
out = out.strip()
return out, err, p.returncode
def ast_eval(value, default=None): def ast_eval(value, default=None):
# type: (AnyStr, Any) -> Any # type: (AnyStr, Any) -> Any
"""Convert string typed value into actual Python type and value """Convert string typed value into actual Python type and value
@ -1575,27 +1623,6 @@ def ast_eval(value, default=None):
return value return value
def sanitize_filename(name):
"""
:param name: filename
:type name: AnyStr
:return: sanitized filename
:rtype: AnyStr
"""
# remove bad chars from the filename
name = re.sub(r'[\\/*]', '-', name)
name = re.sub(r'[:"<>|?]', '', name)
# remove leading/trailing periods and spaces
name = name.strip(' .')
for char in REMOVE_FILENAME_CHARS or []:
name = name.replace(char, '')
return name
def download_file(url, filename, session=None, **kwargs): def download_file(url, filename, session=None, **kwargs):
""" """
download given url to given filename download given url to given filename
@ -1678,34 +1705,3 @@ def spoken_height(height):
:param height: height in cm :param height: height in cm
""" """
return convert_to_inch_faction_html(height).replace('\'', ' foot').replace('"', '') return convert_to_inch_faction_html(height).replace('\'', ' foot').replace('"', '')
def touch_file(fname, atime=None, dir_name=None):
"""
set access time of given file
:param fname: filename
:type fname: AnyStr
:param atime: access time as epoch
:type atime: int
:param: dir_name: directory name
:type dir_name: AnyStr
:return: success
:rtype: bool
"""
if None is not dir_name:
fname = ek.ek(os.path.join, dir_name, fname)
if make_dirs(dir_name):
if not ek.ek(os.path.exists, fname):
with io.open(fname, 'w') as fh:
fh.flush()
if None is not atime:
try:
with open(fname, 'a'):
ek.ek(os.utime, fname, (atime, atime))
return True
except (BaseException, Exception):
logger.debug('File air date stamping not available on your OS')
return False

4
lib/tvinfo_base/base.py

@ -9,7 +9,7 @@ from exceptions_helper import ex
from six import integer_types, iteritems, iterkeys, string_types, text_type from six import integer_types, iteritems, iterkeys, string_types, text_type
from _23 import list_items, list_values from _23 import list_items, list_values
from lib.tvinfo_base.exceptions import * from lib.tvinfo_base.exceptions import *
from sg_helpers import calc_age, make_dirs from sg_helpers import calc_age, make_path
# noinspection PyUnreachableCode # noinspection PyUnreachableCode
if False: if False:
@ -906,7 +906,7 @@ class TVInfoBase(object):
log.error(ex(e)) log.error(ex(e))
pass pass
try: try:
make_dirs(self._cachedir) make_path(self._cachedir)
except (BaseException, Exception): except (BaseException, Exception):
pass pass
return self._get_cache_entry(key, retry=True) return self._get_cache_entry(key, retry=True)

2
sickbeard/__init__.py

@ -823,7 +823,7 @@ def init_stage_1(console_logging):
if CACHE_DIR: if CACHE_DIR:
helpers.clear_cache() helpers.clear_cache()
ZONEINFO_DIR = ek.ek(os.path.join, CACHE_DIR, 'zoneinfo') ZONEINFO_DIR = ek.ek(os.path.join, CACHE_DIR, 'zoneinfo')
if not ek.ek(os.path.isdir, ZONEINFO_DIR) and not helpers.make_dirs(ZONEINFO_DIR): if not ek.ek(os.path.isdir, ZONEINFO_DIR) and not helpers.make_path(ZONEINFO_DIR):
logger.log(u'!!! Creating local zoneinfo dir failed', logger.ERROR) logger.log(u'!!! Creating local zoneinfo dir failed', logger.ERROR)
sg_helpers.CACHE_DIR = CACHE_DIR sg_helpers.CACHE_DIR = CACHE_DIR
sg_helpers.DATA_DIR = DATA_DIR sg_helpers.DATA_DIR = DATA_DIR

4
sickbeard/anime.py

@ -27,7 +27,7 @@ from exceptions_helper import ex
import sickbeard import sickbeard
from . import db, logger from . import db, logger
from .classes import NZBDataSearchResult, NZBSearchResult, TorrentSearchResult from .classes import NZBDataSearchResult, NZBSearchResult, TorrentSearchResult
from .helpers import get_system_temp_dir, make_dirs from .helpers import get_system_temp_dir, make_path
# noinspection PyUnreachableCode # noinspection PyUnreachableCode
if False: if False:
@ -184,7 +184,7 @@ def short_group_names(groups):
def anidb_cache_dir(): def anidb_cache_dir():
# type: (...) -> Optional[AnyStr] # type: (...) -> Optional[AnyStr]
cache_dir = ek.ek(os.path.join, sickbeard.CACHE_DIR or get_system_temp_dir(), 'anidb') cache_dir = ek.ek(os.path.join, sickbeard.CACHE_DIR or get_system_temp_dir(), 'anidb')
if not make_dirs(cache_dir): if not make_path(cache_dir):
cache_dir = None cache_dir = None
return cache_dir return cache_dir

4
sickbeard/db.py

@ -34,7 +34,7 @@ import sickbeard
from . import logger, sgdatetime from . import logger, sgdatetime
from .sgdatetime import timestamp_near from .sgdatetime import timestamp_near
from sg_helpers import make_dirs, compress_file, remove_file_perm, scantree from sg_helpers import make_path, compress_file, remove_file_perm, scantree
from _23 import filter_iter, filter_list, list_values, scandir from _23 import filter_iter, filter_list, list_values, scandir
from six import iterkeys, iteritems, itervalues from six import iterkeys, iteritems, itervalues
@ -841,7 +841,7 @@ def backup_all_dbs(target, compress=True, prefer_7z=True):
:param prefer_7z: prefer 7z compression if available :param prefer_7z: prefer 7z compression if available
:return: success, message :return: success, message
""" """
if not make_dirs(target): if not make_path(target):
logger.log('Failed to create db backup dir', logger.ERROR) logger.log('Failed to create db backup dir', logger.ERROR)
return False, 'Failed to create db backup dir' return False, 'Failed to create db backup dir'
my_db = DBConnection('cache.db') my_db = DBConnection('cache.db')

4
sickbeard/helpers.py

@ -61,7 +61,7 @@ from six.moves import zip
# therefore, they intentionally don't resolve and are unused in this particular file. # therefore, they intentionally don't resolve and are unused in this particular file.
# noinspection PyUnresolvedReferences # noinspection PyUnresolvedReferences
from sg_helpers import chmod_as_parent, clean_data, copy_file, download_file, fix_set_group_id, get_system_temp_dir, \ from sg_helpers import chmod_as_parent, clean_data, copy_file, download_file, fix_set_group_id, get_system_temp_dir, \
get_url, indent_xml, make_dirs, maybe_plural, md5_for_text, move_file, proxy_setting, remove_file, \ get_url, indent_xml, make_path, maybe_plural, md5_for_text, move_file, proxy_setting, remove_file, \
remove_file_perm, replace_extension, sanitize_filename, scantree, touch_file, try_int, try_ord, write_file remove_file_perm, replace_extension, sanitize_filename, scantree, touch_file, try_int, try_ord, write_file
# noinspection PyUnreachableCode # noinspection PyUnreachableCode
@ -479,7 +479,7 @@ def rename_ep_file(cur_path, new_path, old_path_length=0):
# put the extension on the incoming file # put the extension on the incoming file
new_path += cur_file_ext new_path += cur_file_ext
make_dirs(ek.ek(os.path.dirname, new_path), syno=True) make_path(ek.ek(os.path.dirname, new_path), syno=True)
# move the file # move the file
try: try:

2
sickbeard/image_cache.py

@ -528,7 +528,7 @@ class ImageCache(object):
return False return False
for cache_dir in [self.shows_dir, self._thumbnails_dir(*id_args)] + fanart_dir: for cache_dir in [self.shows_dir, self._thumbnails_dir(*id_args)] + fanart_dir:
sg_helpers.make_dirs(cache_dir) sg_helpers.make_path(cache_dir)
logger.log(u'%sing from %s to %s' % (('Copy', 'Mov')[move_file], image_path, dest_path)) logger.log(u'%sing from %s to %s' % (('Copy', 'Mov')[move_file], image_path, dest_path))
# copy poster, banner as thumb, even if moved we need to duplicate the images # copy poster, banner as thumb, even if moved we need to duplicate the images

2
sickbeard/indexers/indexer_api.py

@ -18,7 +18,7 @@
import os import os
from .indexer_config import init_config, tvinfo_config from .indexer_config import init_config, tvinfo_config
from sg_helpers import make_dirs, proxy_setting from sg_helpers import make_path, proxy_setting
import sickbeard import sickbeard
from lib.tvinfo_base import TVInfoBase from lib.tvinfo_base import TVInfoBase
import encodingKludge as ek import encodingKludge as ek

2
sickbeard/postProcessor.py

@ -1155,7 +1155,7 @@ class PostProcessor(object):
self._log(u'Destination folder for this episode is ' + dest_path, logger.DEBUG) self._log(u'Destination folder for this episode is ' + dest_path, logger.DEBUG)
# create any folders we need # create any folders we need
if not helpers.make_dirs(dest_path, syno=True): if not helpers.make_path(dest_path, syno=True):
raise exceptions_helper.PostProcessingFailed(u'Unable to create destination folder: ' + dest_path) raise exceptions_helper.PostProcessingFailed(u'Unable to create destination folder: ' + dest_path)
# figure out the base name of the resulting episode file # figure out the base name of the resulting episode file

2
sickbeard/scene_exceptions.py

@ -399,7 +399,7 @@ def _custom_exceptions_fetcher():
if fetch_data: if fetch_data:
if ek.ek(os.path.exists, tmppath): if ek.ek(os.path.exists, tmppath):
helpers.remove_file(tmppath, tree=True) helpers.remove_file(tmppath, tree=True)
helpers.make_dirs(tmppath) helpers.make_path(tmppath)
helpers.download_file(r'https://github.com/SickGear/sickgear.altdata/raw/master/alt.rar', file_rar) helpers.download_file(r'https://github.com/SickGear/sickgear.altdata/raw/master/alt.rar', file_rar)
rar_handle = None rar_handle = None

6
sickbeard/webserve.py

@ -9495,7 +9495,7 @@ class CachedImages(MainHandler):
image_file = ek.ek(os.path.abspath, image_file.replace('\\', '/')) image_file = ek.ek(os.path.abspath, image_file.replace('\\', '/'))
if not ek.ek(os.path.isfile, image_file) and has_image_ext(file_name): if not ek.ek(os.path.isfile, image_file) and has_image_ext(file_name):
basepath = ek.ek(os.path.dirname, image_file) basepath = ek.ek(os.path.dirname, image_file)
helpers.make_dirs(basepath) helpers.make_path(basepath)
poster_url = '' poster_url = ''
tmdb_image = False tmdb_image = False
if None is not source and source in sickbeard.CACHE_IMAGE_URL_LIST: if None is not source and source in sickbeard.CACHE_IMAGE_URL_LIST:
@ -9597,7 +9597,7 @@ class CachedImages(MainHandler):
if not prefer_person and (char_obj.thumb_url or char_obj.image_url): if not prefer_person and (char_obj.thumb_url or char_obj.image_url):
image_cache_obj = image_cache.ImageCache() image_cache_obj = image_cache.ImageCache()
image_normal, image_thumb = image_cache_obj.character_both_path(char_obj, show_obj, person_obj=person_obj) image_normal, image_thumb = image_cache_obj.character_both_path(char_obj, show_obj, person_obj=person_obj)
sg_helpers.make_dirs(image_cache_obj.characters_dir) sg_helpers.make_path(image_cache_obj.characters_dir)
if self.should_load_image(image_normal) and char_obj.image_url: if self.should_load_image(image_normal) and char_obj.image_url:
sg_helpers.download_file(char_obj.image_url, image_normal) sg_helpers.download_file(char_obj.image_url, image_normal)
if self.should_load_image(image_thumb) and char_obj.thumb_url: if self.should_load_image(image_thumb) and char_obj.thumb_url:
@ -9635,7 +9635,7 @@ class CachedImages(MainHandler):
if person_obj.thumb_url or person_obj.image_url: if person_obj.thumb_url or person_obj.image_url:
image_cache_obj = image_cache.ImageCache() image_cache_obj = image_cache.ImageCache()
image_normal, image_thumb = image_cache_obj.person_both_paths(person_obj) image_normal, image_thumb = image_cache_obj.person_both_paths(person_obj)
sg_helpers.make_dirs(image_cache_obj.characters_dir) sg_helpers.make_path(image_cache_obj.characters_dir)
if self.should_load_image(image_normal) and person_obj.image_url: if self.should_load_image(image_normal) and person_obj.image_url:
sg_helpers.download_file(person_obj.image_url, image_normal) sg_helpers.download_file(person_obj.image_url, image_normal)
if self.should_load_image(image_thumb) and person_obj.thumb_url: if self.should_load_image(image_thumb) and person_obj.thumb_url:

Loading…
Cancel
Save