diff --git a/copyparty/authsrv.py b/copyparty/authsrv.py index 3d92b7e1..01b79884 100644 --- a/copyparty/authsrv.py +++ b/copyparty/authsrv.py @@ -228,21 +228,19 @@ class VFS(object): for f in [{"vp": v, "ap": a, "st": n[1]} for v, a, n in files]: yield f - def user_tree(self, uname, readable=False, writable=False, admin=False): - ret = [] - opt1 = readable and (uname in self.uread or "*" in self.uread) - opt2 = writable and (uname in self.uwrite or "*" in self.uwrite) - if admin: - if opt1 and opt2: - ret.append(self.vpath) - else: - if opt1 or opt2: - ret.append(self.vpath) + def user_tree(self, uname, readable, writable, admin): + is_readable = False + if uname in self.uread or "*" in self.uread: + readable.append(self.vpath) + is_readable = True + + if uname in self.uwrite or "*" in self.uwrite: + writable.append(self.vpath) + if is_readable: + admin.append(self.vpath) for _, vn in sorted(self.nodes.items()): - ret.extend(vn.user_tree(uname, readable, writable, admin)) - - return ret + vn.user_tree(uname, readable, writable, admin) class AuthSrv(object): diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index 989f52d4..1554956f 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -153,10 +153,8 @@ class HttpCli(object): pwd = uparam.get("pw") self.uname = self.auth.iuser.get(pwd, "*") - if self.uname: - self.rvol = self.auth.vfs.user_tree(self.uname, readable=True) - self.wvol = self.auth.vfs.user_tree(self.uname, writable=True) - self.avol = self.auth.vfs.user_tree(self.uname, True, True, True) + self.rvol, self.wvol, self.avol = [[], [], []] + self.auth.vfs.user_tree(self.uname, self.rvol, self.wvol, self.avol) ua = self.headers.get("user-agent", "") self.is_rclone = ua.startswith("rclone/") diff --git a/scripts/profile.py b/scripts/profile.py new file mode 100644 index 00000000..baf0da2f --- /dev/null +++ b/scripts/profile.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 + +import sys + +sys.path.insert(0, ".") +cmd = sys.argv[1] + +if cmd == "cpp": + from copyparty.__main__ import main + + argv = ["__main__", "-v", "srv::r", "-v", "../../yt:yt:r"] + main(argv=argv) + +elif cmd == "test": + from unittest import main + + argv = ["__main__", "discover", "-s", "tests"] + main(module=None, argv=argv) + +else: + raise Exception() + +# import dis; print(dis.dis(main)) + + +# macos: +# option1) python3.9 -m pip install --user -U vmprof==0.4.9 +# option2) python3.9 -m pip install --user -U https://github.com/vmprof/vmprof-python/archive/refs/heads/master.zip +# +# python -m vmprof -o prof --lines ./scripts/profile.py test + +# linux: ~/.local/bin/vmprofshow prof tree | grep -vF '[1m 0.' +# macos: ~/Library/Python/3.9/bin/vmprofshow prof tree | grep -vF '[1m 0.' +# win: %appdata%\..\Roaming\Python\Python39\Scripts\vmprofshow.exe prof tree diff --git a/tests/test_httpcli.py b/tests/test_httpcli.py index 7d4edcc4..7e740763 100644 --- a/tests/test_httpcli.py +++ b/tests/test_httpcli.py @@ -10,12 +10,11 @@ import pprint import tarfile import tempfile import unittest - from argparse import Namespace -from copyparty.authsrv import AuthSrv -from copyparty.httpcli import HttpCli from tests import util as tu +from copyparty.authsrv import AuthSrv +from copyparty.httpcli import HttpCli def hdr(query): diff --git a/tests/test_vfs.py b/tests/test_vfs.py index 633eca35..de15a91e 100644 --- a/tests/test_vfs.py +++ b/tests/test_vfs.py @@ -7,13 +7,12 @@ import json import shutil import tempfile import unittest - from textwrap import dedent from argparse import Namespace -from copyparty.authsrv import AuthSrv -from copyparty import util from tests import util as tu +from copyparty.authsrv import AuthSrv +from copyparty import util class Cfg(Namespace): diff --git a/tests/util.py b/tests/util.py index da5537b9..1a24ac2e 100644 --- a/tests/util.py +++ b/tests/util.py @@ -1,17 +1,36 @@ import os +import sys import time import shutil import jinja2 import tempfile +import platform import subprocess as sp -from copyparty.util import Unrecv +WINDOWS = platform.system() == "Windows" +ANYWIN = WINDOWS or sys.platform in ["msys"] +MACOS = platform.system() == "Darwin" J2_ENV = jinja2.Environment(loader=jinja2.BaseLoader) J2_FILES = J2_ENV.from_string("{{ files|join('\n') }}") +def nah(*a, **ka): + return False + + +if MACOS: + import posixpath + + posixpath.islink = nah + os.path.islink = nah + # 25% faster; until any tests do symlink stuff + + +from copyparty.util import Unrecv + + def runcmd(*argv): p = sp.Popen(argv, stdout=sp.PIPE, stderr=sp.PIPE) stdout, stderr = p.communicate()