diff --git a/copyparty/__init__.py b/copyparty/__init__.py index af43885c..1bca4b9c 100644 --- a/copyparty/__init__.py +++ b/copyparty/__init__.py @@ -16,8 +16,6 @@ except: TYPE_CHECKING = False if True: - from types import ModuleType - from typing import Any, Callable, Optional PY2 = sys.version_info < (3,) @@ -110,7 +108,6 @@ RES = set(zs.strip().split("\n")) class EnvParams(object): def __init__(self) -> None: - self.pkg: Optional[ModuleType] = None self.t0 = time.time() self.mod = "" self.cfg = "" diff --git a/copyparty/__main__.py b/copyparty/__main__.py index 4d61450d..72e3ccfe 100644 --- a/copyparty/__main__.py +++ b/copyparty/__main__.py @@ -218,8 +218,6 @@ def init_E(EE: EnvParams) -> None: raise Exception("could not find a writable path for config") - assert __package__ # !rm - E.pkg = sys.modules[__package__] E.mod = os.path.dirname(os.path.realpath(__file__)) if E.mod.endswith("__init__"): E.mod = os.path.dirname(E.mod) diff --git a/copyparty/util.py b/copyparty/util.py index 1e99092d..33f79ba3 100644 --- a/copyparty/util.py +++ b/copyparty/util.py @@ -3622,10 +3622,10 @@ def stat_resource(E: EnvParams, name: str): return None -def _find_impresource(E: EnvParams, name: str): +def _find_impresource(pkg: types.ModuleType, name: str): assert impresources # !rm try: - files = impresources.files(E.pkg) + files = impresources.files(pkg) except ImportError: return None @@ -3635,7 +3635,7 @@ def _find_impresource(E: EnvParams, name: str): _rescache_has = {} -def _has_resource(E: EnvParams, name: str): +def _has_resource(name: str): try: return _rescache_has[name] except: @@ -3644,14 +3644,17 @@ def _has_resource(E: EnvParams, name: str): if len(_rescache_has) > 999: _rescache_has.clear() + assert __package__ # !rm + pkg = sys.modules[__package__] + if impresources: - res = _find_impresource(E, name) + res = _find_impresource(pkg, name) if res and res.is_file(): _rescache_has[name] = True return True if pkg_resources: - if _pkg_resource_exists(E.pkg.__name__, name): + if _pkg_resource_exists(pkg.__name__, name): _rescache_has[name] = True return True @@ -3660,14 +3663,15 @@ def _has_resource(E: EnvParams, name: str): def has_resource(E: EnvParams, name: str): - return _has_resource(E, name) or os.path.exists(os.path.join(E.mod, name)) + return _has_resource(name) or os.path.exists(os.path.join(E.mod, name)) def load_resource(E: EnvParams, name: str, mode="rb") -> IO[bytes]: enc = None if "b" in mode else "utf-8" if impresources: - res = _find_impresource(E, name) + assert __package__ # !rm + res = _find_impresource(sys.modules[__package__], name) if res and res.is_file(): if enc: return res.open(mode, encoding=enc) @@ -3676,8 +3680,10 @@ def load_resource(E: EnvParams, name: str, mode="rb") -> IO[bytes]: return res.open(mode) if pkg_resources: - if _pkg_resource_exists(E.pkg.__name__, name): - stream = pkg_resources.resource_stream(E.pkg.__name__, name) + assert __package__ # !rm + pkg = sys.modules[__package__] + if _pkg_resource_exists(pkg.__name__, name): + stream = pkg_resources.resource_stream(pkg.__name__, name) if enc: stream = codecs.getreader(enc)(stream) return stream diff --git a/scripts/make-pyz.sh b/scripts/make-pyz.sh index 55027cf6..5164e91e 100755 --- a/scripts/make-pyz.sh +++ b/scripts/make-pyz.sh @@ -11,6 +11,15 @@ gtar=$(command -v gtar || command -v gnutar) || true realpath() { grealpath "$@"; } } +tmv() { + touch -r "$1" t + mv t "$1" +} +ised() { + sed -r "$1" <"$2" >t + tmv "$2" +} + targs=(--owner=1000 --group=1000) [ "$OSTYPE" = msys ] && targs=() @@ -35,6 +44,12 @@ cd pyz cp -pR ../sfx/{copyparty,partftpy} . cp -pR ../sfx/{ftp,j2}/* . +true && { + rm -rf copyparty/web/mde.* copyparty/web/deps/easymde* + echo h > copyparty/web/mde.html + ised '/edit2">edit \(fancy/d' copyparty/web/md.html +} + ts=$(date -u +%s) hts=$(date -u +%Y-%m%d-%H%M%S) ver="$(cat ../sfx/ver)" diff --git a/scripts/test/smoketest.py b/scripts/test/smoketest.py index 95ebc40b..7dbc3dad 100644 --- a/scripts/test/smoketest.py +++ b/scripts/test/smoketest.py @@ -98,6 +98,7 @@ def tc1(vflags): args = [ "-q", + "-j0", "-p4321", "-e2dsa", "-e2tsr",