Skip to content

Commit 416532f

Browse files
committed
Simple sample script
1 parent f6705c3 commit 416532f

File tree

5 files changed

+43
-87
lines changed

5 files changed

+43
-87
lines changed

src/examples/build-with-project.bat

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,24 @@ SETLOCAL
1414
REM TODO:
1515
SET PYTHON=C:\Python34\python.exe
1616

17-
REM TODO: Where to find pyarmor.py
18-
SET PYARMOR_PATH=C:\Python34\Lib\site-packages\pyarmor
17+
REM TODO:
18+
SET PYARMOR=C:\Python34\Scripts\pyarmor.exe
1919

20-
REM TODO: Absolute path in which all python scripts will be obfuscated
21-
SET SOURCE=%PYARMOR_PATH%\examples\simple
20+
REM TODO: In which all python scripts will be obfuscated
21+
SET SOURCE=C:\Python34\Lib\site-packages\pyarmor\examples\simple
2222
REM TODO: Entry script filename, must be relative to %SOURCE%
2323
SET ENTRY_SCRIPT=queens.py
2424

2525
REM For package, uncomment the following lines
26-
rem SET SOURCE=%PYARMOR_PATH%\examples\testpkg\mypkg
26+
rem SET SOURCE=C:\Python34\Lib\site-packages\pyarmor\examples\testpkg\mypkg
2727
rem SET PKGNAME=mypkg
2828
rem SET ENTRY_SCRIPT=__init__.py
2929

3030
REM TODO: output path for saving project config file, and obfuscated scripts
31-
SET PROJECT=%PYARMOR_PATH%\examples\armor-project
31+
SET PROJECT=C:\Python34\Lib\site-packages\pyarmor\projects\project1
3232

3333
REM TODO: Filter the source files, exclude all the scripts in test
34-
rem SET PROJECT_FILTER=global-include *.py, prune test
34+
rem SET PROJECT_FILTER=global-include *.py, prune test, prune build
3535

3636
REM TODO: If generate new license for obfuscated scripts, uncomment next line
3737
rem SET LICENSE_CODE=any-identify-string
@@ -55,23 +55,6 @@ rem ECHO Package name is %PKGNAME%
5555
rem ECHO.
5656
rem )
5757

58-
REM Check Python
59-
%PYTHON% --version
60-
IF NOT ERRORLEVEL 0 (
61-
ECHO.
62-
ECHO Python doesn't work, check value of variable PYTHON
63-
ECHO.
64-
GOTO END
65-
)
66-
67-
REM Check Pyarmor
68-
IF NOT EXIST "%PYARMOR_PATH%\pyarmor.py" (
69-
ECHO.
70-
ECHO No pyarmor found, check value of variable PYARMOR_PATH
71-
ECHO.
72-
GOTO END
73-
)
74-
7558
REM Check Source
7659
IF NOT EXIST "%SOURCE%" (
7760
ECHO.
@@ -90,8 +73,7 @@ IF NOT EXIST "%SOURCE%\%ENTRY_SCRIPT%" (
9073

9174
REM Create a project
9275
ECHO.
93-
CD /D %PYARMOR_PATH%
94-
%PYTHON% pyarmor.py init --src=%SOURCE% --entry=%ENTRY_SCRIPT% %PROJECT%
76+
%PYARMOR% init --src=%SOURCE% --entry=%ENTRY_SCRIPT% %PROJECT%
9577
IF NOT ERRORLEVEL 0 GOTO END
9678
ECHO.
9779

src/examples/build-with-project.sh

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
# TODO: python interpreter
1212
PYTHON=python
1313

14-
# TODO: Absolute path of pyarmor installed, where to find pyarmor.py
15-
PYARMOR_PATH=/usr/local/lib/python2.7/dist-packages/pyarmor
14+
# TODO:
15+
PYARMOR=pyarmor
1616

1717
# TODO: Absolute path in which all python scripts will be obfuscated
1818
SOURCE=/home/jondy/workspace/project/src
@@ -48,29 +48,25 @@ if [[ "${ENTRY_SCRIPT}" == "__init__.py" ]] ; then
4848
echo -e "\nPackage name is $PKGNAME\n"
4949
fi
5050

51-
# Project convenient command
52-
PYARMOR=./pyarmor
53-
5451
# Create a project
55-
cd ${PYARMOR_PATH}
56-
$PYTHON pyarmor.py init --src=$SOURCE --entry=${ENTRY_SCRIPT} $PROJECT || exit 1
52+
$PYARMOR init --src=$SOURCE --entry=${ENTRY_SCRIPT} $PROJECT || exit 1
5753

5854
# Change to project path, there is a convenient script pyarmor.bat
5955
cd $PROJECT
6056

6157
# Filter source files by config project filter
6258
if [[ -n "${PROJECT_FILTER}" ]] ; then
63-
$PYARMOR config --manifest "${PROJECT_FILTER}" || exit 1
59+
./pyarmor config --manifest "${PROJECT_FILTER}" || exit 1
6460
fi
6561

6662

6763
# Obfuscate scripts by command build
68-
$PYARMOR build || exit 1
64+
./pyarmor build || exit 1
6965

7066
# Generate special license if any
7167
if [[ -n "${LICENSE_CODE}" ]] ; then
7268
echo
73-
$PYARMOR licenses ${LICENSE_EXPIRED_DATE} ${LICENSE_HARDDISK_SERIAL_NUMBER} \
69+
./pyarmor licenses ${LICENSE_EXPIRED_DATE} ${LICENSE_HARDDISK_SERIAL_NUMBER} \
7470
${LICENSE_MAC_ADDR} ${LICENSE_IPV4_ADDR} ${LICENSE_CODE} || exit 1
7571
echo
7672

src/examples/obfuscate-app.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ SETLOCAL
1010
REM TODO:
1111
SET PYTHON=C:\Python34\python.exe
1212

13-
REM TODO: Where to find pyarmor.py
13+
REM TODO:
1414
SET PYARMOR=C:\Python34\Scripts\pyarmor.exe
1515

1616
REM TODO: Entry script filename

src/examples/obfuscate-pkg.bat

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,69 +10,51 @@ SETLOCAL
1010
REM TODO:
1111
SET PYTHON=C:\Python34\python.exe
1212

13-
REM TODO: Where to find pyarmor.py
14-
SET PYARMOR_PATH=C:\Python34\Lib\site-packages\pyarmor
13+
REM TODO:
14+
SET PYARMOR=C:\Python34\Scripts\pyarmor.exe
1515

16-
REM TODO: Absolute path in which all python scripts will be obfuscated
17-
SET SOURCE=%PYARMOR_PATH%\examples\testpkg
16+
REM TODO: Package path
17+
SET PKGPATH=C:\Python34\Lib\site-packages\pyarmor\examples\testpkg
1818

19-
REM TODO: Package name, __init__.py shoule be in %SOURCE%\%PKGNAME%
19+
REM TODO: Package name, __init__.py shoule be in %PKGPATH%\%PKGNAME%
2020
SET PKGNAME=mypkg
21+
SET ENTRY_SCRIPT=%PKGPATH%\%PKGNAME%\__init__.py
2122

2223
REM TODO: Output path for obfuscated package and runtime files
23-
SET OUTPUT=%PYARMOR_PATH%\examples\pkg-dist
24+
SET OUTPUT=C:\Python34\Lib\site-packages\pyarmor\examples\dist
2425

2526
REM TODO: Comment next line if do not try to test obfuscated package
2627
SET TEST_OBFUSCATED_PACKAGE=1
2728

2829
REM TODO: Let obfuscated package expired on some day, uncomment next line
29-
SET LICENSE_EXPIRED_DATE=2019-01-01
30-
31-
REM Check Python
32-
%PYTHON% --version
33-
IF NOT ERRORLEVEL 0 (
34-
ECHO.
35-
ECHO Python doesn't work, check value of variable PYTHON
36-
ECHO.
37-
GOTO END
38-
)
39-
40-
REM Check Pyarmor
41-
IF NOT EXIST "%PYARMOR_PATH%\pyarmor.py" (
42-
ECHO.
43-
ECHO No pyarmor found, check value of variable PYARMOR_PATH
44-
ECHO.
45-
GOTO END
46-
)
30+
rem SET LICENSE_EXPIRED_DATE=2019-01-01
4731

48-
REM Check Source
49-
IF NOT EXIST "%SOURCE%" (
32+
REM Check Package
33+
IF NOT EXIST "%PKGPATH%" (
5034
ECHO.
51-
ECHO No %SOURCE% found, check value of variable SOURCE
35+
ECHO No %PKGPATH% found, check value of variable PKGPATH
5236
ECHO.
5337
GOTO END
5438
)
5539

56-
REM Check package
57-
SET PKGPATH=%SOURCE%\%PKGNAME%
58-
IF NOT EXIST "%PKGPATH%\__init__.py" (
40+
REM Check entry script
41+
IF NOT EXIST "%ENTRY_SCRIPT%" (
5942
ECHO.
60-
ECHO No %PKGPATH%\__init__.py found, check value of variable PKGNAME
43+
ECHO No %ENTRY_SCRIPT% found, check value of variable PKGNAME
6144
ECHO.
6245
GOTO END
6346
)
6447

6548
REM Obfuscate scripts
6649
ECHO.
67-
CD /D %PYARMOR_PATH%
68-
%PYTHON% pyarmor.py obfuscate --recursive --no-restrict --src %PKGPATH% --entry __init__.py --output %OUTPUT%\%PKGNAME%
50+
%PYARMOR% obfuscate --recursive --output %OUTPUT%\%PKGNAME% %ENTRY_SCRIPT%
6951
IF NOT ERRORLEVEL 0 GOTO END
7052
ECHO.
7153

7254
REM Generate an expired license if LICENSE_EXPIRED_DATE is set
7355
SET LICENSE_CODE=expired-%LICENSE_EXPIRED_DATE%
7456
IF DEFINED LICENSE_EXPIRED_DATE (
75-
%PYTHON% pyarmor.py licenses --expired %LICENSE_EXPIRED_DATE% %LICENSE_CODE%
57+
%PYARMOR% licenses --expired %LICENSE_EXPIRED_DATE% %LICENSE_CODE%
7658
IF NOT ERRORLEVEL 0 GOTO END
7759

7860
REM Overwrite default license with this expired license

src/examples/obfuscate-pkg.sh

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@
44
# Before run it, all TODO variables need to set correctly.
55
#
66

7-
# TODO: python interpreter
7+
# TODO:
88
PYTHON=python
99

10-
# TODO: Absolute path of pyarmor installed, where to find pyarmor.py
11-
PYARMOR_PATH=/usr/local/lib/python2.7/dist-packages/pyarmor
10+
# TODO:
11+
PYARMOR=pyarmor
1212

13-
# TODO: Absolute path in which all python scripts will be obfuscated
14-
SOURCE=/home/jondy/workspace/project/src
13+
# TODO: Package path
14+
PKGPATH=/home/jondy/workspace/project/src
1515

16-
# TODO: Package name, __init__.py shoule be in $SOURCE/$PKGNAME
16+
# TODO: Package name, __init__.py shoule be in $PKGPATH/$PKGNAME
1717
PKGNAME=foo
18+
ENTRY_SCRIPT=$PKGPATH/$PKGNAME/__init__.py
1819

1920
# TODO: Output path for obfuscated package and runtime files
2021
OUTPUT=/home/jondy/workspace/project/dist
@@ -26,26 +27,21 @@ TEST_OBFUSCATED_PACKAGE=1
2627
# LICENSE_EXPIRED_DATE=2019-01-01
2728

2829
# Check package
29-
PKGPATH=$SOURCE/$PKGNAME
30-
if ! [[ -d "$SOURCE" ]] ; then
31-
echo "No $SOURCE found, check variable SOURCE" && exit 1
32-
fi
3330
if ! [[ -d "$PKGPATH" ]] ; then
34-
echo "No $PKGNAME found, check variable PKGNAME" && exit 1
31+
echo "No $PKGPATH found, check variable PKGPATH" && exit 1
3532
fi
36-
if ! [[ -f "$PKGPATH/__init__.py" ]] ; then
37-
echo "No __init__.py found in $PKGPATH, check variable SOURCE and PKGNAME" && exit 1
33+
if ! [[ -d "${ENTRY_SCRIPT}" ]] ; then
34+
echo "No ${ENTRY_SCRIPT} found, check variable PKGPATH and PKGNAME" && exit 1
3835
fi
3936

4037
# Obfuscate scripts
41-
cd ${PYARMOR_PATH}
42-
$PYTHON pyarmor.py obfuscate --recursive --no-restrict --src "$PKGPATH" --entry "__init__.py" --output "${OUTPUT}/$PKGNAME" || exit 1
38+
$PYARMOR obfuscate --recursive --output "${OUTPUT}/$PKGNAME" "${ENTRY_SCRIPT}" || exit 1
4339

4440
# Generate an expired license if any
4541
if [[ -n "${LICENSE_EXPIRED_DATE}" ]] ; then
4642
echo
4743
LICENSE_CODE="expired-${LICENSE_EXPIRED_DATE}"
48-
$PYTHON pyarmor.py licenses --expired ${LICENSE_EXPIRED_DATE} ${LICENSE_CODE} || exit 1
44+
$PYARMOR licenses --expired ${LICENSE_EXPIRED_DATE} ${LICENSE_CODE} || exit 1
4945
echo
5046

5147
# Overwrite default license with this expired license

0 commit comments

Comments
 (0)