replace 'print()' with 'output.stderr_write("\n")'

This commit is contained in:
Mike Fährmann
2025-02-15 18:01:05 +01:00
parent 35307608f2
commit 800cf5beb5
4 changed files with 15 additions and 15 deletions

View File

@@ -12,7 +12,7 @@ import time
import mimetypes
from requests.exceptions import RequestException, ConnectionError, Timeout
from .common import DownloaderBase
from .. import text, util
from .. import text, util, output
from ssl import SSLError
@@ -89,7 +89,7 @@ class HttpDownloader(DownloaderBase):
try:
return self._download_impl(url, pathfmt)
except Exception:
print()
output.stderr_write("\n")
raise
finally:
# remove file from incomplete downloads
@@ -269,7 +269,7 @@ class HttpDownloader(DownloaderBase):
else response.iter_content(16), b"")
except (RequestException, SSLError) as exc:
msg = str(exc)
print()
output.stderr_write("\n")
continue
if self._adjust_extension(pathfmt, file_header) and \
pathfmt.exists():
@@ -303,14 +303,14 @@ class HttpDownloader(DownloaderBase):
self.receive(fp, content, size, offset)
except (RequestException, SSLError) as exc:
msg = str(exc)
print()
output.stderr_write("\n")
continue
# check file size
if size and fp.tell() < size:
msg = "file size mismatch ({} < {})".format(
fp.tell(), size)
print()
output.stderr_write("\n")
continue
break
@@ -329,7 +329,7 @@ class HttpDownloader(DownloaderBase):
for _ in response.iter_content(self.chunk_size):
pass
except (RequestException, SSLError) as exc:
print()
output.stderr_write("\n")
self.log.debug(
"Unable to consume response body (%s: %s); "
"closing the connection anyway", exc.__class__.__name__, exc)

View File

@@ -9,7 +9,7 @@
"""Compare versions of the same file and replace/enumerate them on mismatch"""
from .common import PostProcessor
from .. import text, util, exception
from .. import text, util, output, exception
import os
@@ -83,7 +83,7 @@ class ComparePP(PostProcessor):
self._equal_cnt += 1
if self._equal_cnt >= self._equal_max:
util.remove_file(pathfmt.temppath)
print()
output.stderr_write("\n")
raise self._equal_exc()
pathfmt.delete = True

View File

@@ -9,7 +9,7 @@
"""Convert Pixiv Ugoira to WebM"""
from .common import PostProcessor
from .. import util
from .. import util, output
import subprocess
import tempfile
import zipfile
@@ -226,13 +226,13 @@ class UgoiraPP(PostProcessor):
if self._finalize:
self._finalize(pathfmt, tempdir)
except OSError as exc:
print()
output.stderr_write("\n")
self.log.error("Unable to invoke FFmpeg (%s: %s)",
exc.__class__.__name__, exc)
self.log.debug("", exc_info=exc)
pathfmt.realpath = pathfmt.temppath
except Exception as exc:
print()
output.stderr_write("\n")
self.log.error("%s: %s", exc.__class__.__name__, exc)
self.log.debug("", exc_info=exc)
pathfmt.realpath = pathfmt.temppath
@@ -296,7 +296,7 @@ class UgoiraPP(PostProcessor):
out = None if self.output else subprocess.DEVNULL
retcode = util.Popen(args, stdout=out, stderr=out).wait()
if retcode:
print()
output.stderr_write("\n")
self.log.error("Non-zero exit status when running %s (%s)",
args, retcode)
raise ValueError()

View File

@@ -12,7 +12,7 @@ import sys
from .extractor.common import Extractor, Message
from .job import DownloadJob
from . import util, version, exception
from . import util, version, output, exception
REPOS = {
"stable" : "mikf/gallery-dl",
@@ -143,13 +143,13 @@ class UpdateJob(DownloadJob):
def _warning(self, msg, *args):
if self._newline:
self._newline = False
print()
output.stderr_write("\n")
self.extractor.log.warning(msg, *args)
def _error(self, msg, *args):
if self._newline:
self._newline = False
print()
output.stderr_write("\n")
self.status |= 1
self.extractor.log.error(msg, *args)