|
|
@ -53,7 +53,7 @@ import requests.exceptions |
|
|
|
import subliminal |
|
|
|
from lxml_etree import etree, is_lxml |
|
|
|
|
|
|
|
from _23 import b64decodebytes, b64encodebytes, decode_bytes, decode_str, DirEntry, filter_iter, Popen, scandir |
|
|
|
from _23 import b64decodebytes, b64encodebytes, decode_bytes, decode_str, filter_iter, Popen, scandir |
|
|
|
from six import iteritems, PY2, string_types, text_type |
|
|
|
# noinspection PyUnresolvedReferences |
|
|
|
from six.moves import zip |
|
|
@ -63,7 +63,7 @@ from six.moves import zip |
|
|
|
# noinspection PyUnresolvedReferences |
|
|
|
from sg_helpers import chmod_as_parent, clean_data, copy_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, \ |
|
|
|
remove_file_perm, replace_extension, try_int, try_ord, write_file |
|
|
|
remove_file_perm, replace_extension, scantree, try_int, try_ord, write_file |
|
|
|
|
|
|
|
# noinspection PyUnreachableCode |
|
|
|
if False: |
|
|
@ -1366,40 +1366,6 @@ def cpu_sleep(): |
|
|
|
time.sleep(cpu_presets[sickbeard.CPU_PRESET]) |
|
|
|
|
|
|
|
|
|
|
|
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 cleanup_cache(): |
|
|
|
""" |
|
|
|
Delete old cached files |
|
|
|