summaryrefslogtreecommitdiffstats
path: root/gallery_dl/output.py
diff options
context:
space:
mode:
Diffstat (limited to 'gallery_dl/output.py')
-rw-r--r--gallery_dl/output.py37
1 files changed, 13 insertions, 24 deletions
diff --git a/gallery_dl/output.py b/gallery_dl/output.py
index e4937f4..519a8f4 100644
--- a/gallery_dl/output.py
+++ b/gallery_dl/output.py
@@ -165,9 +165,9 @@ class Formatter(logging.Formatter):
if record.exc_info and not record.exc_text:
record.exc_text = self.formatException(record.exc_info)
if record.exc_text:
- msg = msg + "\n" + record.exc_text
+ msg = f"{msg}\n{record.exc_text}"
if record.stack_info:
- msg = msg + "\n" + record.stack_info
+ msg = f"{msg}\n{record.stack_info}"
return msg
@@ -317,18 +317,7 @@ def configure_standard_streams():
elif not options.get("errors"):
options["errors"] = "replace"
- try:
- stream.reconfigure(**options)
- except AttributeError:
- # no 'reconfigure' support
- oget = options.get
- setattr(sys, name, stream.__class__(
- stream.buffer,
- encoding=oget("encoding", stream.encoding),
- errors=oget("errors", "replace"),
- newline=oget("newline", stream.newlines),
- line_buffering=oget("line_buffering", stream.line_buffering),
- ))
+ stream.reconfigure(**options)
# --------------------------------------------------------------------
@@ -383,10 +372,10 @@ class NullOutput():
class PipeOutput(NullOutput):
def skip(self, path):
- stdout_write(CHAR_SKIP + path + "\n")
+ stdout_write(f"{CHAR_SKIP}{path}\n")
def success(self, path):
- stdout_write(path + "\n")
+ stdout_write(f"{path}\n")
class TerminalOutput():
@@ -401,13 +390,13 @@ class TerminalOutput():
self.shorten = util.identity
def start(self, path):
- stdout_write_flush(self.shorten(" " + path))
+ stdout_write_flush(self.shorten(f" {path}"))
def skip(self, path):
- stdout_write(self.shorten(CHAR_SKIP + path) + "\n")
+ stdout_write(f"{self.shorten(CHAR_SKIP + path)}\n")
def success(self, path):
- stdout_write("\r" + self.shorten(CHAR_SUCCESS + path) + "\n")
+ stdout_write(f"\r{self.shorten(CHAR_SUCCESS + path)}\n")
def progress(self, bytes_total, bytes_downloaded, bytes_per_second):
bdl = util.format_value(bytes_downloaded)
@@ -435,10 +424,10 @@ class ColorOutput(TerminalOutput):
stdout_write_flush(self.shorten(path))
def skip(self, path):
- stdout_write(self.color_skip + self.shorten(path) + "\033[0m\n")
+ stdout_write(f"{self.color_skip}{self.shorten(path)}\x1b[0m\n")
def success(self, path):
- stdout_write(self.color_success + self.shorten(path) + "\033[0m\n")
+ stdout_write(f"{self.color_success}{self.shorten(path)}\x1b[0m\n")
class CustomOutput():
@@ -514,7 +503,7 @@ def shorten_string(txt, limit, sep="…"):
if len(txt) <= limit:
return txt
limit -= len(sep)
- return txt[:limit // 2] + sep + txt[-((limit+1) // 2):]
+ return f"{txt[:limit // 2]}{sep}{txt[-((limit+1) // 2):]}"
def shorten_string_eaw(txt, limit, sep="…", cache=EAWCache()):
@@ -529,7 +518,7 @@ def shorten_string_eaw(txt, limit, sep="…", cache=EAWCache()):
limit -= len(sep)
if text_width == len(txt):
# all characters have a width of 1
- return txt[:limit // 2] + sep + txt[-((limit+1) // 2):]
+ return f"{txt[:limit // 2]}{sep}{txt[-((limit+1) // 2):]}"
# wide characters
left = 0
@@ -548,4 +537,4 @@ def shorten_string_eaw(txt, limit, sep="…", cache=EAWCache()):
break
right -= 1
- return txt[:left] + sep + txt[right+1:]
+ return f"{txt[:left]}{sep}{txt[right+1:]}"