From 9ca8154651915690940347ce263d1dc9bd597132 Mon Sep 17 00:00:00 2001 From: ed Date: Sun, 15 Oct 2023 18:47:34 +0000 Subject: [PATCH] prefer the new TTF in pillow 10.1 + pyinstaller 6.1 fixes --- copyparty/__main__.py | 4 ++-- copyparty/ico.py | 23 +++++++++++++++++++++- copyparty/th_srv.py | 9 ++++++++- scripts/make-sfx.sh | 7 ++----- scripts/pyinstaller/build.sh | 14 ++++++++++++-- scripts/pyinstaller/deps.sha512 | 22 +++++++++++---------- scripts/pyinstaller/notes.txt | 34 ++++++++++++++++----------------- 7 files changed, 75 insertions(+), 38 deletions(-) diff --git a/copyparty/__main__.py b/copyparty/__main__.py index bb7db1d3..0a19378e 100755 --- a/copyparty/__main__.py +++ b/copyparty/__main__.py @@ -1082,9 +1082,9 @@ def add_thumbnail(ap): # https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html # https://github.com/libvips/libvips # ffmpeg -hide_banner -demuxers | awk '/^ D /{print$2}' | while IFS= read -r x; do ffmpeg -hide_banner -h demuxer=$x; done | grep -E '^Demuxer |extensions:' - ap2.add_argument("--th-r-pil", metavar="T,T", type=u, default="avif,avifs,blp,bmp,dcx,dds,dib,emf,eps,fits,flc,fli,fpx,gif,heic,heics,heif,heifs,icns,ico,im,j2p,j2k,jp2,jpeg,jpg,jpx,pbm,pcx,pgm,png,pnm,ppm,psd,sgi,spi,tga,tif,tiff,webp,wmf,xbm,xpm", help="image formats to decode using pillow") + ap2.add_argument("--th-r-pil", metavar="T,T", type=u, default="avif,avifs,blp,bmp,dcx,dds,dib,emf,eps,fits,flc,fli,fpx,gif,heic,heics,heif,heifs,icns,ico,im,j2p,j2k,jp2,jpeg,jpg,jpx,pbm,pcx,pgm,png,pnm,ppm,psd,qoi,sgi,spi,tga,tif,tiff,webp,wmf,xbm,xpm", help="image formats to decode using pillow") ap2.add_argument("--th-r-vips", metavar="T,T", type=u, default="avif,exr,fit,fits,fts,gif,hdr,heic,jp2,jpeg,jpg,jpx,jxl,nii,pfm,pgm,png,ppm,svg,tif,tiff,webp", help="image formats to decode using pyvips") - ap2.add_argument("--th-r-ffi", metavar="T,T", type=u, default="apng,avif,avifs,bmp,dds,dib,fit,fits,fts,gif,hdr,heic,heics,heif,heifs,icns,ico,jp2,jpeg,jpg,jpx,jxl,pbm,pcx,pfm,pgm,png,pnm,ppm,psd,sgi,tga,tif,tiff,webp,xbm,xpm", help="image formats to decode using ffmpeg") + ap2.add_argument("--th-r-ffi", metavar="T,T", type=u, default="apng,avif,avifs,bmp,dds,dib,fit,fits,fts,gif,hdr,heic,heics,heif,heifs,icns,ico,jp2,jpeg,jpg,jpx,jxl,pbm,pcx,pfm,pgm,png,pnm,ppm,psd,qoi,sgi,tga,tif,tiff,webp,xbm,xpm", help="image formats to decode using ffmpeg") ap2.add_argument("--th-r-ffv", metavar="T,T", type=u, default="3gp,asf,av1,avc,avi,flv,h264,h265,hevc,m4v,mjpeg,mjpg,mkv,mov,mp4,mpeg,mpeg2,mpegts,mpg,mpg2,mts,nut,ogm,ogv,rm,ts,vob,webm,wmv", help="video formats to decode using ffmpeg") ap2.add_argument("--th-r-ffa", metavar="T,T", type=u, default="aac,ac3,aif,aiff,alac,alaw,amr,apac,ape,au,bonk,dfpwm,dts,flac,gsm,ilbc,it,m4a,mo3,mod,mp2,mp3,mpc,mptm,mt2,mulaw,ogg,okt,opus,ra,s3m,tak,tta,ulaw,wav,wma,wv,xm,xpk", help="audio formats to decode using ffmpeg") diff --git a/copyparty/ico.py b/copyparty/ico.py index 6f708307..81211dc3 100644 --- a/copyparty/ico.py +++ b/copyparty/ico.py @@ -6,7 +6,7 @@ import colorsys import hashlib from .__init__ import PY2 -from .th_srv import HAVE_PIL +from .th_srv import HAVE_PIL, HAVE_PILF from .util import BytesIO @@ -37,6 +37,27 @@ class Ico(object): if chrome: # cannot handle more than ~2000 unique SVGs + if HAVE_PILF: + try: + from PIL import Image, ImageDraw + + h = int(96 * h / w) + w = 96 + img = Image.new("RGB", (w, h), "#" + c[:6]) + pb = ImageDraw.Draw(img) + _, _, tw, th = pb.textbbox((0, 0), ext, font_size=16) + xy = ((w - tw) // 2, (h - th) // 2) + pb.text(xy, ext, fill="#" + c[6:], font_size=16) + + img = img.resize((w * 2, h * 2), Image.NEAREST) + + buf = BytesIO() + img.save(buf, format="PNG", compress_level=1) + return "image/png", buf.getvalue() + + except: + pass + if HAVE_PIL: # svg: 3s, cache: 6s, this: 8s from PIL import Image, ImageDraw diff --git a/copyparty/th_srv.py b/copyparty/th_srv.py index 230fb2be..e4398887 100644 --- a/copyparty/th_srv.py +++ b/copyparty/th_srv.py @@ -37,14 +37,21 @@ if TYPE_CHECKING: from .svchub import SvcHub HAVE_PIL = False +HAVE_PILF = False HAVE_HEIF = False HAVE_AVIF = False HAVE_WEBP = False try: - from PIL import ExifTags, Image, ImageOps + from PIL import ExifTags, Image, ImageFont, ImageOps HAVE_PIL = True + try: + ImageFont.load_default(size=16) + HAVE_PILF = True + except: + pass + try: Image.new("RGB", (2, 2)).save(BytesIO(), format="webp") HAVE_WEBP = True diff --git a/scripts/make-sfx.sh b/scripts/make-sfx.sh index 37c2a9de..cc4606be 100755 --- a/scripts/make-sfx.sh +++ b/scripts/make-sfx.sh @@ -420,16 +420,13 @@ rm -f ftp/pyftpdlib/{__main__,prefork}.py [ $no_ftp ] && rm -rf copyparty/ftpd.py ftp asyncore.py asynchat.py && - sed -ri '/add_argument\("--ftp/d' copyparty/__main__.py && sed -ri '/\.ftp/d' copyparty/svchub.py [ $no_smb ] && - rm -f copyparty/smbd.py && - sed -ri '/add_argument\("--smb/d' copyparty/__main__.py + rm -f copyparty/smbd.py [ $no_zm ] && - rm -rf copyparty/mdns.py copyparty/stolen/dnslib && - sed -ri '/add_argument\("--zm/d' copyparty/__main__.py + rm -rf copyparty/mdns.py copyparty/stolen/dnslib [ $no_cm ] && { rm -rf copyparty/web/mde.* copyparty/web/deps/easymde* diff --git a/scripts/pyinstaller/build.sh b/scripts/pyinstaller/build.sh index 7976fb93..5bf0c5c3 100644 --- a/scripts/pyinstaller/build.sh +++ b/scripts/pyinstaller/build.sh @@ -9,10 +9,13 @@ tee build2.sh | cmp build.sh && rm build2.sh || { [[ $r =~ [yY] ]] && mv build{2,}.sh && exec ./build.sh } -[ -e up2k.sh ] && [ ! "$1" ] && ./up2k.sh +clean=--clean +[ "$1" = f ] && clean= && shift uname -s | grep WOW64 && m=64 || m=32 uname -s | grep NT-10 && w10=1 || w7=1 +[ $w7 ] && [ -e up2k.sh ] && [ ! "$1" ] && ./up2k.sh + [ $w7 ] && pyv=37 || pyv=311 esuf= [ $w7 ] && [ $m = 32 ] && esuf=32 @@ -65,12 +68,18 @@ sed -r 's/1,2,3,0/'$a,$b,$c,$d'/;s/1\.2\.3/'$a.$b.$c/ loader.rc2 sed -ri s/copyparty.exe/copyparty$esuf.exe/ loader.rc2 excl=( + asyncio copyparty.broker_mp copyparty.broker_mpw + copyparty.smbd ctypes.macholib curses + email._header_value_parser + email.header + email.parser inspect multiprocessing + packaging pdb pickle PIL.EpsImagePlugin @@ -85,6 +94,7 @@ excl=( PIL.ImageShow PIL.ImageTk PIL.ImageWin + PIL.PdfParser ) || excl+=( PIL PIL.ExifTags @@ -95,7 +105,7 @@ excl=( excl=( "${excl[@]/#/--exclude-module }" ) $APPDATA/python/python$pyv/scripts/pyinstaller \ - -y --clean -p mods --upx-dir=. \ + -y $clean -p mods --upx-dir=. \ ${excl[*]} \ --version-file loader.rc2 -i loader.ico -n copyparty -c -F loader.py \ --add-data 'mods/copyparty/res;copyparty/res' \ diff --git a/scripts/pyinstaller/deps.sha512 b/scripts/pyinstaller/deps.sha512 index 06850588..7fa6310d 100644 --- a/scripts/pyinstaller/deps.sha512 +++ b/scripts/pyinstaller/deps.sha512 @@ -1,22 +1,23 @@ -d5510a24cb5e15d6d30677335bbc7624c319b371c0513981843dc51d9b3a1e027661096dfcfc540634222bb2634be6db55bf95185b30133cb884f1e47652cf53 altgraph-0.17.3-py2.py3-none-any.whl +f117016b1e6a7d7e745db30d3e67f1acf7957c443a0dd301b6c5e10b8368f2aa4db6be9782d2d3f84beadd139bfeef4982e40f21ca5d9065cb794eeb0e473e82 altgraph-0.17.4-py2.py3-none-any.whl eda6c38fc4d813fee897e969ff9ecc5acc613df755ae63df0392217bbd67408b5c1f6c676f2bf5497b772a3eb4e1a360e1245e1c16ee83f0af555f1ab82c3977 Git-2.39.1-32-bit.exe 17ce52ba50692a9d964f57a23ac163fb74c77fdeb2ca988a6d439ae1fe91955ff43730c073af97a7b3223093ffea3479a996b9b50ee7fba0869247a56f74baa6 pefile-2023.2.7-py3-none-any.whl f298e34356b5590dde7477d7b3a88ad39c622a2bcf3fcd7c53870ce8384dd510f690af81b8f42e121a22d3968a767d2e07595036b2ed7049c8ef4d112bcf3a61 pyinstaller-5.13.2-py3-none-win32.whl -ea73aa54cc6d5db20dfb127e54562dabf890e4cd6171a91b10a51af2bcfc76e1d64cbdce4546df2dcfe42b624724c85b1cd05934be2413425b1f880222727b4f pyinstaller-5.13.2-py3-none-win_amd64.whl -2f4e3927a38cf7757bc9a1c06370d79209669a285a80f1b09cf9917137825c7022a50a56b351807e6e687e2c3a7bd7b2c5cc6daeb4d90e11920284c1a04a1cc3 pyinstaller_hooks_contrib-2023.8-py2.py3-none-any.whl +f23615c522ed58b9a05978ba4c69c06224590f3a6adbd8e89b31838b181a57160739ceff1fc2ba6f4239b8fee46f92ce02910b2debda2710558ed42cff1ce3f1 pyinstaller-6.1.0-py3-none-win_amd64.whl +5747b3b119629c4cf956f0eaa85f29218bb3680d3a4a262fa6e976e56b35067302e153d2c0a001505f2cb642b1f78752567889b3b82e342d6cd29aac8b70e92e pyinstaller_hooks_contrib-2023.10-py2.py3-none-any.whl 749a473646c6d4c7939989649733d4c7699fd1c359c27046bf5bc9c070d1a4b8b986bbc65f60d7da725baf16dbfdd75a4c2f5bb8335f2cb5685073f5fee5c2d1 pywin32_ctypes-0.2.2-py3-none-any.whl +6e0d854040baff861e1647d2bece7d090bc793b2bd9819c56105b94090df54881a6a9b43ebd82578cd7c76d47181571b671e60672afd9def389d03c9dae84fcf setuptools-68.2.2-py3-none-any.whl 3c5adf0a36516d284a2ede363051edc1bcc9df925c5a8a9fa2e03cab579dd8d847fdad42f7fd5ba35992e08234c97d2dbfec40a9d12eec61c8dc03758f2bd88e typing_extensions-4.4.0-py3-none-any.whl 8d16a967a0a7872a7575b1005cf66915deacda6ee8611fbb52f42fc3e3beb2f901a5140c942a5d146bd412b92bfa9cbadd82beeba83df6d70930c6dc26608a5b upx-4.1.0-win32.zip # u2c (win7) -a7d259277af4948bf960682bc9fb45a44b9ae9a19763c8a7c313cef4aa9ec2d447d843e4a7c409e9312c8c8f863a24487a8ee4ffa6891e9b1c4e111bb4723861 certifi-2022.12.7-py3-none-any.whl -2822c0dae180b1c8cfb7a70c8c00bad62af9afdbb18b656236680def9d3f1fcdcb8ef5eb64fc3b4c934385cd175ad5992a2284bcba78a243130de75b2d1650db charset_normalizer-3.1.0-cp37-cp37m-win32.whl +4562b1065c6bce7084eb575b654985c990e26034bfcd8db54629312f43ac737e264db7a2b4d8b797e09919a485cbc6af3fd0931690b7ed79b62bcc0736aec9fc certifi-2023.7.22-py3-none-any.whl +904eb57b13bea80aea861de86987e618665d37fa9ea0856e0125a9ba767a53e5064de0b9c4735435a2ddf4f16f7f7d2c75a682e1de83d9f57922bdca8e29988c charset_normalizer-3.3.0-cp37-cp37m-win32.whl ffdd45326f4e91c02714f7a944cbcc2fdd09299f709cfa8aec0892053eef0134fb80d9ba3790afd319538a86feb619037cbf533e2f5939cb56b35bb17f56c858 idna-3.4-py3-none-any.whl -220e0e122d5851aaccf633224dd7fbd3ba8c8d2720944d8019d6a276ed818d83e3426fe21807f22d673b5428f19fcf9a6b4e645f69bbecd967c568bb6aeb7c8d requests-2.28.2-py3-none-any.whl -8770011f4ad1fe40a3062e6cdf1fda431530c59ee7de3fc5f8c57db54bfdb71c3aa220ca0e0bb1874fc6700e9ebb57defbae54ac84938bc9ad8f074910106681 urllib3-1.26.14-py2.py3-none-any.whl +b795abb26ba2f04f1afcfb196f21f638014b26c8186f8f488f1c2d91e8e0220962fbd259dbc9c3875222eb47fc95c73fc0606aaa6602b9ebc524809c9ba3501f requests-2.31.0-py3-none-any.whl +5a25cb9b79bb6107f9055dc3e9f62ebc6d4d9ca2c730d824985c93cd82406b723c200d6300c5064e42ee9fc7a2853d6ec6661394f3ed7bac03750e1f2a6840d1 urllib3-1.26.17-py2.py3-none-any.whl # win7 91c025f7d94bcdf93df838fab67053165a414fc84e8496f92ecbb910dd55f6b6af5e360bbd051444066880c5a6877e75157bd95e150ead46e5c605930dfc50f2 future-0.18.2.tar.gz c06b3295d1d0b0f0a6f9a6cd0be861b9b643b4a5ea37857f0bd41c45deaf27bb927b71922dab74e633e43d75d04a9bd0d1c4ad875569740b0f2a98dd2bfa5113 importlib_metadata-5.0.0-py3-none-any.whl -4e71295da5d1a26c71a0baa8905fdccb522bb16d56bc964db636de68688c5bf703f3b2880cdeea07138789e0eb4506e06f9ccd0da906c89d2cb6d55ad64659ea pip-22.3-py3-none-any.whl +016a8cbd09384f1a9a44cb0e8274df75a8bcb2f3966bb5d708c62145289efaa5db98f75256c97e4f8046735ce2e529fbb076f284a46cdb716e89a75660200ad9 pip-23.2.1-py3-none-any.whl 6bb73cc2db795c59c92f2115727f5c173cacc9465af7710db9ff2f2aec2d73130d0992d0f16dcb3fac222dc15c0916562d0813b2337401022020673a4461df3d python-3.7.9-amd64.exe 500747651c87f59f2436c5ab91207b5b657856e43d10083f3ce27efb196a2580fadd199a4209519b409920c562aaaa7dcbdfb83ed2072a43eaccae6e2d056f31 python-3.7.9.exe 68e1b618d988be56aaae4e2eb92bc0093627a00441c1074ebe680c41aa98a6161e52733ad0c59888c643a33fe56884e4f935178b2557fbbdd105e92e0d993df6 windows6.1-kb2533623-x64.msu @@ -26,5 +27,6 @@ ba91ab0518c61eff13e5612d9e6b532940813f6b56e6ed81ea6c7c4d45acee4d98136a383a250675 00558cca2e0ac813d404252f6e5aeacb50546822ecb5d0570228b8ddd29d94e059fbeb6b90393dee5abcddaca1370aca784dc9b095cbb74e980b3c024767fb24 Jinja2-3.1.2-py3-none-any.whl 7f8f4daa4f4f2dbf24cdd534b2952ee3fba6334eb42b37465ccda3aa1cccc3d6204aa6bfffb8a83bf42ec59c702b5b5247d4c8ee0d4df906334ae53072ef8c4c MarkupSafe-2.1.3-cp311-cp311-win_amd64.whl 8a6e2b13a2ec4ef914a5d62aad3db6464d45e525a82e07f6051ed10474eae959069e165dba011aefb8207cdfd55391d73d6f06362c7eb247b08763106709526e mutagen-1.47.0-py3-none-any.whl -08a033202b5c51e50609b2700dd69cbae30edb367f34762fd1633aae08b35949b4f67f12c75f25868a5b62b4956190d0cc8d201b170758d9c04a523bc8442b9b Pillow-10.0.1-cp311-cp311-win_amd64.whl -c86bbeacad3ae3c7bde747f5b4f09c11eced841add14e79ec4a064e5e29ebca35460e543ba735b11bfb882837d5ff4371ce64492d28d096b4686233c9a8cda6d python-3.11.5-amd64.exe +656015f5cc2c04aa0653ee5609c39a7e5f0b6a58c84fe26b20bd070c52d20b4effb810132f7fb771168483e9fd975cc3302837dd7a1a687ee058b0460c857cc4 packaging-23.2-py3-none-any.whl +6401616fdfdd720d1aaa9a0ed1398d00664b28b6d84517dff8d1f9c416452610c6afa64cfb012a78e61d1cf4f6d0784eca6e7610957859e511f15bc6f3b3bd53 Pillow-10.1.0-cp311-cp311-win_amd64.whl +36442c017d8fc603745d33ca888b5b1194644103cbe1ff53e32d9b0355e290d5efac655fa1ae1b8e552ad8468878dc600d550c1158224260ca463991442e5264 python-3.11.6-amd64.exe diff --git a/scripts/pyinstaller/notes.txt b/scripts/pyinstaller/notes.txt index 05cfc0b8..14513cb7 100644 --- a/scripts/pyinstaller/notes.txt +++ b/scripts/pyinstaller/notes.txt @@ -15,19 +15,24 @@ uname -s | grep NT-10 && w10=1 || { w7=1; uname -s | grep WOW64 && w7x64=1 || w7x32=1 } fns=( - altgraph-0.17.3-py2.py3-none-any.whl + altgraph-0.17.4-py2.py3-none-any.whl pefile-2023.2.7-py3-none-any.whl - pyinstaller-5.13.2-py3-none-win_amd64.whl - pyinstaller_hooks_contrib-2023.7-py2.py3-none-any.whl + pyinstaller_hooks_contrib-2023.10-py2.py3-none-any.whl pywin32_ctypes-0.2.2-py3-none-any.whl + setuptools-68.2.2-py3-none-any.whl upx-4.1.0-win32.zip ) [ $w10 ] && fns+=( + pyinstaller-6.1.0-py3-none-win_amd64.whl + Jinja2-3.1.2-py3-none-any.whl + MarkupSafe-2.1.3-cp311-cp311-win_amd64.whl mutagen-1.47.0-py3-none-any.whl - Pillow-10.0.1-cp311-cp311-win_amd64.whl - python-3.11.3-amd64.exe -} + packaging-23.2-py3-none-any.whl + Pillow-10.1.0-cp311-cp311-win_amd64.whl + python-3.11.6-amd64.exe +) [ $w7 ] && fns+=( + pyinstaller-5.13.2-py3-none-win32.whl certifi-2022.12.7-py3-none-any.whl chardet-5.1.0-py3-none-any.whl idna-3.4-py3-none-any.whl @@ -37,7 +42,7 @@ fns=( [ $w7 ] && fns+=( future-0.18.2.tar.gz importlib_metadata-5.0.0-py3-none-any.whl - pip-22.3-py3-none-any.whl + pip-23.2.1-py3-none-any.whl typing_extensions-4.4.0-py3-none-any.whl zipp-3.10.0-py3-none-any.whl ) @@ -67,31 +72,26 @@ uname -s | grep NT-10 && w10=1 || w7=1 [ $w7 ] && pyv=37 || pyv=311 appd=$(cygpath.exe "$APPDATA") cd ~/Downloads && -unzip upx-*-win32.zip && +yes | unzip upx-*-win32.zip && mv upx-*/upx.exe . && python -m ensurepip && -python -m pip install --user -U pip-*.whl && -{ [ $w7 ] || python -m pip install --user -U mutagen-*.whl Pillow-*.whl; } && +{ [ $w10 ] || python -m pip install --user -U pip-*.whl; } && +{ [ $w7 ] || python -m pip install --user -U {packaging,setuptools,mutagen,Pillow,Jinja2,MarkupSafe}-*.whl; } && { [ $w10 ] || python -m pip install --user -U {requests,urllib3,charset_normalizer,certifi,idna}-*.whl; } && { [ $w10 ] || python -m pip install --user -U future-*.tar.gz importlib_metadata-*.whl typing_extensions-*.whl zipp-*.whl; } && python -m pip install --user -U pyinstaller-*.whl pefile-*.whl pywin32_ctypes-*.whl pyinstaller_hooks_contrib-*.whl altgraph-*.whl && sed -ri 's/--lzma/--best/' $appd/Python/Python$pyv/site-packages/pyinstaller/building/utils.py && curl -fkLO https://192.168.123.1:3923/cpp/scripts/uncomment.py && -python uncomment.py $(for d in $appd/Python/Python$pyv/site-packages/{requests,urllib3,charset_normalizer,certifi,idna}; do find $d -name \*.py; done) && +python uncomment.py 1 $(for d in $appd/Python/Python$pyv/site-packages/{requests,urllib3,charset_normalizer,certifi,idna,mutagen,PIL,jinja2,markupsafe}; do find $d -name \*.py; done) && cd && rm -f build.sh && curl -fkLO https://192.168.123.1:3923/cpp/scripts/pyinstaller/build.sh && -curl -fkLO https://192.168.123.1:3923/cpp/scripts/pyinstaller/up2k.sh && +{ [ $w10 ] || curl -fkLO https://192.168.123.1:3923/cpp/scripts/pyinstaller/up2k.sh; } && echo ok # python -m pip install --user -U Pillow-9.2.0-cp37-cp37m-win32.whl # sed -ri 's/, bestopt, /]+bestopt+[/' $APPDATA/Python/Python37/site-packages/pyinstaller/building/utils.py # sed -ri 's/(^\s+bestopt = ).*/\1["--best","--lzma","--ultra-brute"]/' $APPDATA/Python/Python37/site-packages/pyinstaller/building/utils.py -===[ win10: copy-paste into git-bash ]========================= -#for f in $appd/Python/Python311/site-packages/mutagen/*.py; do awk -i inplace '/^\s*def _?(save|write)/{sub(/d.*/," ");s=$0;ns=length(s)} ns&&/[^ ]/&&substr($0,0,ns)!=s{ns=0} !ns' "$f"; done && -python uncomment.py $appd/Python/Python311/site-packages/{mutagen,PIL,jinja2,markupsafe}/*.py && -echo ok - ## ============================================================ ## notes