Skip to content

Commit 3e70a75

Browse files
committed
Add usage
1 parent 1331a3d commit 3e70a75

3 files changed

Lines changed: 202 additions & 3 deletions

File tree

src/MANIFEST.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
include ../README.md
1+
include README.rst usage.md
22
include pyshield.key pyshield.lic public.key product.key license.lic
33
recursive-include example *.py README LINCESE
4-
graft platforms
4+
graft platforms

src/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from distutils.core import setup
1313

1414
def get_description():
15-
README = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'README.md'))
15+
README = os.path.abspath(os.path.join(os.path.dirname(__file__), 'README.rst'))
1616
with open(README, 'r') as f:
1717
return f.read()
1818

src/usage.md

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
# Basic Usages
2+
3+
Here are some exampes to show basic usage of [Pyarmor].
4+
5+
All of first,
6+
7+
- Open a command box, enter the path of [Pyarmor] installed
8+
- Run pyarmor.py with your favor python
9+
10+
Then following the steps below to learn how to use [Pyarmor]
11+
12+
## Import encrypted module
13+
14+
The common usage for Pyarmor is to encrypted some python modules,
15+
import them in normal python environments.
16+
17+
[pybench](examples/pybench) is a collection of tests that provides a
18+
standardized way to measure the performance of Python
19+
implementations. It's an exactly one package to verify this
20+
feature. We'll encrypted 2 scripts [Strings.py](examples/Strings.py)
21+
and [Lists.py](examples/Lists.py), then import them by pybench.
22+
23+
### Generate a project capsule
24+
25+
Use command "capsule"
26+
27+
``` bash
28+
python pyarmor.py capsule pybench
29+
```
30+
31+
Project capsule is a compressed zip file, which include all the files
32+
used when encrypting scripts. This command will generate "pybench.zip"
33+
in the current path.
34+
35+
Generally, one capsule is only used for one project.
36+
37+
### Encrypt modules
38+
39+
Use command "encrypt"
40+
41+
``` bash
42+
python pyarmor.py encrypt --with-capsule=pybench.zip --in-place --output=dist --src=examples/pybench Lists.py Strings.py
43+
```
44+
45+
* --with-capsule specifies project capsule generated above. It's required.
46+
* --in-place tell pyarmor save encrypted files in the same path of original file
47+
* --src specifies relative path of scripts
48+
49+
This command will encrypt two scripts saved to
50+
51+
```
52+
examples/pybench/Lists.pye
53+
examples/pybench/Strings.pye
54+
```
55+
56+
and generate some extra files in the output path "dist":
57+
58+
```
59+
pyshield.key
60+
pyshield.lic
61+
product.key
62+
* license.lic
63+
64+
pyimcore.py
65+
pytransform.py
66+
_pytransofrm.dll or _pytransofrm.so
67+
```
68+
69+
### Imported encrypted module
70+
71+
* Copy all the files in the path "dist/" to "examples/pybench"
72+
* Add one line "import pyimcore" in the file "examples/pybench/pybench.py"
73+
* Remove "examples/pybench/Lists.py" and "examples/pybench/Strings.py"
74+
* Run pybench.py
75+
76+
Both Lists.py and Strings.py are removed, they are replaced with
77+
"Lists.pye" and "Strings.pye". pybench.py still works, that's what
78+
pyarmor does.
79+
80+
## Bind encrypted script to fix machine or expired it
81+
82+
Maybe you want to import encrypted scripts only in some special
83+
machine, or expired it at some point. Pyarmor command "license" is
84+
just for this case.
85+
86+
Command "encrypt" generates some extra files include "license.lic". In
87+
above example, it's in the output path "dist". It's necessary to run
88+
or import encrypted scripts. This file is a part of project capsule,
89+
can be used in any machine and never expired.
90+
91+
Command "license" will generate special "license.lic", which could be
92+
bind to fixed machine or expired.
93+
94+
Now let's generate a license file bind to this machine, first got
95+
96+
``` bash
97+
python pyarmor.py hdinfo
98+
99+
It prints harddisk infomation as the floowing
100+
101+
Harddisk's serial number is '100304PBN2081SF3NJ5T'
102+
```
103+
104+
Run command "license"
105+
```
106+
python pyarmor.py encrypt --with-capsule=pybench.zip --bind-disk "100304PBN2081SF3NJ5T"
107+
```
108+
109+
This command will generate a "license.lic.txt" in the current path.
110+
111+
Continue above example, replace "examples/pybench/license.lic" with this "license.lic.txt"
112+
```
113+
cp license.lic.txt examples/pybench/license.lic
114+
```
115+
116+
Run pybench.py again
117+
118+
``` bash
119+
cd examples/pybench
120+
python pybench.py
121+
```
122+
123+
It should work in this machine. If you copy "examples/pybench" to
124+
other machine, it will failed to run pybench.py because encrypted
125+
modules "Strings.pye" and "Lists.pye" could not be imported
126+
127+
### Generate a expired license
128+
```
129+
python pyarmor.py encrypt --with-capsule=pybench.zip --expired-date=2018-05-30
130+
```
131+
The "license.lic.txt" generate by this command will expired on May 30, 2018
132+
133+
### Combined license
134+
```
135+
python pyarmor.py encrypt --with-capsule=pybench.zip --expired-date=2018-05-30 --bind-disk "100304PBN2081SF3NJ5T"
136+
```
137+
138+
The "license.lic.txt" generate by this command will expired on May 30,
139+
2018 and only could be used in this machine.
140+
141+
## Run encrypted script
142+
143+
[examples/queens.py](examples/queens.py) is a script to solve eight
144+
queens problem. This example show you how to run encrypted queens.py
145+
146+
### Generate a project capsule
147+
```
148+
python pyarmor.py capsule project
149+
```
150+
151+
This command will generate "project.zip" in current path.
152+
153+
### Encrypt script
154+
```
155+
python pyarmor.py encrypt --with-capsule=project2.zip --main=queens --output=examples/runtime examples/queens.py
156+
```
157+
* --main tells pyarmor generate a wrapper script named "queens.py" in output path.
158+
159+
After this command, the script "queens.py" will be encrypted and saved
160+
to "examples/runtime/queens.pye" , and all the extra files to run
161+
encrypted "queens.pye" in the output path "examples/runtime".
162+
163+
The file list of "examples/runtime"
164+
165+
```
166+
pyshield.key
167+
pyshield.lic
168+
product.key
169+
license.lic
170+
171+
pyimcore.py
172+
pytransform.py
173+
_pytransofrm.dll or _pytransofrm.so
174+
175+
queens.py
176+
queens.pye
177+
178+
```
179+
180+
### Run encrypted script
181+
182+
``` bash
183+
cd examples/runtime
184+
python queens.py -n 8
185+
```
186+
187+
Note that this queens.py is wrapper to run encrypted queens.pye, the
188+
content of it would be
189+
190+
``` python
191+
import pyimcore
192+
from pytransform import exec_file
193+
exec_file("queens.pye")
194+
```
195+
196+
# Command Line Options
197+
198+
199+
[Pyarmor]: https://github.com/dashingsoft/pyarmor

0 commit comments

Comments
 (0)