Skip to content

Commit 3e97408

Browse files
committed
Address comments
1 parent 039195e commit 3e97408

File tree

4 files changed

+41
-12
lines changed

4 files changed

+41
-12
lines changed

ci/fireci/fireci/ci_utils.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import os
1717
import subprocess
1818

19-
from typing import List
19+
from typing import List, Tuple, Union
2020

2121
_logger = logging.getLogger('fireci.ci_utils')
2222

@@ -69,3 +69,22 @@ def get_projects(file_path: str = "subprojects.cfg") -> List[str]:
6969
with open(file_path, 'r') as file:
7070
stripped_lines = [line.strip() for line in file]
7171
return [line for line in stripped_lines if line and not line.startswith('#')]
72+
73+
def counts(arr: List[Union[bool, int]]) -> Tuple[int, int]:
74+
"""Given an array of booleans and ints, returns a tuple mapping of [true, false].
75+
Positive int values add to the `true` count while values less than one add to `false`.
76+
"""
77+
true_count = 0
78+
false_count = 0
79+
for value in arr:
80+
if isinstance(value, bool):
81+
if value:
82+
true_count += 1
83+
else:
84+
false_count += 1
85+
elif value >= 1:
86+
true_count += value
87+
else:
88+
false_count += abs(value) if value < 0 else 1
89+
90+
return true_count, false_count

ci/fireci/fireci/dir_utils.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,13 @@ def rmdir(path: str) -> bool:
4747

4848
def rmglob(pattern: str) -> int:
4949
"""Deletes all files that match a given pattern, and returns the amount of (root) files deleted"""
50-
files = 0
51-
for file in glob.glob(os.path.expanduser(pattern)):
50+
files = glob.glob(os.path.expanduser(pattern))
51+
for file in files:
5252
path = pathlib.Path(file)
5353
if path.is_dir():
5454
rmdir(file)
5555
else:
5656
_logger.debug(f"Deleting file: {path}")
5757
os.remove(path)
58-
files += 1
59-
60-
return files
58+
59+
return len(files)

ci/fireci/fireciplugins/clean.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
from fireci import ci_command
1919
from fireci import ci_utils
2020
from fireci import dir_utils
21+
from typing import Tuple
22+
from termcolor import colored
2123

2224
log = logging.getLogger('fireci.clean')
2325

@@ -63,10 +65,10 @@ def clean(projects, gradle, build, transforms, build_cache, deep, cache):
6365
if build:
6466
cleaners.append(delete_build)
6567
if gradle:
66-
cleaners.append(delete_build)
68+
cleaners.append(delete_gradle)
6769

6870
results = [call_and_sum(projects, cleaner) for cleaner in cleaners]
69-
delete_count = sum(map(int, results))
71+
local_count = tuple(map(sum, zip(*results)))
7072

7173
cleaners = []
7274

@@ -81,13 +83,21 @@ def clean(projects, gradle, build, transforms, build_cache, deep, cache):
8183
cleaners.append(delete_build_cache)
8284

8385
results = [cleaner() for cleaner in cleaners]
84-
delete_count += sum(map(int, results))
86+
system_count = ci_utils.counts(results)
87+
88+
[deleted, skipped] = tuple(a + b for a, b in zip(local_count, system_count))
89+
90+
log.info(f"""
91+
Clean results:
92+
93+
{colored("Deleted:", None, attrs=["bold"])} {colored(deleted, "red")}
94+
{colored("Already deleted:", None, attrs=["bold"])} {colored(skipped, "grey")}
95+
""")
8596

86-
log.info(f"Deleted {delete_count} directories/files")
8797

88-
def call_and_sum(variables, func) -> int:
98+
def call_and_sum(variables, func) -> Tuple[int, int]:
8999
results = map(lambda var: func(var), variables)
90-
return sum(map(int, results))
100+
return ci_utils.counts(results)
91101

92102
def delete_build(dir: str) -> bool:
93103
return dir_utils.rmdir(f"{dir}/build")

ci/fireci/setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ install_requires =
1515
requests==2.31.0
1616
seaborn==0.12.2
1717
PyYAML==6.0.1
18+
termcolor==2.5.0
1819

1920
[options.extras_require]
2021
test =

0 commit comments

Comments
 (0)