changed the indent of some stuff to make it more

make sense
This commit is contained in:
Karma Riuk
2025-02-28 18:04:19 +01:00
parent 1c4a873fdc
commit 919a568faa

View File

@ -118,15 +118,6 @@ def remove_dir(dir: str) -> None:
if os.listdir(parent) == []: if os.listdir(parent) == []:
shutil.rmtree(parent) shutil.rmtree(parent)
def create_docker_container(client):
container = client.containers.run(
image="crab-java-env",
command="tail -f /dev/null",
detach=True,
tty=True
)
return container
def execute_in_container(container, command): def execute_in_container(container, command):
exec_result = container.exec_run(command, stream=True) exec_result = container.exec_run(command, stream=True)
output = "".join([line.decode() for line in exec_result.output]) output = "".join([line.decode() for line in exec_result.output])
@ -174,49 +165,54 @@ def test_repo(build_file: str, container, updates: dict) -> bool:
return True return True
def process_row(repo, client, dest: str, force: bool = False, verbose: bool = False) -> dict: def process_row(repo, client, dest: str, updates: dict, force: bool = False, verbose: bool = False) -> None:
updates = {} with tqdm(total=5, leave=False) as pbar:
container = create_docker_container(client) if repo in EXCLUSION_LIST:
updates["error_msg"] = "Repo in exclusion list"
if verbose: print(f"Skipping {repo}, in exclusion list")
return
try: pbar.set_postfix_str("Cloning...")
with tqdm(total=5, leave=False) as pbar: if force:
if repo in EXCLUSION_LIST: clone(repo, dest, updates, verbose=verbose)
updates["error_msg"] = "Repo in exclusion list" pbar.update(1)
if verbose: print(f"Skipping {repo}, in exclusion list")
return updates
pbar.set_postfix_str("Cloning...") repo_path = os.path.join(dest, repo)
if force: if not os.path.exists(repo_path):
clone(repo, dest, updates, verbose=verbose) updates["error_msg"] = "Repo not cloned"
pbar.update(1) return
repo_path = os.path.join(dest, repo) pbar.set_postfix_str("Getting build file...")
if not os.path.exists(repo_path): build_file = get_build_file(dest, repo, updates)
updates["error_msg"] = "Repo not cloned" if build_file is None:
return updates if verbose: print(f"Removing {repo}, no build file")
remove_dir(repo_path)
return
pbar.update(1)
pbar.set_postfix_str("Checking for tests...")
if not has_tests(repo_path, build_file, updates):
if verbose: print(f"Removing {repo}, no test suites")
remove_dir(repo_path)
return
if verbose: print(f"Keeping {repo}")
pbar.update(1)
pbar.set_postfix_str("Getting build file...") container = client.containers.run(
build_file = get_build_file(dest, repo, updates) image="crab-java-env",
if build_file is None: command="tail -f /dev/null",
if verbose: print(f"Removing {repo}, no build file") volumes={os.path.abspath(repo_path): {"bind": "/repo", "mode": "rw"}},
remove_dir(repo_path) detach=True,
return updates tty=True
pbar.update(1) )
pbar.set_postfix_str("Checking for tests...")
if not has_tests(repo_path, build_file, updates):
if verbose: print(f"Removing {repo}, no test suites")
remove_dir(repo_path)
return updates
if verbose: print(f"Keeping {repo}")
pbar.update(1)
try:
pbar.set_postfix_str("Compiling...") pbar.set_postfix_str("Compiling...")
compiled = compile_repo(build_file, container, updates) compiled = compile_repo(build_file, container, updates)
if not compiled: if not compiled:
if verbose: print(f"Removing {repo}, failed to compile") if verbose: print(f"Removing {repo}, failed to compile")
remove_dir(repo_path) remove_dir(repo_path)
return updates return
pbar.update(1) pbar.update(1)
pbar.set_postfix_str("Runing tests...") pbar.set_postfix_str("Runing tests...")
@ -224,16 +220,14 @@ def process_row(repo, client, dest: str, force: bool = False, verbose: bool = Fa
if not compiled: if not compiled:
if verbose: print(f"Removing {repo}, failed to compile") if verbose: print(f"Removing {repo}, failed to compile")
remove_dir(repo_path) remove_dir(repo_path)
return updates return
pbar.update(1) pbar.update(1)
# If repo was not removed, then it is a good repo # If repo was not removed, then it is a good repo
updates["good_repo_for_crab"] = True updates["good_repo_for_crab"] = True
finally: finally:
container.kill() container.kill()
container.remove() container.remove()
return updates
def clone_repos(file: str, dest: str, force: bool =False, verbose: bool = False) -> None: def clone_repos(file: str, dest: str, force: bool =False, verbose: bool = False) -> None:
""" """