diff --git a/shlax/actions/copy.py b/shlax/actions/copy.py index 848917d..02d549e 100644 --- a/shlax/actions/copy.py +++ b/shlax/actions/copy.py @@ -3,6 +3,8 @@ import binascii import glob import os +from ..exceptions import ShlaxException + class Copy: def __init__(self, *args): @@ -15,12 +17,16 @@ class Copy: else: self.src.append(src) - def listfiles(self): + async def listfiles(self, target): if getattr(self, '_listfiles', None): return self._listfiles result = [] for src in self.src: + if not await target.parent.exists(src): + target.output.fail(self) + raise ShlaxException(f'File not found {src}') + if os.path.isfile(src): result.append(src) continue @@ -39,7 +45,7 @@ class Copy: async def __call__(self, target): await target.mkdir(self.dst) - for path in self.listfiles(): + for path in await self.listfiles(target): if os.path.isdir(path): await target.mkdir(os.path.join(self.dst, path)) elif '/' in path: @@ -55,9 +61,11 @@ class Copy: def __str__(self): return f'Copy({", ".join(self.src)}, {self.dst})' - async def cachekey(self): + async def cachekey(self, target): async def chksum(path): with open(path, 'rb') as f: return (path, str(binascii.crc32(f.read()))) - results = await asyncio.gather(*[chksum(f) for f in self.listfiles()]) + results = await asyncio.gather( + *[chksum(f) for f in await self.listfiles(target)] + ) return {path: chks for path, chks in results} diff --git a/shlax/cli.py b/shlax/cli.py index 194d576..5659b1a 100644 --- a/shlax/cli.py +++ b/shlax/cli.py @@ -13,7 +13,7 @@ import importlib import os import sys -from .proc import ProcFailure +from .exceptions import ShlaxException class Group(cli2.Group): @@ -57,10 +57,11 @@ class Command(cli2.Command): try: result = super().__call__(*argv) - except ProcFailure: + except ShlaxException as exc: # just output the failure without TB, as command was already # printed anyway - pass + self.exit_code = 1 + self['target'].value.output.fail(exc) if self['target'].value.results: if self['target'].value.results[-1].status == 'failure': diff --git a/shlax/proc.py b/shlax/proc.py index 41b58f2..e44f631 100644 --- a/shlax/proc.py +++ b/shlax/proc.py @@ -7,10 +7,11 @@ import os import shlex import sys +from .exceptions import ShlaxException from .output import Output -class ProcFailure(Exception): +class ProcFailure(ShlaxException): def __init__(self, proc): self.proc = proc diff --git a/shlax/targets/buildah.py b/shlax/targets/buildah.py index 7de8bd5..4ee3153 100644 --- a/shlax/targets/buildah.py +++ b/shlax/targets/buildah.py @@ -88,7 +88,7 @@ class Buildah(Target): prefix = tag break if hasattr(action, 'cachekey'): - action_key = action.cachekey() + action_key = action.cachekey(self) if asyncio.iscoroutine(action_key): action_key = str(await action_key) else: