Skip to content

Commit f16a662

Browse files
ruff
1 parent c588e7c commit f16a662

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

build_tools/purge_archive.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
import shutil
44
import stat
55
from datetime import datetime, timedelta
6+
from typing import Callable
67

78
max_build_age_in_days = 7
89
minimum_number_of_builds_to_keep = 5
910
build_area = r"\\isis.cclrc.ac.uk\inst$\kits$\CompGroup\ICP"
1011

1112

12-
def winapi_path(dos_path):
13+
def winapi_path(dos_path: str) -> str:
1314
path = os.path.abspath(dos_path)
1415
long_path_identifier = "\\\\?\\"
1516
if path.startswith(long_path_identifier):
@@ -21,7 +22,7 @@ def winapi_path(dos_path):
2122
return win_path
2223

2324

24-
def rmtree_error(func, path, exc_info):
25+
def rmtree_error(func: Callable[[str], None], path: str, exc_info: tuple) -> None:
2526
try:
2627
if not os.access(path, os.W_OK):
2728
os.chmod(path, stat.S_IWUSR)
@@ -30,33 +31,33 @@ def rmtree_error(func, path, exc_info):
3031
print(f"Unable to delete file: {e}")
3132

3233

33-
def delete_dir(directory):
34+
def delete_dir(directory: str) -> None:
3435
print(f"Deleting directory: {directory}")
3536
try:
3637
shutil.rmtree(winapi_path(directory), onerror=rmtree_error)
3738
except Exception as e:
3839
print(f"Unable to delete directory {directory}: {e}")
3940

4041

41-
def delete_file(file):
42+
def delete_file(file: str) -> None:
4243
print(f"Deleting file: {file}")
4344
try:
4445
os.remove(winapi_path(file))
4546
except Exception as e:
4647
print(f"Unable to delete file {file}: {e}")
4748

4849

49-
def old_enough_to_delete(f):
50+
def old_enough_to_delete(f: str) -> bool:
5051
return datetime.now() - datetime.fromtimestamp(os.path.getmtime(f)) > timedelta(
5152
days=max_build_age_in_days
5253
)
5354

5455

55-
def is_build_dir(d):
56+
def is_build_dir(d: str) -> bool:
5657
return os.path.isdir(d) and "BUILD" in os.path.split(d)[-1].upper()
5758

5859

59-
def deletion_directories(project_areas):
60+
def deletion_directories(project_areas: list[str]) -> list[str]:
6061
dirs = []
6162
for project_area in project_areas:
6263
project_dirs = [os.path.join(project_area, sub_dir) for sub_dir in os.listdir(project_area)]
@@ -71,7 +72,7 @@ def deletion_directories(project_areas):
7172
return dirs
7273

7374

74-
def deletion_files(project_areas, pattern):
75+
def deletion_files(project_areas: list[str], pattern: str) -> list[str]:
7576
files = []
7677
for project_area in project_areas:
7778
files_by_age = sorted(
@@ -87,7 +88,7 @@ def deletion_files(project_areas, pattern):
8788
return files
8889

8990

90-
def purge(dry_run=False):
91+
def purge(dry_run: bool = False) -> None:
9192
print("Beginning archive purge...")
9293
project_areas = [
9394
os.path.join(build_area, proj)

0 commit comments

Comments
 (0)