Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cfc026987d | ||
|
|
2c5b9ab442 |
+12
-4
@@ -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}
|
||||
|
||||
@@ -27,28 +27,33 @@ class Packages:
|
||||
update='apk update',
|
||||
upgrade='apk upgrade',
|
||||
install='apk add',
|
||||
host=None,
|
||||
),
|
||||
apt=dict(
|
||||
update='apt-get -y update',
|
||||
upgrade='apt-get -y upgrade',
|
||||
install='apt-get -y --no-install-recommends install',
|
||||
host=None,
|
||||
),
|
||||
pacman=dict(
|
||||
update='pacman -Sy',
|
||||
upgrade='pacman -Su --noconfirm',
|
||||
install='pacman -S --noconfirm',
|
||||
lastupdate='stat -c %Y /var/lib/pacman/sync/core.db',
|
||||
host='/var/lib/pacman',
|
||||
),
|
||||
dnf=dict(
|
||||
update='dnf makecache --assumeyes',
|
||||
upgrade='dnf upgrade --best --assumeyes --skip-broken', # noqa
|
||||
install='dnf install --setopt=install_weak_deps=False --best --assumeyes', # noqa
|
||||
lastupdate='stat -c %Y /var/cache/dnf/* | head -n1',
|
||||
host=None,
|
||||
),
|
||||
yum=dict(
|
||||
update='yum update',
|
||||
upgrade='yum upgrade',
|
||||
install='yum install',
|
||||
host=None,
|
||||
),
|
||||
)
|
||||
|
||||
@@ -62,6 +67,12 @@ class Packages:
|
||||
self.packages += line.split(' ')
|
||||
|
||||
async def cache_setup(self, target):
|
||||
# Try to use the host cache directory if present rather than home
|
||||
# directory, in cases where host and guest are the same distros
|
||||
hostpath = self.mgrs[self.mgr]['host']
|
||||
if target.exists(hostpath):
|
||||
self.cache_root = hostpath
|
||||
|
||||
if 'CACHE_DIR' in os.environ:
|
||||
self.cache_root = os.path.join(os.getenv('CACHE_DIR'))
|
||||
else:
|
||||
|
||||
+4
-3
@@ -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':
|
||||
|
||||
+2
-1
@@ -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
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user