add global WINDOWS bool

pull/779/head
Mike Fährmann 4 years ago
parent 6294e2c540
commit c8787647ed
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

@ -193,7 +193,7 @@ def _path():
if path != -1: if path != -1:
return util.expand_path(path) return util.expand_path(path)
if os.name == "nt": if util.WINDOWS:
import tempfile import tempfile
return os.path.join(tempfile.gettempdir(), ".gallery-dl.cache") return os.path.join(tempfile.gettempdir(), ".gallery-dl.cache")
@ -205,7 +205,7 @@ def _path():
try: try:
dbfile = _path() dbfile = _path()
if os.name != "nt": if not util.WINDOWS:
# restrict access permissions for new db files # restrict access permissions for new db files
os.close(os.open(dbfile, os.O_CREAT | os.O_RDONLY, 0o600)) os.close(os.open(dbfile, os.O_CREAT | os.O_RDONLY, 0o600))
DatabaseCacheDecorator.db = sqlite3.connect( DatabaseCacheDecorator.db = sqlite3.connect(

@ -22,7 +22,7 @@ log = logging.getLogger("config")
_config = {} _config = {}
if os.name == "nt": if util.WINDOWS:
_default_configs = [ _default_configs = [
r"%USERPROFILE%\gallery-dl\config.json", r"%USERPROFILE%\gallery-dl\config.json",
r"%USERPROFILE%\gallery-dl.conf", r"%USERPROFILE%\gallery-dl.conf",

@ -10,9 +10,8 @@
from .common import Extractor, Message from .common import Extractor, Message
from . import deviantart, flickr, reddit, smugmug, tumblr from . import deviantart, flickr, reddit, smugmug, tumblr
from .. import text, oauth, config, exception from .. import text, oauth, util, config, exception
from ..cache import cache from ..cache import cache
import os
import urllib.parse import urllib.parse
REDIRECT_URI_LOCALHOST = "http://localhost:6414/" REDIRECT_URI_LOCALHOST = "http://localhost:6414/"
@ -42,7 +41,7 @@ class OAuthBase(Extractor):
server.listen(1) server.listen(1)
# workaround for ctrl+c not working during server.accept on Windows # workaround for ctrl+c not working during server.accept on Windows
if os.name == "nt": if util.WINDOWS:
server.settimeout(1.0) server.settimeout(1.0)
while True: while True:
try: try:

@ -303,7 +303,7 @@ class ColorOutput(TerminalOutput):
print("\r\033[1;32m", self.shorten(path), "\033[0m", sep="") print("\r\033[1;32m", self.shorten(path), "\033[0m", sep="")
if os.name == "nt": if util.WINDOWS:
ANSI = os.environ.get("TERM") == "ANSI" ANSI = os.environ.get("TERM") == "ANSI"
OFFSET = 1 OFFSET = 1
CHAR_SKIP = "# " CHAR_SKIP = "# "

@ -11,10 +11,9 @@
from .common import PostProcessor from .common import PostProcessor
from .. import util from .. import util
import subprocess import subprocess
import os
if os.name == "nt": if util.WINDOWS:
def quote(s): def quote(s):
return '"' + s.replace('"', '\\"') + '"' return '"' + s.replace('"', '\\"') + '"'
else: else:

@ -270,6 +270,7 @@ class UniversalNone():
NONE = UniversalNone() NONE = UniversalNone()
WINDOWS = (os.name == "nt")
def build_predicate(predicates): def build_predicate(predicates):
@ -673,7 +674,7 @@ class PathFormat():
restrict = extractor.config("path-restrict", "auto") restrict = extractor.config("path-restrict", "auto")
if restrict == "auto": if restrict == "auto":
restrict = "\\\\|/<>:\"?*" if os.name == "nt" else "/" restrict = "\\\\|/<>:\"?*" if WINDOWS else "/"
elif restrict == "unix": elif restrict == "unix":
restrict = "/" restrict = "/"
elif restrict == "windows": elif restrict == "windows":
@ -727,7 +728,6 @@ class PathFormat():
def set_directory(self, kwdict): def set_directory(self, kwdict):
"""Build directory path and create it if necessary""" """Build directory path and create it if necessary"""
self.kwdict = kwdict self.kwdict = kwdict
windows = os.name == "nt"
# Build path segments by applying 'kwdict' to directory format strings # Build path segments by applying 'kwdict' to directory format strings
segments = [] segments = []
@ -735,7 +735,7 @@ class PathFormat():
try: try:
for formatter in self.directory_formatters: for formatter in self.directory_formatters:
segment = formatter(kwdict).strip() segment = formatter(kwdict).strip()
if windows: if WINDOWS:
# remove trailing dots and spaces (#647) # remove trailing dots and spaces (#647)
segment = segment.rstrip(". ") segment = segment.rstrip(". ")
if segment: if segment:
@ -752,7 +752,7 @@ class PathFormat():
directory += sep directory += sep
self.directory = directory self.directory = directory
if windows: if WINDOWS:
# Enable longer-than-260-character paths on Windows # Enable longer-than-260-character paths on Windows
directory = "\\\\?\\" + os.path.abspath(directory) directory = "\\\\?\\" + os.path.abspath(directory)

Loading…
Cancel
Save