add clean command
This commit is contained in:
parent
574596dba7
commit
7c632047e4
46
src/pycage/clean.py
Normal file
46
src/pycage/clean.py
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import click
|
||||||
|
|
||||||
|
from pycage.helpers import get_interpreter, print_error
|
||||||
|
|
||||||
|
|
||||||
|
@click.group(help="commands to remove specified files")
|
||||||
|
def clean() -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def delete_files(
|
||||||
|
glob_pattern: str,
|
||||||
|
) -> None:
|
||||||
|
try:
|
||||||
|
pth_intp = get_interpreter()
|
||||||
|
except RuntimeError:
|
||||||
|
click.echo("Base interpreter path could not be found", err=True)
|
||||||
|
return
|
||||||
|
|
||||||
|
base_folder = pth_intp.parent
|
||||||
|
assert base_folder.is_dir(), "base folder not a directory"
|
||||||
|
precomp_files = base_folder.glob(glob_pattern)
|
||||||
|
for file in precomp_files:
|
||||||
|
file.unlink(missing_ok=True)
|
||||||
|
|
||||||
|
|
||||||
|
@click.command(help="removes all pre-compiled byte code files in the distribution")
|
||||||
|
def precompiled() -> None:
|
||||||
|
try:
|
||||||
|
delete_files(r"**/*.pyc")
|
||||||
|
except Exception as err:
|
||||||
|
print_error(err)
|
||||||
|
|
||||||
|
|
||||||
|
@click.command(help="removes all sensitive distribution data")
|
||||||
|
def dist_info() -> None:
|
||||||
|
try:
|
||||||
|
delete_files(r"**/*url.json")
|
||||||
|
except Exception as err:
|
||||||
|
print_error(err)
|
||||||
|
|
||||||
|
|
||||||
|
clean.add_command(precompiled)
|
||||||
|
clean.add_command(dist_info)
|
||||||
@ -2,6 +2,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import click
|
import click
|
||||||
|
|
||||||
|
import pycage.clean
|
||||||
import pycage.compile
|
import pycage.compile
|
||||||
import pycage.files
|
import pycage.files
|
||||||
import pycage.get
|
import pycage.get
|
||||||
@ -17,6 +18,7 @@ cli.add_command(pycage.get.get)
|
|||||||
cli.add_command(pycage.venv.venv)
|
cli.add_command(pycage.venv.venv)
|
||||||
cli.add_command(pycage.files.copy)
|
cli.add_command(pycage.files.copy)
|
||||||
cli.add_command(pycage.compile.compile)
|
cli.add_command(pycage.compile.compile)
|
||||||
|
cli.add_command(pycage.clean.clean)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
cli()
|
cli()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user