Merge branch 'improve-unsquash-errors'

main
Adriaan de Groot 6 years ago
commit 3e4f429f35

@ -2,6 +2,10 @@
#
# Fetch the Transifex translations for Calamares and incorporate them
# into the source tree, adding commits of the different files.
#
# Run this (occasionally) at the top-level directory to get
# new translations. See also CMakeLists.txt and ci/txstats.py
# for update instructions.
### INITIAL SETUP
#

@ -1,7 +1,13 @@
#!/bin/sh
#
# Fetch the Transifex translations for Calamares and incorporate them
# into the source tree, adding commits of the different files.
# Extract translations from Calamares source and send them
# to Transifex.
#
# Run this at the top-level.
#
# Use the --no-tx option to do the extraction, but not the
# pushing-to-Transifex part. This can be useful to check for
# new strings or when testing the tools themselves.
### INITIAL SETUP
#

@ -0,0 +1,55 @@
#! /bin/sh
### Command-line validation
#
#
SRCDIR=$( dirname "$0" )
test -d "$SRCDIR" || { echo "! Can't find source directory." ; exit 1 ; }
MODULE="$1"
test -n "$MODULE" || { echo "! Usage: $0 <module>" ; exit 1 ; }
### Run-time validation
#
# .. switch SRCDIR to the module that has been found
BINDIR="$SRCDIR" # Keep original SRCDIR
SRCDIR="$SRCDIR/$MODULE"
XSRCDIR="src/modules/$MODULE" # In builddir
TESTDIR="$SRCDIR/tests"
test -x "$BINDIR/testmodule.py" || { echo "! No support script $BINDIR/testmodule.py" ; exit 1 ; }
test -d "$SRCDIR" || { echo "! Source $SRCDIR is not a directory." ; exit 1 ; }
test -f "$TESTDIR/1.global" || { echo "! Source $SRCDIR has no tests." ; exit 1 ; }
test -f "libcalamares.so" || { echo "! Run the tests from the build-directory." ; exit 1 ; }
test -d "$XSRCDIR" || { echo "! No module directory $XSRCDIR in build-dir." ; exit 1 ; }
### Python setup
#
#
export PYTHONPATH=".:$PYTHONPATH"
PYTHON=$( which python3 2> /dev/null )
if test -z "$PYTHON" ; then
PYTHON=$( which python 2> /dev/null )
fi
test -x "$PYTHON" || { echo "! No suitable Python executable found." ; exit 1 ; }
### Test-execution
#
#
C=0
while true ; do
# Might use shell arithmetic, but need other shebang then
C=$( expr "$C" + 1 )
G_CFG="$TESTDIR/$C.global"
J_CFG="$TESTDIR/$C.job"
test -f "$G_CFG" || break
if test -f "$J_CFG" ; then
$PYTHON "$BINDIR/testmodule.py" "$XSRCDIR" "$G_CFG" "$J_CFG"
else
$PYTHON "$BINDIR/testmodule.py" "$XSRCDIR" "$G_CFG"
fi
done

@ -30,6 +30,15 @@ import tempfile
from libcalamares import *
import gettext
_ = gettext.translation("calamares-python",
localedir=utils.gettext_path(),
languages=utils.gettext_languages(),
fallback=True).gettext
def pretty_name():
return _("Installing filesystems.")
class UnpackEntry:
"""
@ -61,6 +70,8 @@ def list_excludes(destination):
"""
lst = []
extra_mounts = globalstorage.value("extraMounts")
if extra_mounts is None:
extra_mounts = []
for extra_mount in extra_mounts:
mount_point = extra_mount["mountPoint"]
@ -138,7 +149,8 @@ def file_copy(source, dest, progress_cb):
# https://bugzilla.redhat.com/show_bug.cgi?id=868755#c50
# for the same issue in Anaconda, which uses a similar workaround.
if process.returncode != 0 and process.returncode != 23:
return "rsync failed with error code {}.".format(process.returncode)
utils.warn("rsync failed with error code {}.".format(process.returncode))
return _("rsync failed with error code {}.").format(process.returncode)
return None
@ -192,11 +204,10 @@ class UnpackOperation:
if entry.sourcefs == "squashfs":
if shutil.which("unsquashfs") is None:
msg = ("Failed to find unsquashfs, make sure you have "
"the squashfs-tools package installed")
print(msg)
return ("Failed to unpack image",
msg)
utils.warning("Failed to find unsquashfs")
return (_("Failed to unpack image \"{}\"").format(entry.source),
_("Failed to find unsquashfs, make sure you have the squashfs-tools package installed"))
fslist = subprocess.check_output(
["unsquashfs", "-l", entry.source]
@ -213,7 +224,7 @@ class UnpackOperation:
error_msg = self.unpack_image(entry, imgmountdir)
if error_msg:
return ("Failed to unpack image {}".format(entry.source),
return (_("Failed to unpack image \"{}\"").format(entry.source),
error_msg)
return None
@ -261,55 +272,66 @@ class UnpackOperation:
subprocess.check_call(["umount", "-l", imgmountdir])
def run():
def get_supported_filesystems():
"""
Unsquash filesystem.
Reads /proc/filesystems (the list of supported filesystems
for the current kernel) and returns a list of (names of)
those filesystems.
"""
PATH_PROCFS = '/proc/filesystems'
if os.path.isfile(PATH_PROCFS) and os.access(PATH_PROCFS, os.R_OK):
with open(PATH_PROCFS, 'r') as procfile:
filesystems = procfile.read()
filesystems = filesystems.replace(
"nodev", "").replace("\t", "").splitlines()
return filesystems
return []
def run():
"""
Unsquash filesystem.
"""
root_mount_point = globalstorage.value("rootMountPoint")
if not root_mount_point:
return ("No mount point for root partition in globalstorage",
"globalstorage does not contain a \"rootMountPoint\" key, "
"doing nothing")
utils.warning("No mount point for root partition")
return (_("No mount point for root partition"),
_("globalstorage does not contain a \"rootMountPoint\" key, "
"doing nothing"))
if not os.path.exists(root_mount_point):
return ("Bad mount point for root partition in globalstorage",
"globalstorage[\"rootMountPoint\"] is \"{}\", which does not "
"exist, doing nothing".format(root_mount_point))
utils.warning("Bad root mount point \"{}\"".format(root_mount_point))
return (_("Bad mount point for root partition"),
_("rootMountPoint is \"{}\", which does not "
"exist, doing nothing").format(root_mount_point))
supported_filesystems = get_supported_filesystems()
unpack = list()
for entry in job.configuration["unpack"]:
source = os.path.abspath(entry["source"])
sourcefs = entry["sourcefs"]
# Get supported filesystems
fs_is_supported = False
if os.path.isfile(PATH_PROCFS) and os.access(PATH_PROCFS, os.R_OK):
with open(PATH_PROCFS, 'r') as procfile:
filesystems = procfile.read()
filesystems = filesystems.replace(
"nodev", "").replace("\t", "").splitlines()
# Check if the source filesystem is supported
for fs in filesystems:
if fs == sourcefs:
fs_is_supported = True
if not fs_is_supported:
return "Bad filesystem", "sourcefs=\"{}\"".format(sourcefs)
if sourcefs not in supported_filesystems:
utils.warning("The filesystem for \"{}\" ({}) is not supported".format(source, sourcefs))
return (_("Bad unsquash configuration"),
_("The filesystem for \"{}\" ({}) is not supported").format(source, sourcefs))
destination = os.path.abspath(root_mount_point + entry["destination"])
if not os.path.exists(source):
return "Bad source", "source=\"{}\"".format(source)
utils.warning("The source filesystem \"{}\" does not exist".format(source))
return (_("Bad unsquash configuration"),
_("The source filesystem \"{}\" does not exist").format(source))
if not os.path.isdir(destination):
return "Bad destination", "destination=\"{}\"".format(destination)
utils.warning(("The destination \"{}\" in the target system is not a directory").format(destination))
return (_("Bad unsquash configuration"),
_("The destination \"{}\" in the target system is not a directory").format(destination))
unpack.append(UnpackEntry(source, sourcefs, destination))

@ -0,0 +1,17 @@
#! /bin/sh
SRCDIR=$( dirname "$0" )
# For test 3
mkdir /tmp/unpackfs-test-run-rootdir3
# For test 7
mkdir /tmp/unpackfs-test-run-rootdir3/realdest
# Run tests
sh "$SRCDIR/../testpythonrun.sh" unpackfs
# Cleanup test 7
rm -rf /tmp/unpackfs-test-run-rootdir3/realdest
# Cleanup test 3
rmdir /tmp/unpackfs-test-run-rootdir3

@ -0,0 +1,2 @@
---
rootMountPoint: /tmp/unpackfs-test-run-rootdir/

@ -0,0 +1,2 @@
---
rootMountPoint: /tmp/unpackfs-test-run-rootdir3/

@ -0,0 +1,2 @@
---
rootMountPoint: /tmp/unpackfs-test-run-rootdir3/

@ -0,0 +1,4 @@
---
unpack:
- source: .
sourcefs: bogus

@ -0,0 +1,2 @@
---
rootMountPoint: /tmp/unpackfs-test-run-rootdir3/

@ -0,0 +1,5 @@
---
unpack:
- source: ./fakesource
sourcefs: ext4
destination: fakedest

@ -0,0 +1,2 @@
---
rootMountPoint: /tmp/unpackfs-test-run-rootdir3/

@ -0,0 +1,5 @@
---
unpack:
- source: .
sourcefs: ext4
destination: fakedest

@ -0,0 +1,2 @@
---
rootMountPoint: /tmp/unpackfs-test-run-rootdir3/

@ -0,0 +1,5 @@
---
unpack:
- source: .
sourcefs: ext4
destination: realdest
Loading…
Cancel
Save