aboutsummaryrefslogtreecommitdiffstats
path: root/fpga/.ci/scripts/cleanup_incomplete_ip_builds.py
blob: 75c08db725ed4a16bb39b49ecedfb6947c410b83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python3
#
# Copyright 2021 Ettus Research, a National Instruments Brand
#
# SPDX-License-Identifier: LGPL-3.0-or-later
#
# Description:
#
#   Our pipelines reuse IP builds to save time. In the case where an IP build
#   fails or is terminated before completion, it is sometimes necessary to
#   clean up the build so that the next build can complete properly. This
#   script searches for and deletes any incomplete IP builds.
#

import argparse
import os
import shutil

# argument parsing
parser = argparse.ArgumentParser(description="This script removes all directories where the .build_lock file still exists")
parser.add_argument('--directory', '-d', required=True, help='directory to search for lock files (recursively)')
args = parser.parse_args()

# search .build_lock files
lockFiles = []
for root, dirs, files in os.walk(args.directory):
  for file in files:
    if file == ".build_lock":
      lockFiles.append(os.path.join(root, file))

# remove all directories containing lock files
for lockFile in lockFiles:
  dirPath = os.path.dirname(lockFile)
  print("delete " + dirPath)
  shutil.rmtree(dirPath)