diff --git a/.vscode/settings.json b/.vscode/settings.json index 53c2d963..e6adbdc0 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -33,6 +33,17 @@ "test_*.py" ], "python.linting.pylintEnabled": true, - "python.linting.enabled": true, - "python.pythonPath": "/usr/bin/python3", + "python.linting.flake8Enabled": true, + "python.linting.banditEnabled": true, + "python.linting.flake8Args": [ + "--max-line-length=120", + "--ignore=E722,F405,E203,W503,W293", + ], + "python.formatting.provider": "black", + "editor.formatOnSave": true, + // + // things you may wanna edit: + // + "python.pythonPath": ".env/bin/python", + //"python.linting.enabled": true, } \ No newline at end of file diff --git a/README.md b/README.md index af049867..038d2e65 100644 --- a/README.md +++ b/README.md @@ -25,3 +25,15 @@ turn your phone or raspi into a portable file server with resumable uploads/down * [ ] accounts conclusion: don't bother + +## dependencies + +* jinja2 + * markupsafe + +## dev env + + python3 -v venv .env + . .env/bin/activate + pip install jinja2 # dependencies + pip install black bandit pylint flake8 # vscode tooling diff --git a/copyparty/__main__.py b/copyparty/__main__.py index b7932c5b..6bfa045a 100644 --- a/copyparty/__main__.py +++ b/copyparty/__main__.py @@ -14,8 +14,8 @@ import threading from textwrap import dedent import multiprocessing as mp -from .__version__ import * -from .tcpsrv import * +from .__version__ import S_VERSION, S_BUILD_DT +from .tcpsrv import TcpSrv class RiceFormatter(argparse.HelpFormatter): @@ -41,7 +41,7 @@ def main(): try: # support vscode debugger (bonus: same behavior as on windows) mp.set_start_method("spawn", True) - except: + except AttributeError: # py2.7 probably pass diff --git a/copyparty/authsrv.py b/copyparty/authsrv.py index e4a752e9..4f09601e 100644 --- a/copyparty/authsrv.py +++ b/copyparty/authsrv.py @@ -5,7 +5,7 @@ from __future__ import print_function import os import threading -from .__init__ import * +from .__init__ import PY2 from .util import undot @@ -21,8 +21,8 @@ class VFS(object): def add(self, src, dst): """get existing, or add new path to the vfs""" - assert not src.endswith("/") - assert not dst.endswith("/") + assert not src.endswith("/") # nosec + assert not dst.endswith("/") # nosec if "/" in dst: # requires breadth-first population (permissions trickle down) @@ -93,7 +93,7 @@ class VFS(object): for name in virt_all: try: real.remove(name) - except: + except ValueError: pass absreal = [] @@ -227,14 +227,14 @@ class AuthSrv(object): if not mount: # -h says our defaults are CWD at root and read/write for everyone vfs = VFS(os.path.abspath("."), "", ["*"], ["*"]) - elif not "" in mount: + elif "" not in mount: # there's volumes but no root; make root inaccessible vfs = VFS(os.path.abspath("."), "", [], []) maxdepth = 0 for dst in sorted(mount.keys(), key=lambda x: (x.count("/"), len(x))): depth = dst.count("/") - assert maxdepth <= depth + assert maxdepth <= depth # nosec maxdepth = depth if dst == "": diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index 4184baad..02c95639 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -2,13 +2,12 @@ # coding: utf-8 from __future__ import print_function +import os import time -import hashlib import mimetypes -import jinja2 -from .__init__ import * -from .util import * +from .__init__ import E, PY2 +from .util import * # noqa # pylint: disable=unused-wildcard-import if not PY2: unicode = str @@ -72,7 +71,7 @@ class HttpCli(object): # split req into vpath + args args = {} - if not "?" in self.req: + if "?" not in self.req: vpath = undot(self.req) else: vpath, arglist = self.req.split("?", 1) @@ -164,7 +163,7 @@ class HttpCli(object): try: if self.headers["expect"].lower() == "100-continue": self.s.send(b"HTTP/1.1 100 Continue\r\n\r\n") - except: + except KeyError: pass self.parser = MultipartParser(self.log, self.sr, self.headers) @@ -190,7 +189,7 @@ class HttpCli(object): msg = u"login ok" else: msg = u"naw dude" - pwd = u"x" + pwd = u"x" # nosec h = ["Set-Cookie: cppwd={}; Path=/".format(pwd)] html = u'