Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cfc026987d | ||
|
|
2c5b9ab442 |
+12
-4
@@ -3,6 +3,8 @@ import binascii
|
|||||||
import glob
|
import glob
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
from ..exceptions import ShlaxException
|
||||||
|
|
||||||
|
|
||||||
class Copy:
|
class Copy:
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
@@ -15,12 +17,16 @@ class Copy:
|
|||||||
else:
|
else:
|
||||||
self.src.append(src)
|
self.src.append(src)
|
||||||
|
|
||||||
def listfiles(self):
|
async def listfiles(self, target):
|
||||||
if getattr(self, '_listfiles', None):
|
if getattr(self, '_listfiles', None):
|
||||||
return self._listfiles
|
return self._listfiles
|
||||||
|
|
||||||
result = []
|
result = []
|
||||||
for src in self.src:
|
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):
|
if os.path.isfile(src):
|
||||||
result.append(src)
|
result.append(src)
|
||||||
continue
|
continue
|
||||||
@@ -39,7 +45,7 @@ class Copy:
|
|||||||
async def __call__(self, target):
|
async def __call__(self, target):
|
||||||
await target.mkdir(self.dst)
|
await target.mkdir(self.dst)
|
||||||
|
|
||||||
for path in self.listfiles():
|
for path in await self.listfiles(target):
|
||||||
if os.path.isdir(path):
|
if os.path.isdir(path):
|
||||||
await target.mkdir(os.path.join(self.dst, path))
|
await target.mkdir(os.path.join(self.dst, path))
|
||||||
elif '/' in path:
|
elif '/' in path:
|
||||||
@@ -55,9 +61,11 @@ class Copy:
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f'Copy({", ".join(self.src)}, {self.dst})'
|
return f'Copy({", ".join(self.src)}, {self.dst})'
|
||||||
|
|
||||||
async def cachekey(self):
|
async def cachekey(self, target):
|
||||||
async def chksum(path):
|
async def chksum(path):
|
||||||
with open(path, 'rb') as f:
|
with open(path, 'rb') as f:
|
||||||
return (path, str(binascii.crc32(f.read())))
|
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}
|
return {path: chks for path, chks in results}
|
||||||
|
|||||||
@@ -27,28 +27,33 @@ class Packages:
|
|||||||
update='apk update',
|
update='apk update',
|
||||||
upgrade='apk upgrade',
|
upgrade='apk upgrade',
|
||||||
install='apk add',
|
install='apk add',
|
||||||
|
host=None,
|
||||||
),
|
),
|
||||||
apt=dict(
|
apt=dict(
|
||||||
update='apt-get -y update',
|
update='apt-get -y update',
|
||||||
upgrade='apt-get -y upgrade',
|
upgrade='apt-get -y upgrade',
|
||||||
install='apt-get -y --no-install-recommends install',
|
install='apt-get -y --no-install-recommends install',
|
||||||
|
host=None,
|
||||||
),
|
),
|
||||||
pacman=dict(
|
pacman=dict(
|
||||||
update='pacman -Sy',
|
update='pacman -Sy',
|
||||||
upgrade='pacman -Su --noconfirm',
|
upgrade='pacman -Su --noconfirm',
|
||||||
install='pacman -S --noconfirm',
|
install='pacman -S --noconfirm',
|
||||||
lastupdate='stat -c %Y /var/lib/pacman/sync/core.db',
|
lastupdate='stat -c %Y /var/lib/pacman/sync/core.db',
|
||||||
|
host='/var/lib/pacman',
|
||||||
),
|
),
|
||||||
dnf=dict(
|
dnf=dict(
|
||||||
update='dnf makecache --assumeyes',
|
update='dnf makecache --assumeyes',
|
||||||
upgrade='dnf upgrade --best --assumeyes --skip-broken', # noqa
|
upgrade='dnf upgrade --best --assumeyes --skip-broken', # noqa
|
||||||
install='dnf install --setopt=install_weak_deps=False --best --assumeyes', # noqa
|
install='dnf install --setopt=install_weak_deps=False --best --assumeyes', # noqa
|
||||||
lastupdate='stat -c %Y /var/cache/dnf/* | head -n1',
|
lastupdate='stat -c %Y /var/cache/dnf/* | head -n1',
|
||||||
|
host=None,
|
||||||
),
|
),
|
||||||
yum=dict(
|
yum=dict(
|
||||||
update='yum update',
|
update='yum update',
|
||||||
upgrade='yum upgrade',
|
upgrade='yum upgrade',
|
||||||
install='yum install',
|
install='yum install',
|
||||||
|
host=None,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -62,6 +67,12 @@ class Packages:
|
|||||||
self.packages += line.split(' ')
|
self.packages += line.split(' ')
|
||||||
|
|
||||||
async def cache_setup(self, target):
|
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:
|
if 'CACHE_DIR' in os.environ:
|
||||||
self.cache_root = os.path.join(os.getenv('CACHE_DIR'))
|
self.cache_root = os.path.join(os.getenv('CACHE_DIR'))
|
||||||
else:
|
else:
|
||||||
|
|||||||
+4
-3
@@ -13,7 +13,7 @@ import importlib
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from .proc import ProcFailure
|
from .exceptions import ShlaxException
|
||||||
|
|
||||||
|
|
||||||
class Group(cli2.Group):
|
class Group(cli2.Group):
|
||||||
@@ -57,10 +57,11 @@ class Command(cli2.Command):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
result = super().__call__(*argv)
|
result = super().__call__(*argv)
|
||||||
except ProcFailure:
|
except ShlaxException as exc:
|
||||||
# just output the failure without TB, as command was already
|
# just output the failure without TB, as command was already
|
||||||
# printed anyway
|
# printed anyway
|
||||||
pass
|
self.exit_code = 1
|
||||||
|
self['target'].value.output.fail(exc)
|
||||||
|
|
||||||
if self['target'].value.results:
|
if self['target'].value.results:
|
||||||
if self['target'].value.results[-1].status == 'failure':
|
if self['target'].value.results[-1].status == 'failure':
|
||||||
|
|||||||
+2
-1
@@ -7,10 +7,11 @@ import os
|
|||||||
import shlex
|
import shlex
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from .exceptions import ShlaxException
|
||||||
from .output import Output
|
from .output import Output
|
||||||
|
|
||||||
|
|
||||||
class ProcFailure(Exception):
|
class ProcFailure(ShlaxException):
|
||||||
def __init__(self, proc):
|
def __init__(self, proc):
|
||||||
self.proc = proc
|
self.proc = proc
|
||||||
|
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ class Buildah(Target):
|
|||||||
prefix = tag
|
prefix = tag
|
||||||
break
|
break
|
||||||
if hasattr(action, 'cachekey'):
|
if hasattr(action, 'cachekey'):
|
||||||
action_key = action.cachekey()
|
action_key = action.cachekey(self)
|
||||||
if asyncio.iscoroutine(action_key):
|
if asyncio.iscoroutine(action_key):
|
||||||
action_key = str(await action_key)
|
action_key = str(await action_key)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user