Skip to content

Commit

Permalink
Add: Auto zip all the files to be distributed
Browse files Browse the repository at this point in the history
  • Loading branch information
LussacZheng committed Jul 20, 2020
1 parent b4a1cf2 commit fb62374
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 19 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

# You-Get Unofficial Build Executable

![platform](https://img.shields.io/badge/platform-windows-brightgreen)
![platform](https://img.shields.io/badge/platform-Windows-brightgreen?logo=windows)
![GitHub release](https://img.shields.io/github/v/release/LussacZheng/you-get.exe?include_prereleases&label=build)
[![GitHub All Releases](https://img.shields.io/github/downloads/LussacZheng/you-get.exe/total?color=green)](https://github.com/LussacZheng/you-get.exe/releases)
[![GitHub All Releases](https://img.shields.io/github/downloads/LussacZheng/you-get.exe/total?color=green&logo=github)](https://github.com/LussacZheng/you-get.exe/releases)

Use [PyInstaller](https://github.com/pyinstaller/pyinstaller) to bundle [You-Get](https://github.com/soimort/you-get) into a single executable for Windows.

Expand Down
4 changes: 2 additions & 2 deletions README_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

# You-Get 非官方构建的可执行文件

![platform](https://img.shields.io/badge/platform-windows-brightgreen)
![platform](https://img.shields.io/badge/platform-Windows-brightgreen?logo=windows)
![GitHub release](https://img.shields.io/github/v/release/LussacZheng/you-get.exe?include_prereleases&label=build)
[![GitHub All Releases](https://img.shields.io/github/downloads/LussacZheng/you-get.exe/total?color=green)](https://github.com/LussacZheng/you-get.exe/releases)
[![GitHub All Releases](https://img.shields.io/github/downloads/LussacZheng/you-get.exe/total?color=green&logo=github)](https://github.com/LussacZheng/you-get.exe/releases)

使用 [PyInstaller](https://github.com/pyinstaller/pyinstaller) 打包 [You-Get](https://github.com/soimort/you-get) 为一个独立的可执行文件 (Windows)。

Expand Down
19 changes: 19 additions & 0 deletions bin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## Source

- `zip.exe`

```text
Version: v3.0
SHA256: d73ef5858db9bb968da585546283dfab586ce11a218b0b223c0a5f0adcade7d4
Source: https://sourceforge.net/projects/gnuwin32/files/zip/3.0/
From: "zip-3.0-bin.zip" \bin\zip.exe
```

- `bzip2.dll`

```text
Version: v1.0.5
SHA256: da25db24809479051d980be5e186926dd53233a76dfe357a455387646befca76
Source: https://sourceforge.net/projects/gnuwin32/files/bzip2/1.0.5/
From: "bzip2-1.0.5-bin.zip" \bin\bzip2.dll
```
Binary file added bin/bzip2.dll
Binary file not shown.
Binary file added bin/zip.exe
Binary file not shown.
102 changes: 91 additions & 11 deletions build.bat
Original file line number Diff line number Diff line change
@@ -1,36 +1,64 @@
@rem - Encoding:utf-8; Mode:Batch; Language:en; LineEndings:CRLF -
:: You-Get Unofficial Build Executable for Windows
:: Author: Lussac (https://blog.lussac.net)
:: Last updated: 2020-02-19
:: Last updated: 2020-07-20
:: >>> Get updated from: https://github.com/LussacZheng/you-get.exe <<<
:: >>> EDIT AT YOUR OWN RISK. <<<
@echo off


rem ================= STEP 0: Root =================


:: Set the root directory
set "root=%~dp0"
set "root=%root:~0,-1%"
cd "%root%"


rem ================= STEP 1: Clean =================


if exist build\you-get\ rd /S /Q build\you-get
if exist dist\you-get.exe del /S /Q dist\you-get.exe >NUL 2>NUL
if exist dist\LICENSE.txt del /S /Q dist\LICENSE.txt >NUL 2>NUL
if exist dist\ (
pushd dist
if exist you-get.exe del /S /Q you-get.exe >NUL 2>NUL
if exist LICENSE.txt del /S /Q LICENSE.txt >NUL 2>NUL
if exist README.md del /S /Q README.md >NUL 2>NUL
if exist README_cn.md del /S /Q README_cn.md >NUL 2>NUL
popd
)


:: Step 2. Check
if NOT exist repository\you-get\you-get (
echo.
echo * Please run "devscripts\init.bat" first or clone the repository of "you-get".
pause > NUL
exit
)


rem ================= STEP 3: Build =================


cd repository

:: First, move out the original `__init__.py` from "you_get.extractors",
:: in order that we can recover everything after build.
:: Then copy all the extractors from `repository\_extractors\`, with a new `__init__.py`
:: which has imported these extractors, into the module "you_get.extractors"
move you-get\src\you_get\extractors\__init__.py .\ > NUL
xcopy _extractors\*.py you-get\src\you_get\extractors\ >NUL

pushd you-get

echo.
echo ============================================================
echo * pyinstaller "you-get" ...
echo ------------------------------------------------------------
echo.

:: PyInstaller bundle command - START
pyinstaller -F --path=src ^
--distpath ..\..\dist ^
Expand All @@ -43,30 +71,82 @@ pyinstaller -F --path=src ^
--hidden-import=you_get.util ^
you-get
:: PyInstaller bundle command - END
echo.
echo ============================================================
echo.

xcopy LICENSE.txt ..\..\dist\ >NUL

popd
:: Recover everything in you-get.git after build

:: Recover everything in you-get.git after built
for /f "delims=" %%i in ('dir /b /a-d _extractors') do (
del /Q you-get\src\you_get\extractors\%%i >NUL 2>NUL
)
move __init__.py you-get\src\you_get\extractors\ > NUL

cd ..\build
if exist file_version_info.txt (
pyi-set_version file_version_info.txt ..\dist\you-get.exe
echo.
echo ============================================================
echo.
pyi-set_version file_version_info.txt ..\dist\you-get.exe
)
cd ..

echo.
echo ============================================================
echo.
echo * Build logs saved in: "%~dp0build\you-get\"
echo * Build executable saved to: "%~dp0dist\you-get.exe"
echo * Build complete.
echo * Build completed.


rem ================= STEP 4: Zip =================


echo.
echo ============================================================
echo * zip "you-get.zip" ...
echo ------------------------------------------------------------
echo.

:: copy the files to be zipped
xcopy /Y repository\you-get\LICENSE.txt dist\ >NUL
xcopy /Y README.md dist\ >NUL
xcopy /Y README_cn.md dist\ >NUL

if NOT exist bin\zip.exe goto :no_zip_exe
if NOT exist bin\bzip2.dll goto :no_zip_exe

:: Get the version of you-get, arch of executable, and build date tag
:: --> %_version%, %_arch%, %_date%
:: ==> %_zip_archive%
if exist build\file_version_info.txt (
set "_info=file_version_info.txt"
) else ( set "_info=file_version_info.sample.txt" )
for /f "tokens=4 delims='" %%i in ('type "build\%_info%" ^| find "FileVersion"') do ( set "_version=%%i" )
for /f "tokens=5 delims='x" %%i in ('type "build\%_info%" ^| find "ProductVersion"') do ( set "_arch=%%i" )
if "%_arch%"=="86" ( set "_arch=32" )
for /f %%i in ('WMIC OS GET LocalDateTime ^| find "."') do ( set "_LDT=%%i" )
set "_date=%_LDT:~2,2%%_LDT:~4,2%%_LDT:~6,2%"
set "_zip_archive=you-get-%_version%-win%_arch%_UB%_date%.zip"

cd dist
..\bin\zip.exe %_zip_archive% you-get.exe LICENSE.txt README.md README_cn.md -z < LICENSE.txt

echo.
echo * Zip archive file saved to: "%~dp0dist\%_zip_archive%"
echo * Zip completed.
echo.
echo ============================================================
echo.
echo * All completed.
echo.
echo ============================================================
echo.

pause
goto :eof

:no_zip_exe
echo.
echo * Please download "zip.exe" and "bzip2.dll", and put them into "bin/".
pause > NUL
exit

10 changes: 6 additions & 4 deletions build/file_version_info.sample.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ VSVersionInfo(
ffi=FixedFileInfo(
# filevers and prodvers should be always a tuple with four items: (1, 2, 3, 4)
# Set not needed items to zero 0.
filevers=(0, 4, 1423, 0),
prodvers=(2020, 3, 24, 0),
filevers=(0, 4, 1456, 0),
prodvers=(2020, 7, 20, 0),
# Contains a bitmask that specifies the valid bits 'flags'r
mask=0x3f,
# Contains a bitmask that specifies the Boolean attributes of the file.
Expand All @@ -31,11 +31,13 @@ VSVersionInfo(
u'040904B0',
[StringStruct(u'Comments', u'Dumb downloader that scrapes the web'),
StringStruct(u'FileDescription', u'Dumb downloader that scrapes the web'),
StringStruct(u'FileVersion', u'0.4.1423'),
# '0.4.1456' or '0.4.1456.ur'
StringStruct(u'FileVersion', u'0.4.1456'),
StringStruct(u'OriginalFilename', u'you-get.exe'),
StringStruct(u'LegalCopyright', u'Released on GitHub@LussacZheng/you-get.exe'),
StringStruct(u'ProductName', u'You-Get Unofficial Build Executable for Windows'),
StringStruct(u'ProductVersion', u'UB200324_x64')])
# 'UB200720_x64' or 'UB200720_x86'
StringStruct(u'ProductVersion', u'UB200720_x64')])
]),
VarFileInfo([VarStruct(u'Translation', [1033, 1200])])
]
Expand Down
3 changes: 3 additions & 0 deletions devscripts/init.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
@rem - Encoding:utf-8; Mode:Batch; Language:en; LineEndings:CRLF -
@echo off

:: Set the root directory
cd "%~dp0"

call use-proxy.bat
cd ..\repository

Expand Down
3 changes: 3 additions & 0 deletions devscripts/update.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
@rem - Encoding:utf-8; Mode:Batch; Language:en; LineEndings:CRLF -
@echo off

:: Set the root directory
cd "%~dp0"

call use-proxy.bat
cd ..\repository

Expand Down

0 comments on commit fb62374

Please sign in to comment.