From e4801d9b0622bdc2112ba9d02b3cffc81e7a948b Mon Sep 17 00:00:00 2001 From: ed Date: Wed, 21 Apr 2021 18:28:44 +0200 Subject: [PATCH] support msys2-python --- copyparty/__init__.py | 2 ++ copyparty/httpcli.py | 4 ++-- copyparty/up2k.py | 6 +++--- copyparty/util.py | 9 +++++---- scripts/sfx.py | 2 +- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/copyparty/__init__.py b/copyparty/__init__.py index f2fc0fe7..1e1af8c1 100644 --- a/copyparty/__init__.py +++ b/copyparty/__init__.py @@ -16,6 +16,8 @@ if platform.system() == "Windows": VT100 = not WINDOWS or WINDOWS >= [10, 0, 14393] # introduced in anniversary update +ANYWIN = WINDOWS or sys.platform in ["msys"] + MACOS = platform.system() == "Darwin" diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index ca33eaeb..7615b71a 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -13,7 +13,7 @@ import ctypes from datetime import datetime import calendar -from .__init__ import E, PY2, WINDOWS +from .__init__ import E, PY2, WINDOWS, ANYWIN from .util import * # noqa # pylint: disable=unused-wildcard-import from .szip import StreamZip from .star import StreamTar @@ -626,7 +626,7 @@ class HttpCli(object): self.loud_reply(x, status=500) return False - if not WINDOWS and num_left == 0: + if not ANYWIN and num_left == 0: times = (int(time.time()), int(lastmod)) self.log("no more chunks, setting times {}".format(times)) try: diff --git a/copyparty/up2k.py b/copyparty/up2k.py index 210a3b4c..674a79cc 100644 --- a/copyparty/up2k.py +++ b/copyparty/up2k.py @@ -16,7 +16,7 @@ import traceback import subprocess as sp from copy import deepcopy -from .__init__ import WINDOWS +from .__init__ import WINDOWS, ANYWIN from .util import ( Pebkac, Queue, @@ -79,7 +79,7 @@ class Up2k(object): if self.sqlite_ver < (3, 9): self.no_expr_idx = True - if WINDOWS: + if ANYWIN: # usually fails to set lastmod too quickly self.lastmod_q = Queue() thr = threading.Thread(target=self._lastmodder) @@ -1110,7 +1110,7 @@ class Up2k(object): atomic_move(src, dst) - if WINDOWS: + if ANYWIN: self.lastmod_q.put([dst, (int(time.time()), int(job["lmod"]))]) # legit api sware 2 me mum diff --git a/copyparty/util.py b/copyparty/util.py index 52fc0fd0..2cbdb431 100644 --- a/copyparty/util.py +++ b/copyparty/util.py @@ -16,7 +16,7 @@ import mimetypes import contextlib import subprocess as sp # nosec -from .__init__ import PY2, WINDOWS +from .__init__ import PY2, WINDOWS, ANYWIN from .stolen import surrogateescape FAKE_MP = False @@ -580,8 +580,8 @@ def sanitize_fn(fn, ok=""): if "/" not in ok: fn = fn.replace("\\", "/").split("/")[-1] - if WINDOWS: - for bad, good in [x for x in [ + if ANYWIN: + remap = [ ["<", "<"], [">", ">"], [":", ":"], @@ -591,7 +591,8 @@ def sanitize_fn(fn, ok=""): ["|", "|"], ["?", "?"], ["*", "*"], - ] if x[0] not in ok]: + ] + for bad, good in [x for x in remap if x[0] not in ok]: fn = fn.replace(bad, good) bad = ["con", "prn", "aux", "nul"] diff --git a/scripts/sfx.py b/scripts/sfx.py index 22f9e900..2c9e4002 100644 --- a/scripts/sfx.py +++ b/scripts/sfx.py @@ -26,7 +26,7 @@ CKSUM = None STAMP = None PY2 = sys.version_info[0] == 2 -WINDOWS = sys.platform == "win32" +WINDOWS = sys.platform in ["win32", "msys"] sys.dont_write_bytecode = True me = os.path.abspath(os.path.realpath(__file__)) cpp = None