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:
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(

@ -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",

@ -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:

@ -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 = "# "

@ -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:

@ -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)

Loading…
Cancel
Save