mirror of
https://github.com/9001/copyparty.git
synced 2025-10-03 09:49:29 +02:00
add safety profiles + improve helptext + speed
This commit is contained in:
parent
438384425a
commit
eb3fa5aa6b
5 changed files with 225 additions and 26 deletions
|
@ -21,37 +21,52 @@ def uh(top):
|
|||
if os.path.exists(top + "/uh"):
|
||||
return
|
||||
|
||||
libs = "typing|types|collections\.abc"
|
||||
ptn = re.compile(r"^(\s*)(from (?:{0}) import |import (?:{0})\b).*".format(libs))
|
||||
|
||||
# pr("building support for your python ver")
|
||||
pr("unhinting")
|
||||
files = []
|
||||
for (dp, _, fns) in os.walk(top):
|
||||
for fn in fns:
|
||||
if not fn.endswith(".py"):
|
||||
continue
|
||||
|
||||
pr(".")
|
||||
fp = os.path.join(dp, fn)
|
||||
cs = strip_file_to_string(fp, no_ast=True, to_empty=True)
|
||||
files.append(fp)
|
||||
|
||||
# remove expensive imports too
|
||||
lns = []
|
||||
for ln in cs.split("\n"):
|
||||
m = ptn.match(ln)
|
||||
if m:
|
||||
ln = m.group(1) + "raise Exception()"
|
||||
try:
|
||||
import multiprocessing as mp
|
||||
|
||||
lns.append(ln)
|
||||
|
||||
cs = "\n".join(lns)
|
||||
with open(fp, "wb") as f:
|
||||
f.write(cs.encode("utf-8"))
|
||||
with mp.Pool(os.cpu_count()) as pool:
|
||||
pool.map(uh1, files)
|
||||
except Exception as ex:
|
||||
print("\nnon-mp fallback due to {}\n".format(ex))
|
||||
for fp in files:
|
||||
uh1(fp)
|
||||
|
||||
pr("k\n\n")
|
||||
with open(top + "/uh", "wb") as f:
|
||||
f.write(b"a")
|
||||
|
||||
|
||||
def uh1(fp):
|
||||
pr(".")
|
||||
cs = strip_file_to_string(fp, no_ast=True, to_empty=True)
|
||||
|
||||
libs = "typing|types|collections\.abc"
|
||||
ptn = re.compile(r"^(\s*)(from (?:{0}) import |import (?:{0})\b).*".format(libs))
|
||||
|
||||
# remove expensive imports too
|
||||
lns = []
|
||||
for ln in cs.split("\n"):
|
||||
m = ptn.match(ln)
|
||||
if m:
|
||||
ln = m.group(1) + "raise Exception()"
|
||||
|
||||
lns.append(ln)
|
||||
|
||||
cs = "\n".join(lns)
|
||||
with open(fp, "wb") as f:
|
||||
f.write(cs.encode("utf-8"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
uh(".")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue