|
51 | 51 |
|
52 | 52 | FINISH_ENCRYPT_MSG = f""" |
53 | 53 | Encryption completed {SUCCESS_ANSI}. |
| 54 | +""" |
| 55 | + |
| 56 | +FINISH_ENCRYPT_WITH_LOADER_MSG = f""" |
| 57 | +{FINISH_ENCRYPT_MSG} |
54 | 58 | Please copy {LOADER_FILE_NAME} into your encrypted directory. |
55 | 59 | 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. |
57 | 61 | """ # noqa: W604 |
58 | 62 |
|
59 | 63 | FINISH_DECRYPT_MSG = f""" |
@@ -169,6 +173,12 @@ def cli(): |
169 | 173 | envvar=f"{ENVVAR_PREFIX}_KEY", |
170 | 174 | show_envvar=True, |
171 | 175 | ) |
| 176 | +@click.option( |
| 177 | + "--without-loader", |
| 178 | + default=False, |
| 179 | + help="Don't generate loader file", |
| 180 | + is_flag=True, |
| 181 | +) |
172 | 182 | @click.option( |
173 | 183 | "--with-license", default=False, help="Add license to encrypted file", is_flag=True |
174 | 184 | ) |
@@ -211,7 +221,7 @@ def cli(): |
211 | 221 | @click.help_option("-h", "--help") |
212 | 222 | @click.pass_context |
213 | 223 | 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 |
215 | 225 | ): |
216 | 226 | """Encrypt your python code""" |
217 | 227 | if key is None: |
@@ -247,12 +257,17 @@ def encrypt_command( |
247 | 257 | else: |
248 | 258 | raise Exception(f"{path} is not a valid path.") |
249 | 259 |
|
250 | | - cipher_key, d, n = encrypt_key(key.encode()) # 需要放进导入器中 |
251 | | - loader_extension = generate_so_file(cipher_key, d, n, license=with_license) |
252 | 260 | if with_license is True: |
253 | 261 | generate_license_file(key, Path(os.getcwd()), after, before, mac, ipv4) |
254 | 262 | 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)) |
256 | 271 |
|
257 | 272 |
|
258 | 273 | @cli.command(name="decrypt") |
|
0 commit comments