mirror of
https://github.com/9001/copyparty.git
synced 2025-08-17 09:02:15 -06:00
pickle needs this ;_;
This commit is contained in:
parent
2cef5365f7
commit
c5db7c1a0c
|
@ -2,7 +2,8 @@
|
||||||
# coding: latin-1
|
# coding: latin-1
|
||||||
from __future__ import print_function, unicode_literals
|
from __future__ import print_function, unicode_literals
|
||||||
|
|
||||||
import os, sys, time, shutil, threading, tarfile, hashlib, platform, tempfile, traceback
|
import re, os, sys, time, shutil, signal, threading, tarfile, hashlib, platform, tempfile, traceback
|
||||||
|
import subprocess as sp
|
||||||
|
|
||||||
"""
|
"""
|
||||||
run me with any version of python, i will unpack and run copyparty
|
run me with any version of python, i will unpack and run copyparty
|
||||||
|
@ -31,16 +32,16 @@ sys.dont_write_bytecode = True
|
||||||
me = os.path.abspath(os.path.realpath(__file__))
|
me = os.path.abspath(os.path.realpath(__file__))
|
||||||
|
|
||||||
|
|
||||||
def eprint(*args, **kwargs):
|
def eprint(*a, **ka):
|
||||||
kwargs["file"] = sys.stderr
|
ka["file"] = sys.stderr
|
||||||
print(*args, **kwargs)
|
print(*a, **ka)
|
||||||
|
|
||||||
|
|
||||||
def msg(*args, **kwargs):
|
def msg(*a, **ka):
|
||||||
if args:
|
if a:
|
||||||
args = ["[SFX]", args[0]] + list(args[1:])
|
a = ["[SFX]", a[0]] + list(a[1:])
|
||||||
|
|
||||||
eprint(*args, **kwargs)
|
eprint(*a, **ka)
|
||||||
|
|
||||||
|
|
||||||
# skip 1
|
# skip 1
|
||||||
|
@ -155,6 +156,9 @@ def encode(data, size, cksum, ver, ts):
|
||||||
skip = True
|
skip = True
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if ln.strip().startswith("# fmt: "):
|
||||||
|
continue
|
||||||
|
|
||||||
unpk += ln + "\n"
|
unpk += ln + "\n"
|
||||||
|
|
||||||
for k, v in [
|
for k, v in [
|
||||||
|
@ -307,32 +311,29 @@ def get_payload():
|
||||||
fpos = ofs + len(ptn) - 3
|
fpos = ofs + len(ptn) - 3
|
||||||
f.seek(fpos)
|
f.seek(fpos)
|
||||||
dpos = 0
|
dpos = 0
|
||||||
leftovers = b""
|
rem = b""
|
||||||
while True:
|
while True:
|
||||||
rbuf = f.read(1024 * 32)
|
rbuf = f.read(1024 * 32)
|
||||||
if rbuf:
|
if rbuf:
|
||||||
buf = leftovers + rbuf
|
buf = rem + rbuf
|
||||||
ofs = buf.rfind(b"\n")
|
ofs = buf.rfind(b"\n")
|
||||||
if len(buf) <= 4:
|
if len(buf) <= 4:
|
||||||
leftovers = buf
|
rem = buf
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if ofs >= len(buf) - 4:
|
if ofs >= len(buf) - 4:
|
||||||
leftovers = buf[ofs:]
|
rem = buf[ofs:]
|
||||||
buf = buf[:ofs]
|
buf = buf[:ofs]
|
||||||
else:
|
else:
|
||||||
leftovers = b"\n# "
|
rem = b"\n# "
|
||||||
else:
|
else:
|
||||||
buf = leftovers
|
buf = rem
|
||||||
|
|
||||||
fpos += len(buf) + 1
|
fpos += len(buf) + 1
|
||||||
buf = (
|
for a, b in [[b"\n# ", b""], [b"\n#r", b"\r"], [b"\n#n", b"\n"]]:
|
||||||
buf.replace(b"\n# ", b"")
|
buf = buf.replace(a, b)
|
||||||
.replace(b"\n#r", b"\r")
|
|
||||||
.replace(b"\n#n", b"\n")
|
|
||||||
)
|
|
||||||
dpos += len(buf) - 1
|
|
||||||
|
|
||||||
|
dpos += len(buf) - 1
|
||||||
yield buf
|
yield buf
|
||||||
|
|
||||||
if not rbuf:
|
if not rbuf:
|
||||||
|
@ -356,7 +357,7 @@ def utime(top):
|
||||||
|
|
||||||
def confirm(rv):
|
def confirm(rv):
|
||||||
msg()
|
msg()
|
||||||
msg(traceback.format_exc())
|
msg("retcode", rv if rv else traceback.format_exc())
|
||||||
msg("*** hit enter to exit ***")
|
msg("*** hit enter to exit ***")
|
||||||
try:
|
try:
|
||||||
raw_input() if PY2 else input()
|
raw_input() if PY2 else input()
|
||||||
|
@ -389,19 +390,36 @@ def run(tmp, j2):
|
||||||
if j2:
|
if j2:
|
||||||
del ld[-1]
|
del ld[-1]
|
||||||
|
|
||||||
|
if any([re.match(r"^-.*j[0-9]", x) for x in sys.argv]):
|
||||||
|
run_s(ld)
|
||||||
|
else:
|
||||||
|
run_i(ld)
|
||||||
|
|
||||||
|
|
||||||
|
def run_i(ld):
|
||||||
for x in ld:
|
for x in ld:
|
||||||
sys.path.insert(0, x)
|
sys.path.insert(0, x)
|
||||||
|
|
||||||
try:
|
from copyparty.__main__ import main as p
|
||||||
from copyparty.__main__ import main as p
|
|
||||||
|
|
||||||
p()
|
p()
|
||||||
|
|
||||||
except SystemExit as ex:
|
|
||||||
if ex.code:
|
def run_s(ld):
|
||||||
confirm(ex.code)
|
# fmt: off
|
||||||
except:
|
c = "import sys,runpy;" + "".join(['sys.path.insert(0,r"' + x + '");' for x in ld]) + 'runpy.run_module("copyparty",run_name="__main__")'
|
||||||
confirm(1)
|
c = [str(x) for x in [sys.executable, "-c", c] + list(sys.argv[1:])]
|
||||||
|
# fmt: on
|
||||||
|
msg("\n", c, "\n")
|
||||||
|
p = sp.Popen(c)
|
||||||
|
|
||||||
|
def bye(*a):
|
||||||
|
p.send_signal(signal.SIGINT)
|
||||||
|
|
||||||
|
signal.signal(signal.SIGTERM, bye)
|
||||||
|
p.wait()
|
||||||
|
|
||||||
|
raise SystemExit(p.returncode)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
@ -442,7 +460,16 @@ def main():
|
||||||
except:
|
except:
|
||||||
j2 = None
|
j2 = None
|
||||||
|
|
||||||
run(tmp, j2)
|
try:
|
||||||
|
run(tmp, j2)
|
||||||
|
except SystemExit as ex:
|
||||||
|
c = ex.code
|
||||||
|
if c not in [0, -15]:
|
||||||
|
confirm(ex.code)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
pass
|
||||||
|
except:
|
||||||
|
confirm(0)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in a new issue