diff --git a/github_scripts/suite_data.py b/github_scripts/suite_data.py index 98c33109..a5dbc367 100644 --- a/github_scripts/suite_data.py +++ b/github_scripts/suite_data.py @@ -10,7 +10,6 @@ import re import os -import shutil import sqlite3 import subprocess import yaml @@ -18,7 +17,6 @@ from pathlib import Path from typing import Dict, List, Optional, Set, Union from git_bdiff import GitBDiff, GitInfo -from get_git_sources import clone_repo, sync_repo class SuiteData: @@ -36,12 +34,12 @@ class SuiteData: "-v-", ) - def __init__(self, suite_path=None) -> None: + def __init__(self, suite_path: Path = None) -> None: self.dependencies = {} self.rose_data = {} self.suite_path = suite_path + self.source_root = suite_path / "share" / "source" self.task_states = {} - self.temp_directory = None def get_um_failed_configs(self) -> Set[str]: """ @@ -65,7 +63,7 @@ def read_um_section(self, change: str) -> str: """ Read through a UM file searching for line """ - change = self.temp_directory / "um" / change + change = self.source_root / "um" / change lines = change.read_text() lines = lines.lower() try: @@ -118,7 +116,7 @@ def get_um_owners(self, filename: str) -> Dict: Read UM Code Owners file and write to a dictionary """ - fpath = self.temp_directory / "um" / filename + fpath = self.source_root / "um" / filename owners_text = fpath.read_text() in_owners = False @@ -179,7 +177,7 @@ def populate_gitbdiff(self) -> None: if not data["gitinfo"].is_main(): parent = "main" self.dependencies[dependency]["gitbdiff"] = GitBDiff( - repo=self.temp_directory / dependency, parent=parent + repo=self.source_root / dependency, parent=parent ).files() else: self.dependencies[dependency]["gitbdiff"] = [] @@ -191,23 +189,9 @@ def populate_gitinfo(self) -> None: for dependency in self.dependencies: self.dependencies[dependency]["gitinfo"] = GitInfo( - self.temp_directory / dependency + self.source_root / dependency ) - def clone_sources(self) -> None: - """ - Clone the sources defined in the dependencies file, to allow reading of files - and creation of diffs. - If the source is not a github url, then copy it using rsync - """ - - for dependency, data in self.dependencies.items(): - loc = self.temp_directory / dependency - if data["source"].endswith(".git"): - clone_repo(data["source"], data["ref"], loc) - else: - sync_repo(data["source"], data["ref"], loc) - def determine_primary_source(self) -> str: """ Work out what repo launched the suite based on the what sources are available in @@ -418,9 +402,3 @@ def run_command( ) if rval: return result - - def cleanup(self) -> None: - """ - Remove self.temp_directory - """ - shutil.rmtree(self.temp_directory) diff --git a/github_scripts/suite_report_git.py b/github_scripts/suite_report_git.py index 340110c4..62dc2b8e 100755 --- a/github_scripts/suite_report_git.py +++ b/github_scripts/suite_report_git.py @@ -16,7 +16,6 @@ from collections import defaultdict from contextlib import contextmanager from pathlib import Path -from tempfile import mkdtemp from typing import Dict, List, Set, Tuple from suite_data import SuiteData @@ -79,8 +78,6 @@ def __init__(self, suite_path: Path) -> None: self.rose_data: Dict[str, str] = self.read_rose_conf() self.dependencies: Dict[str, Dict] = self.read_dependencies() self.primary_source: str = self.determine_primary_source() - self.temp_directory = Path(mkdtemp()) - self.clone_sources() self.populate_gitinfo() self.populate_gitbdiff() self.trac_log = [] @@ -90,7 +87,7 @@ def parse_local_source(self, source: str) -> Tuple[str, str]: Find the branch name or hash and remote reference for a given source """ - source = self.temp_directory / source + source = self.source_root / source branch_name = self.run_command( f"git -C {source} branch --show-current", rval=True @@ -361,8 +358,11 @@ def parse_args() -> argparse.Namespace: args, _ = parser.parse_known_args() - # Check log file is writable, set as None if not (this will output to stdout) - if args.log_path and not os.access(args.log_path, os.W_OK): + # Default log_path as suite_path if not set, then check log file is writable + # set as None if not (this will output to stdout) + if not args.log_path: + args.log_path = args.suite_path + if not os.access(args.log_path, os.W_OK): args.log_path = None return args @@ -376,11 +376,8 @@ def main() -> None: args = parse_args() suite_report = SuiteReport(args.suite_path) - try: - suite_report.create_log() - suite_report.write_log(args.log_path) - finally: - suite_report.cleanup() + suite_report.create_log() + suite_report.write_log(args.log_path) if __name__ == "__main__":