mirror of
https://github.com/9001/copyparty.git
synced 2025-08-17 17:12:13 -06:00
more cleanup
This commit is contained in:
parent
f4a3bbd237
commit
4e5a323c62
|
@ -32,7 +32,7 @@ try:
|
|||
except:
|
||||
HAVE_SSL = False
|
||||
|
||||
printed = ""
|
||||
printed = []
|
||||
|
||||
|
||||
class RiceFormatter(argparse.HelpFormatter):
|
||||
|
@ -65,10 +65,8 @@ class Dodge11874(RiceFormatter):
|
|||
|
||||
|
||||
def lprint(*a, **ka):
|
||||
global printed
|
||||
|
||||
txt = " ".join(unicode(x) for x in a) + ka.get("end", "\n")
|
||||
printed += txt
|
||||
printed.append(txt)
|
||||
if not VT100:
|
||||
txt = ansi_re.sub("", txt)
|
||||
|
||||
|
@ -722,7 +720,7 @@ def main(argv=None):
|
|||
|
||||
# signal.signal(signal.SIGINT, sighandler)
|
||||
|
||||
SvcHub(al, argv, printed).run()
|
||||
SvcHub(al, argv, "".join(printed)).run()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -160,15 +160,15 @@ class TcpSrv(object):
|
|||
continue
|
||||
|
||||
if ln == ln.lstrip():
|
||||
dev = re.split(r'[: ]', ln)[0]
|
||||
dev = re.split(r"[: ]", ln)[0]
|
||||
|
||||
if "UP" in re.split(r'[<>, \t]', ln):
|
||||
if "UP" in re.split(r"[<>, \t]", ln):
|
||||
up = True
|
||||
|
||||
m = re.match(r'^\s+inet\s+([^ ]+)', ln)
|
||||
|
||||
m = re.match(r"^\s+inet\s+([^ ]+)", ln)
|
||||
if m:
|
||||
ip = m.group(1)
|
||||
|
||||
|
||||
return eps
|
||||
|
||||
def ips_linux(self):
|
||||
|
|
|
@ -9,7 +9,6 @@ import hashlib
|
|||
import threading
|
||||
import subprocess as sp
|
||||
|
||||
from .__init__ import PY2, unicode
|
||||
from .util import fsenc, vsplit, statdir, runcmd, Queue, Cooldown, BytesIO, min_ex
|
||||
from .bos import bos
|
||||
from .mtag import HAVE_FFMPEG, HAVE_FFPROBE, ffprobe
|
||||
|
@ -39,7 +38,7 @@ try:
|
|||
pass
|
||||
|
||||
try:
|
||||
import pillow_avif
|
||||
import pillow_avif # noqa: F401 # pylint: disable=unused-import
|
||||
|
||||
HAVE_AVIF = True
|
||||
except:
|
||||
|
@ -398,7 +397,7 @@ class ThumbSrv(object):
|
|||
|
||||
def _run_ff(self, cmd):
|
||||
# self.log((b" ".join(cmd)).decode("utf-8"))
|
||||
ret, sout, serr = runcmd(cmd, timeout=self.args.th_convt)
|
||||
ret, _, serr = runcmd(cmd, timeout=self.args.th_convt)
|
||||
if not ret:
|
||||
return
|
||||
|
||||
|
@ -583,7 +582,7 @@ class ThumbSrv(object):
|
|||
if age > maxage:
|
||||
with self.mutex:
|
||||
safe = True
|
||||
for k in self.busy.keys():
|
||||
for k in self.busy:
|
||||
if k.lower().replace("\\", "/").startswith(cmp):
|
||||
safe = False
|
||||
break
|
||||
|
|
|
@ -38,6 +38,8 @@ class U2idx(object):
|
|||
self.log("your python does not have sqlite3; searching will be disabled")
|
||||
return
|
||||
|
||||
self.active_id = None
|
||||
self.active_cur = None
|
||||
self.cur = {}
|
||||
self.mem_cur = sqlite3.connect(":memory:")
|
||||
self.mem_cur.execute(r"create table a (b text)")
|
||||
|
|
|
@ -22,7 +22,6 @@ from .util import (
|
|||
Queue,
|
||||
ProgressPrinter,
|
||||
SYMTIME,
|
||||
fsdec,
|
||||
fsenc,
|
||||
absreal,
|
||||
sanitize_fn,
|
||||
|
@ -948,7 +947,7 @@ class Up2k(object):
|
|||
in_progress.pop(w)
|
||||
n_done += 1
|
||||
|
||||
for w in to_delete.keys():
|
||||
for w in to_delete:
|
||||
q = "delete from mt where w = ? and +k = 't:mtp'"
|
||||
cur.execute(q, (w,))
|
||||
|
||||
|
|
|
@ -21,16 +21,16 @@ import subprocess as sp # nosec
|
|||
from datetime import datetime
|
||||
from collections import Counter
|
||||
|
||||
from .__init__ import PY2, WINDOWS, ANYWIN, VT100, unicode
|
||||
from .__init__ import PY2, WINDOWS, ANYWIN, VT100
|
||||
from .stolen import surrogateescape
|
||||
|
||||
FAKE_MP = False
|
||||
|
||||
try:
|
||||
if FAKE_MP:
|
||||
import multiprocessing.dummy as mp # noqa: F401
|
||||
import multiprocessing.dummy as mp # noqa: F401 # pylint: disable=unused-import
|
||||
else:
|
||||
import multiprocessing as mp # noqa: F401
|
||||
import multiprocessing as mp # noqa: F401 # pylint: disable=unused-import
|
||||
except ImportError:
|
||||
# support jython
|
||||
mp = None
|
||||
|
@ -38,13 +38,13 @@ except ImportError:
|
|||
if not PY2:
|
||||
from urllib.parse import unquote_to_bytes as unquote
|
||||
from urllib.parse import quote_from_bytes as quote
|
||||
from queue import Queue
|
||||
from io import BytesIO
|
||||
from queue import Queue # pylint: disable=unused-import
|
||||
from io import BytesIO # pylint: disable=unused-import
|
||||
else:
|
||||
from urllib import unquote # pylint: disable=no-name-in-module
|
||||
from urllib import quote # pylint: disable=no-name-in-module
|
||||
from Queue import Queue # pylint: disable=import-error,no-name-in-module
|
||||
from StringIO import StringIO as BytesIO
|
||||
from StringIO import StringIO as BytesIO # pylint: disable=unused-import
|
||||
|
||||
|
||||
try:
|
||||
|
@ -114,16 +114,22 @@ MIMES = {
|
|||
"m4a": "audio/mp4",
|
||||
"jpg": "image/jpeg",
|
||||
}
|
||||
for ln in """text css html csv
|
||||
|
||||
|
||||
def _add_mimes():
|
||||
for ln in """text css html csv
|
||||
application json wasm xml pdf rtf zip
|
||||
image webp jpeg png gif bmp
|
||||
audio aac ogg wav
|
||||
video webm mp4 mpeg
|
||||
font woff woff2 otf ttf
|
||||
""".splitlines():
|
||||
k, vs = ln.split(" ", 1)
|
||||
for v in vs.strip().split():
|
||||
MIMES[v] = "{}/{}".format(k, v)
|
||||
k, vs = ln.split(" ", 1)
|
||||
for v in vs.strip().split():
|
||||
MIMES[v] = "{}/{}".format(k, v)
|
||||
|
||||
|
||||
_add_mimes()
|
||||
|
||||
|
||||
REKOBO_KEY = {
|
||||
|
@ -175,8 +181,8 @@ class Cooldown(object):
|
|||
now = time.time()
|
||||
|
||||
ret = False
|
||||
v = self.hist.get(key, 0)
|
||||
if now - v > self.maxage:
|
||||
pv = self.hist.get(key, 0)
|
||||
if now - pv > self.maxage:
|
||||
self.hist[key] = now
|
||||
ret = True
|
||||
|
||||
|
@ -395,7 +401,7 @@ def nuprint(msg):
|
|||
def rice_tid():
|
||||
tid = threading.current_thread().ident
|
||||
c = sunpack(b"B" * 5, spack(b">Q", tid)[-5:])
|
||||
return "".join("\033[1;37;48;5;{}m{:02x}".format(x, x) for x in c) + "\033[0m"
|
||||
return "".join("\033[1;37;48;5;{0}m{0:02x}".format(x) for x in c) + "\033[0m"
|
||||
|
||||
|
||||
def trace(*args, **kwargs):
|
||||
|
@ -616,6 +622,9 @@ class MultipartParser(object):
|
|||
r'^content-disposition:(?: *|.*; *)filename="(.*)"', re.IGNORECASE
|
||||
)
|
||||
|
||||
self.boundary = None
|
||||
self.gen = None
|
||||
|
||||
def _read_header(self):
|
||||
"""
|
||||
returns [fieldname, filename] after eating a block of multipart headers
|
||||
|
@ -1101,17 +1110,17 @@ def s3enc(mem_cur, rd, fn):
|
|||
ret.append(v)
|
||||
except:
|
||||
ret.append("//" + w8b64enc(v))
|
||||
# self.log("mojien/{} [{}] {}".format(k, v, ret[-1][2:]))
|
||||
# self.log("mojien [{}] {}".format(v, ret[-1][2:]))
|
||||
|
||||
return tuple(ret)
|
||||
|
||||
|
||||
def s3dec(rd, fn):
|
||||
ret = []
|
||||
for k, v in [["d", rd], ["f", fn]]:
|
||||
for v in [rd, fn]:
|
||||
if v.startswith("//"):
|
||||
ret.append(w8b64dec(v[2:]))
|
||||
# self.log("mojide/{} [{}] {}".format(k, ret[-1], v[2:]))
|
||||
# self.log("mojide [{}] {}".format(ret[-1], v[2:]))
|
||||
else:
|
||||
ret.append(v)
|
||||
|
||||
|
|
Loading…
Reference in a new issue