mirror of
https://github.com/9001/copyparty.git
synced 2025-08-17 00:52:16 -06:00
add pyz builder
This commit is contained in:
parent
253a414443
commit
27485a4cb1
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -12,6 +12,7 @@ copyparty.egg-info/
|
|||
/dist/
|
||||
/py2/
|
||||
/sfx*
|
||||
/pyz/
|
||||
/unt/
|
||||
/log/
|
||||
|
||||
|
|
6
copyparty/__main__.py
Executable file → Normal file
6
copyparty/__main__.py
Executable file → Normal file
|
@ -1391,12 +1391,16 @@ def run_argparse(
|
|||
return ret
|
||||
|
||||
|
||||
def main(argv: Optional[list[str]] = None) -> None:
|
||||
def main(argv: Optional[list[str]] = None, rsrc: Optional[str] = None) -> None:
|
||||
time.strptime("19970815", "%Y%m%d") # python#7980
|
||||
if WINDOWS:
|
||||
os.system("rem") # enables colors
|
||||
|
||||
init_E(E)
|
||||
|
||||
if rsrc: # pyz
|
||||
E.mod = rsrc
|
||||
|
||||
if argv is None:
|
||||
argv = sys.argv
|
||||
|
||||
|
|
61
scripts/make-pyz.sh
Executable file
61
scripts/make-pyz.sh
Executable file
|
@ -0,0 +1,61 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
echo
|
||||
|
||||
# port install gnutar gsed coreutils
|
||||
gtar=$(command -v gtar || command -v gnutar) || true
|
||||
[ ! -z "$gtar" ] && command -v gsed >/dev/null && {
|
||||
tar() { $gtar "$@"; }
|
||||
sed() { gsed "$@"; }
|
||||
command -v grealpath >/dev/null &&
|
||||
realpath() { grealpath "$@"; }
|
||||
}
|
||||
|
||||
targs=(--owner=1000 --group=1000)
|
||||
[ "$OSTYPE" = msys ] &&
|
||||
targs=()
|
||||
|
||||
[ -e copyparty/__main__.py ] || cd ..
|
||||
[ -e copyparty/__main__.py ] || {
|
||||
echo "run me from within the project root folder"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
[ -e sfx/copyparty/__main__.py ] || {
|
||||
echo "run ./scripts/make-sfx.py first"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
rm -rf pyz
|
||||
mkdir -p pyz
|
||||
cd pyz
|
||||
|
||||
cp -pR ../sfx/{copyparty,partftpy} .
|
||||
cp -pR ../sfx/{ftp,j2}/* .
|
||||
|
||||
ts=$(date -u +%s)
|
||||
hts=$(date -u +%Y-%m%d-%H%M%S)
|
||||
ver="$(cat ../sfx/ver)"
|
||||
|
||||
mkdir -p ../dist
|
||||
pyz_out=../dist/copyparty.pyz
|
||||
|
||||
echo creating z.tar
|
||||
( cd copyparty
|
||||
tar -cf z.tar "${targs[@]}" --numeric-owner web res
|
||||
rm -rf web res
|
||||
)
|
||||
|
||||
echo creating loader
|
||||
sed -r 's/^(VER = ).*/\1"'"$ver"'"/; s/^(STAMP = ).*/\1'$(date +%s)/ \
|
||||
<../scripts/ziploader.py \
|
||||
>__main__.py
|
||||
|
||||
echo creating pyz
|
||||
rm -f $pyz_out
|
||||
zip -9 -q -r $pyz_out *
|
||||
|
||||
echo done:
|
||||
echo " $(realpath $pyz_out)"
|
|
@ -99,9 +99,6 @@ pybin=$(command -v python3 || command -v python) || {
|
|||
exit 1
|
||||
}
|
||||
|
||||
[ $CSN ] ||
|
||||
CSN=sfx
|
||||
|
||||
langs=
|
||||
use_gz=
|
||||
zopf=2560
|
||||
|
@ -148,9 +145,9 @@ stamp=$(
|
|||
done | sort | tail -n 1 | sha1sum | cut -c-16
|
||||
)
|
||||
|
||||
rm -rf $CSN/*
|
||||
mkdir -p $CSN build
|
||||
cd $CSN
|
||||
rm -rf sfx$CSN/*
|
||||
mkdir -p sfx$CSN build
|
||||
cd sfx$CSN
|
||||
|
||||
tmpdir="$(
|
||||
printf '%s\n' "$TMPDIR" /tmp |
|
||||
|
@ -386,11 +383,13 @@ git describe --tags >/dev/null 2>/dev/null && {
|
|||
ver="$(awk '/^VERSION *= \(/ {
|
||||
gsub(/[^0-9,a-g-]/,""); gsub(/,/,"."); print; exit}' < copyparty/__version__.py)"
|
||||
|
||||
echo "$ver" >ver # pyz
|
||||
|
||||
ts=$(date -u +%s)
|
||||
hts=$(date -u +%Y-%m%d-%H%M%S) # --date=@$ts (thx osx)
|
||||
|
||||
mkdir -p ../dist
|
||||
sfx_out=../dist/copyparty-$CSN
|
||||
sfx_out=../dist/copyparty-sfx$CSN
|
||||
|
||||
echo cleanup
|
||||
find -name '*.pyc' -delete
|
||||
|
@ -542,7 +541,7 @@ gzres() {
|
|||
}
|
||||
|
||||
|
||||
zdir="$tmpdir/cpp-mk$CSN"
|
||||
zdir="$tmpdir/cpp-mksfx$CSN"
|
||||
[ -e "$zdir/$stamp" ] || rm -rf "$zdir"
|
||||
mkdir -p "$zdir"
|
||||
echo a > "$zdir/$stamp"
|
||||
|
|
|
@ -42,7 +42,7 @@ $f$s.py --version >/dev/null
|
|||
min=99999999
|
||||
for ((a=0; a<$parallel; a++)); do
|
||||
while [ -e .sfx-run ]; do
|
||||
CSN=sfx$a ./make-sfx.sh re "$@"
|
||||
CSN=$a ./make-sfx.sh re "$@"
|
||||
sz=$(wc -c <$f$a$s.py | awk '{print$1}')
|
||||
[ $sz -ge $min ] && continue
|
||||
mv $f$a$s.py $f$s.py.$sz
|
||||
|
|
112
scripts/ziploader.py
Normal file
112
scripts/ziploader.py
Normal file
|
@ -0,0 +1,112 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import atexit
|
||||
import os
|
||||
import platform
|
||||
import sys
|
||||
import tarfile
|
||||
import tempfile
|
||||
import threading
|
||||
import time
|
||||
import traceback
|
||||
|
||||
|
||||
VER = None
|
||||
STAMP = None
|
||||
WINDOWS = sys.platform in ["win32", "msys"]
|
||||
|
||||
|
||||
def msg(*a, **ka):
|
||||
if a:
|
||||
a = ["[ZIP]", a[0]] + list(a[1:])
|
||||
|
||||
ka["file"] = sys.stderr
|
||||
print(*a, **ka)
|
||||
|
||||
|
||||
def utime(top):
|
||||
# avoid cleaners
|
||||
files = [os.path.join(dp, p) for dp, dd, df in os.walk(top) for p in dd + df]
|
||||
try:
|
||||
while True:
|
||||
t = int(time.time())
|
||||
for f in [top] + files:
|
||||
os.utime(f, (t, t))
|
||||
|
||||
time.sleep(78123)
|
||||
except Exception as ex:
|
||||
print("utime:", ex, f)
|
||||
|
||||
|
||||
def confirm(rv):
|
||||
msg()
|
||||
msg("retcode", rv if rv else traceback.format_exc())
|
||||
if WINDOWS:
|
||||
msg("*** hit enter to exit ***")
|
||||
try:
|
||||
input()
|
||||
except:
|
||||
pass
|
||||
|
||||
sys.exit(rv or 1)
|
||||
|
||||
|
||||
def run():
|
||||
import copyparty
|
||||
from copyparty.__main__ import main as cm
|
||||
|
||||
td = tempfile.TemporaryDirectory(prefix="")
|
||||
atexit.register(td.cleanup)
|
||||
rsrc = td.name
|
||||
|
||||
try:
|
||||
from importlib.resources import files
|
||||
|
||||
f = files(copyparty).joinpath("z.tar").open("rb")
|
||||
except:
|
||||
from importlib.resources import open_binary
|
||||
|
||||
f = open_binary("copyparty", "z.tar")
|
||||
|
||||
with tarfile.open(fileobj=f) as tf:
|
||||
try:
|
||||
tf.extractall(rsrc, filter="tar")
|
||||
except TypeError:
|
||||
tf.extractall(rsrc) # nosec (archive is safe)
|
||||
|
||||
f.close()
|
||||
f = None
|
||||
|
||||
msg(" rsrc dir:", rsrc)
|
||||
msg()
|
||||
|
||||
t = threading.Thread(target=utime, args=(rsrc,))
|
||||
t.daemon = True
|
||||
t.start()
|
||||
|
||||
cm(rsrc=rsrc)
|
||||
|
||||
|
||||
def main():
|
||||
sysver = str(sys.version).replace("\n", "\n" + " " * 18)
|
||||
pktime = time.strftime("%Y-%m-%d, %H:%M:%S", time.gmtime(STAMP))
|
||||
msg()
|
||||
msg(" this is: copyparty", VER)
|
||||
msg(" packed at:", pktime, "UTC,", STAMP)
|
||||
msg("python bin:", sys.executable)
|
||||
msg("python ver:", platform.python_implementation(), sysver)
|
||||
|
||||
try:
|
||||
run()
|
||||
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__":
|
||||
main()
|
Loading…
Reference in a new issue