From 74a3f976718b98d2dcae4f2dc6a7cb0f2b766bbd Mon Sep 17 00:00:00 2001 From: ed Date: Wed, 27 Jul 2022 00:15:49 +0200 Subject: [PATCH] cleanup + bump deps --- .gitignore | 3 ++- copyparty/authsrv.py | 4 ++-- copyparty/mtag.py | 6 +++--- scripts/deps-docker/Dockerfile | 4 ++-- tests/test_httpcli.py | 36 ++-------------------------------- tests/test_vfs.py | 34 ++------------------------------ tests/util.py | 35 +++++++++++++++++++++++++++++++++ 7 files changed, 48 insertions(+), 74 deletions(-) diff --git a/.gitignore b/.gitignore index 4015ad0e..70c9a96a 100644 --- a/.gitignore +++ b/.gitignore @@ -8,8 +8,9 @@ copyparty.egg-info/ buildenv/ build/ dist/ -sfx/ py2/ +sfx/ +unt/ .venv/ # ide diff --git a/copyparty/authsrv.py b/copyparty/authsrv.py index 185767d8..1f0cf16d 100644 --- a/copyparty/authsrv.py +++ b/copyparty/authsrv.py @@ -87,7 +87,7 @@ class Lim(object): self.dfl = 0 # free disk space limit self.dft = 0 # last-measured time - self.dfv: Optional[int] = 0 # currently free + self.dfv = 0 # currently free self.smin = 0 # filesize min self.smax = 0 # filesize max @@ -150,7 +150,7 @@ class Lim(object): if self.dft < time.time(): self.dft = int(time.time()) + 300 - self.dfv = get_df(abspath)[0] + self.dfv = get_df(abspath)[0] or 0 for j in list(self.reg.values()) if self.reg else []: self.dfv -= int(j["size"] / len(j["hash"]) * len(j["need"])) diff --git a/copyparty/mtag.py b/copyparty/mtag.py index b291a2fd..9467ddaf 100644 --- a/copyparty/mtag.py +++ b/copyparty/mtag.py @@ -437,10 +437,10 @@ class MTag(object): return r1 def get_mutagen(self, abspath: str) -> dict[str, Union[str, float]]: - ret: dict[str, Union[str, float]] = {} + ret: dict[str, tuple[int, Any]] = {} if not bos.path.isfile(abspath): - return ret + return {} import mutagen @@ -453,7 +453,7 @@ class MTag(object): sz = bos.path.getsize(abspath) try: - ret = {".q": (0, int((sz / md.info.length) / 128))} + ret[".q"] = (0, int((sz / md.info.length) / 128)) except: pass diff --git a/scripts/deps-docker/Dockerfile b/scripts/deps-docker/Dockerfile index 97e4b7aa..f2784da0 100644 --- a/scripts/deps-docker/Dockerfile +++ b/scripts/deps-docker/Dockerfile @@ -2,9 +2,9 @@ FROM alpine:3.16 WORKDIR /z ENV ver_asmcrypto=5b994303a9d3e27e0915f72a10b6c2c51535a4dc \ ver_hashwasm=4.9.0 \ - ver_marked=4.0.17 \ + ver_marked=4.0.18 \ ver_mde=2.16.1 \ - ver_codemirror=5.65.6 \ + ver_codemirror=5.65.7 \ ver_fontawesome=5.13.0 \ ver_zopfli=1.0.3 diff --git a/tests/test_httpcli.py b/tests/test_httpcli.py index ba2eb62a..5b61edf0 100644 --- a/tests/test_httpcli.py +++ b/tests/test_httpcli.py @@ -10,9 +10,10 @@ import pprint import tarfile import tempfile import unittest -from argparse import Namespace from tests import util as tu +from tests.util import Cfg + from copyparty.authsrv import AuthSrv from copyparty.httpcli import HttpCli @@ -22,39 +23,6 @@ def hdr(query): return h.format(query).encode("utf-8") -class Cfg(Namespace): - def __init__(self, a=None, v=None, c=None): - ka = {} - - ex = "e2d e2ds e2dsa e2t e2ts e2tsr ed emp force_js ihead no_acode no_athumb no_del no_logues no_mv no_readme no_robots no_scandir no_thumb no_vthumb no_zip nw" - ka.update(**{k: False for k in ex.split()}) - - ex = "nih no_rescan no_sendfile no_voldump" - ka.update(**{k: True for k in ex.split()}) - - ex = "css_browser hist js_browser no_hash no_idx" - ka.update(**{k: None for k in ex.split()}) - - ex = "re_maxage rproxy rsp_slp s_wr_slp theme themes turbo" - ka.update(**{k: 0 for k in ex.split()}) - - ex = "doctitle favico html_head mth textfiles" - ka.update(**{k: "" for k in ex.split()}) - - super(Cfg, self).__init__( - a=a or [], - v=v or [], - c=c, - s_wr_sz=512 * 1024, - unpost=600, - mtp=[], - mte="a", - lang="eng", - logout=573, - **ka - ) - - class TestHttpCli(unittest.TestCase): def setUp(self): self.td = tu.get_ramdisk() diff --git a/tests/test_vfs.py b/tests/test_vfs.py index 4818d180..3ff4c1a9 100644 --- a/tests/test_vfs.py +++ b/tests/test_vfs.py @@ -8,44 +8,14 @@ import shutil import tempfile import unittest from textwrap import dedent -from argparse import Namespace from tests import util as tu +from tests.util import Cfg + from copyparty.authsrv import AuthSrv, VFS from copyparty import util -class Cfg(Namespace): - def __init__(self, a=None, v=None, c=None): - ex = "nw e2d e2ds e2dsa e2t e2ts e2tsr no_logues no_readme no_acode force_js no_robots no_thumb no_athumb no_vthumb" - ex = {k: False for k in ex.split()} - ex2 = { - "mtp": [], - "mte": "a", - "mth": "", - "doctitle": "", - "html_head": "", - "hist": None, - "no_idx": None, - "no_hash": None, - "js_browser": None, - "css_browser": None, - "no_voldump": True, - "re_maxage": 0, - "rproxy": 0, - "rsp_slp": 0, - "s_wr_slp": 0, - "s_wr_sz": 512 * 1024, - "lang": "eng", - "theme": 0, - "themes": 0, - "turbo": 0, - "logout": 573, - } - ex.update(ex2) - super(Cfg, self).__init__(a=a or [], v=v or [], c=c, **ex) - - class TestVFS(unittest.TestCase): def setUp(self): self.td = tu.get_ramdisk() diff --git a/tests/util.py b/tests/util.py index 92ecaa88..0135250f 100644 --- a/tests/util.py +++ b/tests/util.py @@ -7,6 +7,7 @@ import threading import tempfile import platform import subprocess as sp +from argparse import Namespace WINDOWS = platform.system() == "Windows" @@ -89,6 +90,40 @@ def get_ramdisk(): return subdir(ret) +class Cfg(Namespace): + def __init__(self, a=None, v=None, c=None): + ka = {} + + ex = "e2d e2ds e2dsa e2t e2ts e2tsr e2v e2vu e2vp ed emp force_js ihead no_acode no_athumb no_del no_logues no_mv no_readme no_robots no_scandir no_thumb no_vthumb no_zip nid nih nw" + ka.update(**{k: False for k in ex.split()}) + + ex = "no_rescan no_sendfile no_voldump" + ka.update(**{k: True for k in ex.split()}) + + ex = "css_browser hist js_browser no_hash no_idx" + ka.update(**{k: None for k in ex.split()}) + + ex = "re_maxage rproxy rsp_slp s_wr_slp theme themes turbo df" + ka.update(**{k: 0 for k in ex.split()}) + + ex = "doctitle favico html_head mth textfiles" + ka.update(**{k: "" for k in ex.split()}) + + super(Cfg, self).__init__( + a=a or [], + v=v or [], + c=c, + s_wr_sz=512 * 1024, + unpost=600, + u2sort="s", + mtp=[], + mte="a", + lang="eng", + logout=573, + **ka + ) + + class NullBroker(object): def say(*args): pass