Skip to content

Commit 1877e6f

Browse files
committed
feat: 🎸 support --without-loader option
Closes: #59
1 parent da44d1c commit 1877e6f

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ Options:
6767
-k, --key 🔑 Your encryption key.If you don‘t specify
6868
key, pyencrypt will generate encryption key
6969
randomly. [env var: PYE_ENCRYPT_KEY]
70+
--without-loader Don't generate loader file
7071
--with-license Add license to encrypted file
7172
-m, --bind-mac 01:23:45:67:89:AB
7273
Bind mac address to encrypted file

pyencrypt/cli.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,13 @@
5151

5252
FINISH_ENCRYPT_MSG = f"""
5353
Encryption completed {SUCCESS_ANSI}.
54+
"""
55+
56+
FINISH_ENCRYPT_WITH_LOADER_MSG = f"""
57+
{FINISH_ENCRYPT_MSG}
5458
Please copy {LOADER_FILE_NAME} into your encrypted directory.
5559
And then remove `encrypted` directory.
56-
Finally, add `import loader` at the top of your entry file.\n
60+
Finally, add `import loader` at the top of your entry file.
5761
""" # noqa: W604
5862

5963
FINISH_DECRYPT_MSG = f"""
@@ -169,6 +173,12 @@ def cli():
169173
envvar=f"{ENVVAR_PREFIX}_KEY",
170174
show_envvar=True,
171175
)
176+
@click.option(
177+
"--without-loader",
178+
default=False,
179+
help="Don't generate loader file",
180+
is_flag=True,
181+
)
172182
@click.option(
173183
"--with-license", default=False, help="Add license to encrypted file", is_flag=True
174184
)
@@ -211,7 +221,7 @@ def cli():
211221
@click.help_option("-h", "--help")
212222
@click.pass_context
213223
def encrypt_command(
214-
ctx, pathname, replace, key, with_license, mac, ipv4, before, after
224+
ctx, pathname, replace, key, without_loader, with_license, mac, ipv4, before, after
215225
):
216226
"""Encrypt your python code"""
217227
if key is None:
@@ -247,12 +257,17 @@ def encrypt_command(
247257
else:
248258
raise Exception(f"{path} is not a valid path.")
249259

250-
cipher_key, d, n = encrypt_key(key.encode()) # 需要放进导入器中
251-
loader_extension = generate_so_file(cipher_key, d, n, license=with_license)
252260
if with_license is True:
253261
generate_license_file(key, Path(os.getcwd()), after, before, mac, ipv4)
254262
click.echo(FINISH_GENERATE_LICENSE_MSG)
255-
click.echo(FINISH_ENCRYPT_MSG.format(loader_extension.name))
263+
264+
if without_loader is True:
265+
click.echo(FINISH_ENCRYPT_MSG)
266+
return
267+
268+
cipher_key, d, n = encrypt_key(key.encode()) # 需要放进导入器中
269+
loader_extension = generate_so_file(cipher_key, d, n, license=with_license)
270+
click.echo(FINISH_ENCRYPT_WITH_LOADER_MSG.format(loader_extension.name))
256271

257272

258273
@cli.command(name="decrypt")

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,4 @@ profile = black
6969

7070
[flake8]
7171
max-line-length = 88
72-
extend-ignore = E203,E701,E501
72+
extend-ignore = E203,E701,E501,C901

0 commit comments

Comments
 (0)