Check if artifact exists before trying to install it

epel8
Maxwell G 2 years ago
parent b1de39d9c6
commit 5e5c534c32
No known key found for this signature in database
GPG Key ID: F79E4E25E8C661F8

@ -51,6 +51,14 @@ class AnsibleCollection:
return load(file, Loader=CSafeLoader)
def install(self, destdir: Union[str, Path]) -> None:
artifact = self.collection_srcdir / Path(
f"{self.namespace}-{self.name}-{self.version}.tar.gz"
)
if not artifact.exists() and not artifact.is_file():
raise CollectionError(
f"{artifact} does not exist! Did you run %ansible_collection_build?"
)
args = (
"ansible-galaxy",
"collection",
@ -58,11 +66,12 @@ class AnsibleCollection:
"-n",
"-p",
str(destdir),
f"{self.namespace}-{self.name}-{self.version}.tar.gz",
str(artifact),
)
print(f"Running: {args}")
print()
subprocess.run(args, check=True, cwd=self.collection_srcdir)
print()
def write_filelist(self, filelist: Path) -> None:
filelist.parent.mkdir(parents=True, exist_ok=True)
@ -134,5 +143,5 @@ def main():
if __name__ == "__main__":
try:
main()
except CollectionError as err:
except (CollectionError, subprocess.CalledProcessError) as err:
sys.exit(err)

Loading…
Cancel
Save