mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2026-06-13 14:24:31 +00:00
[utils] Deprecate make_dir in favor of make_parent_dirs (#16931)
Authored by: doe1080
This commit is contained in:
parent
a2483524fb
commit
b05b408d10
@ -395,6 +395,7 @@ banned-from = [
|
||||
"yt_dlp.utils.bytes_to_intlist".msg = "Use `list` instead."
|
||||
"yt_dlp.utils.intlist_to_bytes".msg = "Use `bytes` instead."
|
||||
"yt_dlp.utils.jwt_encode_hs256".msg = "Use `yt_dlp.utils.jwt_encode` instead."
|
||||
"yt_dlp.utils.make_dir".msg = "Use `yt_dlp.utils.make_parent_dirs` instead."
|
||||
"yt_dlp.utils.decodeArgument".msg = "Do not use"
|
||||
"yt_dlp.utils.decodeFilename".msg = "Do not use"
|
||||
"yt_dlp.utils.encodeFilename".msg = "Do not use"
|
||||
|
||||
@ -139,7 +139,7 @@ from .utils import (
|
||||
join_nonempty,
|
||||
locked_file,
|
||||
make_archive_id,
|
||||
make_dir,
|
||||
make_parent_dirs,
|
||||
number_of_digits,
|
||||
orderedSet,
|
||||
orderedSet_from_options,
|
||||
@ -2036,7 +2036,12 @@ class YoutubeDL:
|
||||
raise Exception(f'Invalid result type: {result_type}')
|
||||
|
||||
def _ensure_dir_exists(self, path):
|
||||
return make_dir(path, self.report_error)
|
||||
try:
|
||||
make_parent_dirs(path)
|
||||
return True
|
||||
except OSError as e:
|
||||
self.report_error(f'Unable to create directory: {e}')
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def _playlist_infodict(ie_result, strict=False, **kwargs):
|
||||
|
||||
@ -4,7 +4,7 @@ from .common import PostProcessor
|
||||
from ..compat import shutil
|
||||
from ..utils import (
|
||||
PostProcessingError,
|
||||
make_dir,
|
||||
make_parent_dirs,
|
||||
)
|
||||
|
||||
|
||||
@ -42,7 +42,10 @@ class MoveFilesAfterDownloadPP(PostProcessor):
|
||||
self.report_warning(
|
||||
f'Cannot move file "{oldfile}" out of temporary directory since "{newfile}" already exists. ')
|
||||
continue
|
||||
make_dir(newfile, PostProcessingError)
|
||||
try:
|
||||
make_parent_dirs(newfile)
|
||||
except OSError as e:
|
||||
raise PostProcessingError(f'Unable to create directory: {e}') from e
|
||||
self.to_screen(f'Moving file "{oldfile}" to "{newfile}"')
|
||||
shutil.move(oldfile, newfile) # os.rename cannot move between volumes
|
||||
|
||||
|
||||
@ -46,4 +46,16 @@ def jwt_encode_hs256(payload_data, key, headers={}):
|
||||
return header_b64 + b'.' + payload_b64 + b'.' + signature_b64
|
||||
|
||||
|
||||
def make_dir(path, to_screen=None):
|
||||
from . import make_parent_dirs
|
||||
|
||||
try:
|
||||
make_parent_dirs(path)
|
||||
return True
|
||||
except OSError as e:
|
||||
if to_screen is not None:
|
||||
to_screen(f'Unable to create directory: {e}')
|
||||
return False
|
||||
|
||||
|
||||
compiled_regex_type = type(re.compile(''))
|
||||
|
||||
@ -4713,16 +4713,9 @@ def random_uuidv4():
|
||||
return re.sub(r'[xy]', lambda x: _HEX_TABLE[random.randint(0, 15)], 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx')
|
||||
|
||||
|
||||
def make_dir(path, to_screen=None):
|
||||
try:
|
||||
dn = os.path.dirname(path)
|
||||
if dn:
|
||||
os.makedirs(dn, exist_ok=True)
|
||||
return True
|
||||
except OSError as err:
|
||||
if callable(to_screen) is not None:
|
||||
to_screen(f'unable to create directory {err}')
|
||||
return False
|
||||
def make_parent_dirs(path):
|
||||
if dir_name := os.path.dirname(path):
|
||||
os.makedirs(dir_name, exist_ok=True)
|
||||
|
||||
|
||||
def get_executable_path():
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user