-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
34 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
from pip_upgrade.tools.cprint import ColoredPrint | ||
from pip_upgrade.tools.config import Config | ||
from pip_upgrade.tools.clear_cache import clear_cache | ||
|
||
# Initialize cprint | ||
cprint = ColoredPrint() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import sys | ||
import subprocess | ||
import shutil | ||
|
||
from pathlib import Path | ||
|
||
|
||
def clear_cache(): | ||
""" | ||
Clears pip cache | ||
""" | ||
arg_list = [sys.executable, '-m', 'pip', 'cache', 'dir'] | ||
output = subprocess.check_output(arg_list) | ||
output = output.decode("utf-8").replace("\n", "").replace("\r", "") | ||
|
||
# Dev - print folder size | ||
dev_path = Path(output) | ||
cache_size = sum(f.stat().st_size for f in dev_path.glob('**/*') if f.is_file()) | ||
cache_size = int((cache_size / 1024) / 1024) | ||
|
||
print(f'Folder will be deleted: {output} Size: {cache_size}MB') | ||
confirm = input('Continue? (y/n): ') | ||
|
||
if confirm.lower() == 'y': | ||
try: | ||
shutil.rmtree(output) | ||
print('Cache is cleared..') | ||
except Exception as e: | ||
print(e) | ||
else: | ||
print('Aborted, if the folder was wrong, please fill an issue.') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters