Skip to content

Commit

Permalink
Merge pull request #22 from akloeker/main
Browse files Browse the repository at this point in the history
Ignore empty .repos files in recursive VCS import
  • Loading branch information
lreiher authored Mar 12, 2024
2 parents 6e08e2f + fb840ea commit 4dd021d
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions docker/recursive_vcs_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,23 @@
from typing import List, Optional


def findDotRepos(search_path: str, clone_path: Optional[str] = None) -> List[pathlib.Path]:
def find_dot_repos(search_path: str, clone_path: Optional[str] = None) -> List[pathlib.Path]:

repos = list(pathlib.Path(search_path).glob("**/*.repos"))
if clone_path is not None:
repos.extend(list(pathlib.Path(clone_path).glob("**/*.repos")))
return repos

def is_file_empty(filename):
"""Check if file is empty, allowing blank spaces."""
try:
with open(filename, 'r') as file:
content = file.read().strip()
return len(content) == 0
except Exception as e:
print(e)
# Exception gets raised later
return False

def main():

Expand All @@ -22,7 +32,7 @@ def main():

while True:

found_repos = findDotRepos(search_path, clone_path)
found_repos = find_dot_repos(search_path, clone_path)
remaining_repos = set(found_repos) - set(cloned_repos)

if not remaining_repos:
Expand All @@ -32,7 +42,11 @@ def main():
with open(str(next_repo), "r") as f:
proc = subprocess.run(["vcs", "import", clone_path, "--recursive"], stdin=f)
if proc.returncode != 0:
raise RuntimeError("vcs import failed")
# Ignore empty .repos files
if not is_file_empty(next_repo):
raise RuntimeError("vcs import failed")
else:
print(f"Ignored empty .repos file: {next_repo}")

cloned_repos.append(next_repo)

Expand All @@ -41,3 +55,4 @@ def main():

if __name__ == "__main__":
main()

0 comments on commit 4dd021d

Please sign in to comment.