mirror of
https://github.com/9001/copyparty.git
synced 2025-08-17 00:52:16 -06:00
upgrade bundled jinja2
This commit is contained in:
parent
58f9e05d93
commit
0f558ecbbf
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
turn your phone or raspi into a portable file server with resumable uploads/downloads using IE6 or any other browser
|
turn your phone or raspi into a portable file server with resumable uploads/downloads using IE6 or any other browser
|
||||||
|
|
||||||
* server runs on anything with `py2.7` or `py3.2+`
|
* server runs on anything with `py2.7` or `py3.3+`
|
||||||
* *resumable* uploads need `firefox 12+` / `chrome 6+` / `safari 6+` / `IE 10+`
|
* *resumable* uploads need `firefox 12+` / `chrome 6+` / `safari 6+` / `IE 10+`
|
||||||
* code standard: `black`
|
* code standard: `black`
|
||||||
|
|
||||||
|
@ -68,9 +68,8 @@ summary: it works! you can use it! (but technically not even close to beta)
|
||||||
# dependencies
|
# dependencies
|
||||||
|
|
||||||
* `jinja2`
|
* `jinja2`
|
||||||
* pulls in `markupsafe` as of v2.7; use jinja 2.6 on py3.2
|
|
||||||
|
|
||||||
optional, enables thumbnails:
|
optional, will eventually enable thumbnails:
|
||||||
* `Pillow` (requires py2.7 or py3.5+)
|
* `Pillow` (requires py2.7 or py3.5+)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -62,28 +62,32 @@ cd sfx
|
||||||
)/pe-copyparty"
|
)/pe-copyparty"
|
||||||
|
|
||||||
echo "repack of files in $old"
|
echo "repack of files in $old"
|
||||||
cp -pR "$old/"*{jinja2,copyparty} .
|
cp -pR "$old/"*{dep-j2,copyparty} .
|
||||||
mv {x.,}jinja2 2>/dev/null || true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[ $repack ] || {
|
[ $repack ] || {
|
||||||
echo collecting jinja2
|
echo collecting jinja2
|
||||||
f="../build/Jinja2-2.6.tar.gz"
|
f="../build/Jinja2-2.11.3.tar.gz"
|
||||||
[ -e "$f" ] ||
|
[ -e "$f" ] ||
|
||||||
(url=https://files.pythonhosted.org/packages/25/c8/212b1c2fd6df9eaf536384b6c6619c4e70a3afd2dffdd00e5296ffbae940/Jinja2-2.6.tar.gz;
|
(url=https://files.pythonhosted.org/packages/4f/e7/65300e6b32e69768ded990494809106f87da1d436418d5f1367ed3966fd7/Jinja2-2.11.3.tar.gz;
|
||||||
wget -O$f "$url" || curl -L "$url" >$f)
|
wget -O$f "$url" || curl -L "$url" >$f)
|
||||||
|
|
||||||
tar -zxf $f
|
tar -zxf $f
|
||||||
mv Jinja2-*/jinja2 .
|
mv Jinja2-*/src/jinja2 .
|
||||||
rm -rf Jinja2-* jinja2/testsuite jinja2/_markupsafe/tests.py jinja2/_stringdefs.py
|
rm -rf Jinja2-*
|
||||||
|
|
||||||
f=jinja2/lexer.py
|
echo collecting markupsafe
|
||||||
sed -r '/.*föö.*/ raise SyntaxError/' <$f >t
|
f="../build/MarkupSafe-1.1.1.tar.gz"
|
||||||
tmv $f
|
[ -e "$f" ] ||
|
||||||
|
(url=https://files.pythonhosted.org/packages/b9/2e/64db92e53b86efccfaea71321f597fa2e1b2bd3853d8ce658568f7a13094/MarkupSafe-1.1.1.tar.gz;
|
||||||
|
wget -O$f "$url" || curl -L "$url" >$f)
|
||||||
|
|
||||||
f=jinja2/_markupsafe/_constants.py
|
tar -zxf $f
|
||||||
awk '!/: [0-9]+,?$/ || /(amp|gt|lt|quot|apos|nbsp).:/' <$f >t
|
mv MarkupSafe-*/src/markupsafe .
|
||||||
tmv $f
|
rm -rf MarkupSafe-* markupsafe/_speedups.c
|
||||||
|
|
||||||
|
mkdir dep-j2/
|
||||||
|
mv {markupsafe,jinja2} dep-j2/
|
||||||
|
|
||||||
# msys2 tar is bad, make the best of it
|
# msys2 tar is bad, make the best of it
|
||||||
echo collecting source
|
echo collecting source
|
||||||
|
@ -177,7 +181,7 @@ args=(--owner=1000 --group=1000)
|
||||||
[ "$OSTYPE" = msys ] &&
|
[ "$OSTYPE" = msys ] &&
|
||||||
args=()
|
args=()
|
||||||
|
|
||||||
tar -cf tar "${args[@]}" --numeric-owner copyparty jinja2
|
tar -cf tar "${args[@]}" --numeric-owner copyparty dep-j2
|
||||||
|
|
||||||
echo compressing tar
|
echo compressing tar
|
||||||
# detect best level; bzip2 -7 is usually better than -9
|
# detect best level; bzip2 -7 is usually better than -9
|
||||||
|
|
148
scripts/sfx.py
148
scripts/sfx.py
|
@ -2,7 +2,7 @@
|
||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
from __future__ import print_function, unicode_literals
|
from __future__ import print_function, unicode_literals
|
||||||
|
|
||||||
import re, os, sys, time, shutil, signal, tarfile, hashlib, platform, tempfile
|
import os, sys, time, shutil, signal, tarfile, hashlib, platform, tempfile
|
||||||
import subprocess as sp
|
import subprocess as sp
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
@ -202,93 +202,6 @@ def u8(gen):
|
||||||
yield s
|
yield s
|
||||||
|
|
||||||
|
|
||||||
def get_py_win(ret):
|
|
||||||
tops = []
|
|
||||||
p = str(os.getenv("LocalAppdata"))
|
|
||||||
if p:
|
|
||||||
tops.append(os.path.join(p, "Programs", "Python"))
|
|
||||||
|
|
||||||
progfiles = {}
|
|
||||||
for p in ["ProgramFiles", "ProgramFiles(x86)"]:
|
|
||||||
p = str(os.getenv(p))
|
|
||||||
if p:
|
|
||||||
progfiles[p] = 1
|
|
||||||
# 32bit apps get x86 for both
|
|
||||||
if p.endswith(" (x86)"):
|
|
||||||
progfiles[p[:-6]] = 1
|
|
||||||
|
|
||||||
tops += list(progfiles.keys())
|
|
||||||
|
|
||||||
for sysroot in [me, sys.executable]:
|
|
||||||
sysroot = sysroot[:3].upper()
|
|
||||||
if sysroot[1] == ":" and sysroot not in tops:
|
|
||||||
tops.append(sysroot)
|
|
||||||
|
|
||||||
# $WIRESHARK_SLOGAN
|
|
||||||
for top in tops:
|
|
||||||
try:
|
|
||||||
for name1 in u8(sorted(os.listdir(top), reverse=True)):
|
|
||||||
if name1.lower().startswith("python"):
|
|
||||||
path1 = os.path.join(top, name1)
|
|
||||||
try:
|
|
||||||
for name2 in u8(os.listdir(path1)):
|
|
||||||
if name2.lower() == "python.exe":
|
|
||||||
path2 = os.path.join(path1, name2)
|
|
||||||
ret[path2.lower()] = path2
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def get_py_nix(ret):
|
|
||||||
ptn = re.compile(r"^(python|pypy)[0-9\.-]*$")
|
|
||||||
for bindir in os.getenv("PATH").split(":"):
|
|
||||||
if not bindir:
|
|
||||||
next
|
|
||||||
|
|
||||||
try:
|
|
||||||
for fn in u8(os.listdir(bindir)):
|
|
||||||
if ptn.match(fn):
|
|
||||||
fn = os.path.join(bindir, fn)
|
|
||||||
ret[fn.lower()] = fn
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def read_py(binp):
|
|
||||||
cmd = [
|
|
||||||
binp,
|
|
||||||
"-c",
|
|
||||||
"import sys; sys.stdout.write(' '.join(str(x) for x in sys.version_info)); import jinja2",
|
|
||||||
]
|
|
||||||
p = sp.Popen(cmd, stdout=sp.PIPE, stderr=sp.PIPE)
|
|
||||||
ver, _ = p.communicate()
|
|
||||||
ver = ver.decode("utf-8").split(" ")[:3]
|
|
||||||
ver = [int(x) if x.isdigit() else 0 for x in ver]
|
|
||||||
return ver, p.returncode == 0
|
|
||||||
|
|
||||||
|
|
||||||
def get_pys():
|
|
||||||
ver, chk = read_py(sys.executable)
|
|
||||||
if chk or PY2:
|
|
||||||
return [[chk, ver, sys.executable]]
|
|
||||||
|
|
||||||
hits = {sys.executable.lower(): sys.executable}
|
|
||||||
if platform.system() == "Windows":
|
|
||||||
get_py_win(hits)
|
|
||||||
else:
|
|
||||||
get_py_nix(hits)
|
|
||||||
|
|
||||||
ret = []
|
|
||||||
for binp in hits.values():
|
|
||||||
ver, chk = read_py(binp)
|
|
||||||
ret.append([chk, ver, binp])
|
|
||||||
msg("\t".join(str(x) for x in ret[-1]))
|
|
||||||
|
|
||||||
return ret
|
|
||||||
|
|
||||||
|
|
||||||
def yieldfile(fn):
|
def yieldfile(fn):
|
||||||
with open(fn, "rb") as f:
|
with open(fn, "rb") as f:
|
||||||
for block in iter(lambda: f.read(64 * 1024), b""):
|
for block in iter(lambda: f.read(64 * 1024), b""):
|
||||||
|
@ -440,12 +353,11 @@ def confirm():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def run(tmp, py):
|
def run(tmp, j2ver):
|
||||||
global cpp
|
global cpp
|
||||||
|
|
||||||
msg("OK")
|
msg("jinja2:", j2ver or "bundled")
|
||||||
msg("will use:", py)
|
msg("sfxdir:", tmp)
|
||||||
msg("bound to:", tmp)
|
|
||||||
|
|
||||||
# "systemd-tmpfiles-clean.timer"?? HOW do you even come up with this shit
|
# "systemd-tmpfiles-clean.timer"?? HOW do you even come up with this shit
|
||||||
try:
|
try:
|
||||||
|
@ -457,24 +369,20 @@ def run(tmp, py):
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
fp_py = os.path.join(tmp, "py")
|
ld = [tmp, os.path.join(tmp, "dep-j2")]
|
||||||
try:
|
if j2ver:
|
||||||
with open(fp_py, "wb") as f:
|
del ld[-1]
|
||||||
f.write(py.encode("utf-8") + b"\n")
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# avoid loading ./copyparty.py
|
cmd = (
|
||||||
cmd = [
|
"import sys, runpy; "
|
||||||
py,
|
+ "".join(['sys.path.insert(0, r"' + x + '"); ' for x in ld])
|
||||||
"-c",
|
+ 'runpy.run_module("copyparty", run_name="__main__")'
|
||||||
'import sys, runpy; sys.path.insert(0, r"'
|
)
|
||||||
+ tmp
|
cmd = [sys.executable, "-c", cmd] + list(sys.argv[1:])
|
||||||
+ '"); runpy.run_module("copyparty", run_name="__main__")',
|
|
||||||
] + list(sys.argv[1:])
|
|
||||||
|
|
||||||
|
cmd = [str(x) for x in cmd]
|
||||||
msg("\n", cmd, "\n")
|
msg("\n", cmd, "\n")
|
||||||
cpp = sp.Popen(str(x) for x in cmd)
|
cpp = sp.Popen(cmd)
|
||||||
try:
|
try:
|
||||||
cpp.wait()
|
cpp.wait()
|
||||||
except:
|
except:
|
||||||
|
@ -526,33 +434,13 @@ def main():
|
||||||
signal.signal(signal.SIGTERM, bye)
|
signal.signal(signal.SIGTERM, bye)
|
||||||
|
|
||||||
tmp = unpack()
|
tmp = unpack()
|
||||||
fp_py = os.path.join(tmp, "py")
|
|
||||||
if os.path.exists(fp_py):
|
|
||||||
with open(fp_py, "rb") as f:
|
|
||||||
py = f.read().decode("utf-8").rstrip()
|
|
||||||
|
|
||||||
return run(tmp, py)
|
|
||||||
|
|
||||||
pys = get_pys()
|
|
||||||
pys.sort(reverse=True)
|
|
||||||
j2, ver, py = pys[0]
|
|
||||||
if j2:
|
|
||||||
try:
|
try:
|
||||||
os.rename(os.path.join(tmp, "jinja2"), os.path.join(tmp, "x.jinja2"))
|
from jinja2 import __version__ as j2ver
|
||||||
except:
|
except:
|
||||||
pass
|
j2ver = None
|
||||||
|
|
||||||
return run(tmp, py)
|
return run(tmp, j2ver)
|
||||||
|
|
||||||
msg("\n could not find jinja2; will use py2 + the bundled version\n")
|
|
||||||
for _, ver, py in pys:
|
|
||||||
if ver > [2, 7] and ver < [3, 0]:
|
|
||||||
return run(tmp, py)
|
|
||||||
|
|
||||||
m = "\033[1;31m\n\n\ncould not find a python with jinja2 installed; please do one of these:\n\n pip install --user jinja2\n\n install python2\n\n\033[0m"
|
|
||||||
msg(m)
|
|
||||||
confirm()
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
1
setup.py
1
setup.py
|
@ -110,7 +110,6 @@ args = {
|
||||||
"Programming Language :: Python :: 2",
|
"Programming Language :: Python :: 2",
|
||||||
"Programming Language :: Python :: 2.7",
|
"Programming Language :: Python :: 2.7",
|
||||||
"Programming Language :: Python :: 3",
|
"Programming Language :: Python :: 3",
|
||||||
"Programming Language :: Python :: 3.2",
|
|
||||||
"Programming Language :: Python :: 3.3",
|
"Programming Language :: Python :: 3.3",
|
||||||
"Programming Language :: Python :: 3.4",
|
"Programming Language :: Python :: 3.4",
|
||||||
"Programming Language :: Python :: 3.5",
|
"Programming Language :: Python :: 3.5",
|
||||||
|
|
Loading…
Reference in a new issue