Skip to content

Commit

Permalink
feat: 🎸 add progressbar
Browse files Browse the repository at this point in the history
Closes: #9
  • Loading branch information
ZhaoQi99 committed Nov 24, 2021
1 parent 6273274 commit 1bad6b1
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions pyencrypt/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def encrypt_command(ctx, pathname, delete, key):
ctx.fail(f'Your encryption key is invalid.')
if key is None:
key = generate_aes_key().decode()
click.echo(f'Your randomly encryption key is {key}')
click.echo(f'Your randomly encryption 🔑 is {key}')

path = Path(pathname)
work_dir = Path(os.getcwd()) / 'encrypted' / 'src'
Expand All @@ -103,12 +103,13 @@ def encrypt_command(ctx, pathname, delete, key):
shutil.copytree(path, work_dir)
files = set(path.glob('**/*.py')) - set(
path.glob(f'encrypted/**/*.py'))
for file in files:
if can_encrypt(file):
print(file)
new_path = work_dir / file.relative_to(path)
new_path.unlink()
encrypt_file(file, key, delete, new_path.with_suffix('.pye'))
with click.progressbar(files, label='🔐 Encrypting') as bar:
for file in bar:
if can_encrypt(file):
new_path = work_dir / file.relative_to(path)
new_path.unlink()
encrypt_file(file, key, delete,
new_path.with_suffix('.pye'))
else:
raise Exception(f'{path} is not a valid path.')

Expand Down Expand Up @@ -139,10 +140,10 @@ def decrypt_command(pathname, key):
work_dir.exists() and shutil.rmtree(work_dir)
shutil.copytree(path, work_dir)
files = list(path.glob('**/*.pye'))
for file in files:
print(file)
new_path = work_dir / file.relative_to(path)
decrypt_file(file, key, new_path)
with click.progressbar(files, label='🔓 Decrypting') as bar:
for file in files:
new_path = work_dir / file.relative_to(path)
decrypt_file(file, key, new_path)
else:
raise Exception(f'{path} is not a valid path.')

Expand Down

0 comments on commit 1bad6b1

Please sign in to comment.