mirror of
https://github.com/9001/copyparty.git
synced 2025-08-16 08:32:13 -06:00
pkgres: fix multiprocessing
This commit is contained in:
parent
3ccbcf6185
commit
c398553748
|
@ -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 = ""
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)"
|
||||
|
|
|
@ -98,6 +98,7 @@ def tc1(vflags):
|
|||
|
||||
args = [
|
||||
"-q",
|
||||
"-j0",
|
||||
"-p4321",
|
||||
"-e2dsa",
|
||||
"-e2tsr",
|
||||
|
|
Loading…
Reference in a new issue