From c8787647ed403bbcf02c085dc3e221119535471e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Tue, 19 May 2020 21:42:11 +0200 Subject: [PATCH] add global WINDOWS bool --- gallery_dl/cache.py | 4 ++-- gallery_dl/config.py | 2 +- gallery_dl/extractor/oauth.py | 5 ++--- gallery_dl/output.py | 2 +- gallery_dl/postprocessor/exec.py | 3 +-- gallery_dl/util.py | 8 ++++---- 6 files changed, 11 insertions(+), 13 deletions(-) diff --git a/gallery_dl/cache.py b/gallery_dl/cache.py index 5efa0eb3..ea802dfb 100644 --- a/gallery_dl/cache.py +++ b/gallery_dl/cache.py @@ -193,7 +193,7 @@ def _path(): if path != -1: return util.expand_path(path) - if os.name == "nt": + if util.WINDOWS: import tempfile return os.path.join(tempfile.gettempdir(), ".gallery-dl.cache") @@ -205,7 +205,7 @@ def _path(): try: dbfile = _path() - if os.name != "nt": + if not util.WINDOWS: # restrict access permissions for new db files os.close(os.open(dbfile, os.O_CREAT | os.O_RDONLY, 0o600)) DatabaseCacheDecorator.db = sqlite3.connect( diff --git a/gallery_dl/config.py b/gallery_dl/config.py index c2787adb..8a25901f 100644 --- a/gallery_dl/config.py +++ b/gallery_dl/config.py @@ -22,7 +22,7 @@ log = logging.getLogger("config") _config = {} -if os.name == "nt": +if util.WINDOWS: _default_configs = [ r"%USERPROFILE%\gallery-dl\config.json", r"%USERPROFILE%\gallery-dl.conf", diff --git a/gallery_dl/extractor/oauth.py b/gallery_dl/extractor/oauth.py index c06721c1..123bb44f 100644 --- a/gallery_dl/extractor/oauth.py +++ b/gallery_dl/extractor/oauth.py @@ -10,9 +10,8 @@ from .common import Extractor, Message from . import deviantart, flickr, reddit, smugmug, tumblr -from .. import text, oauth, config, exception +from .. import text, oauth, util, config, exception from ..cache import cache -import os import urllib.parse REDIRECT_URI_LOCALHOST = "http://localhost:6414/" @@ -42,7 +41,7 @@ class OAuthBase(Extractor): server.listen(1) # workaround for ctrl+c not working during server.accept on Windows - if os.name == "nt": + if util.WINDOWS: server.settimeout(1.0) while True: try: diff --git a/gallery_dl/output.py b/gallery_dl/output.py index a9584362..2d3dc17d 100644 --- a/gallery_dl/output.py +++ b/gallery_dl/output.py @@ -303,7 +303,7 @@ class ColorOutput(TerminalOutput): print("\r\033[1;32m", self.shorten(path), "\033[0m", sep="") -if os.name == "nt": +if util.WINDOWS: ANSI = os.environ.get("TERM") == "ANSI" OFFSET = 1 CHAR_SKIP = "# " diff --git a/gallery_dl/postprocessor/exec.py b/gallery_dl/postprocessor/exec.py index a5070688..cbe51ae4 100644 --- a/gallery_dl/postprocessor/exec.py +++ b/gallery_dl/postprocessor/exec.py @@ -11,10 +11,9 @@ from .common import PostProcessor from .. import util import subprocess -import os -if os.name == "nt": +if util.WINDOWS: def quote(s): return '"' + s.replace('"', '\\"') + '"' else: diff --git a/gallery_dl/util.py b/gallery_dl/util.py index aa39c08c..931df9ee 100644 --- a/gallery_dl/util.py +++ b/gallery_dl/util.py @@ -270,6 +270,7 @@ class UniversalNone(): NONE = UniversalNone() +WINDOWS = (os.name == "nt") def build_predicate(predicates): @@ -673,7 +674,7 @@ class PathFormat(): restrict = extractor.config("path-restrict", "auto") if restrict == "auto": - restrict = "\\\\|/<>:\"?*" if os.name == "nt" else "/" + restrict = "\\\\|/<>:\"?*" if WINDOWS else "/" elif restrict == "unix": restrict = "/" elif restrict == "windows": @@ -727,7 +728,6 @@ class PathFormat(): def set_directory(self, kwdict): """Build directory path and create it if necessary""" self.kwdict = kwdict - windows = os.name == "nt" # Build path segments by applying 'kwdict' to directory format strings segments = [] @@ -735,7 +735,7 @@ class PathFormat(): try: for formatter in self.directory_formatters: segment = formatter(kwdict).strip() - if windows: + if WINDOWS: # remove trailing dots and spaces (#647) segment = segment.rstrip(". ") if segment: @@ -752,7 +752,7 @@ class PathFormat(): directory += sep self.directory = directory - if windows: + if WINDOWS: # Enable longer-than-260-character paths on Windows directory = "\\\\?\\" + os.path.abspath(directory)