diff --git a/ci/txpull.sh b/ci/txpull.sh index 4206739dd..610c531d9 100755 --- a/ci/txpull.sh +++ b/ci/txpull.sh @@ -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 # diff --git a/ci/txpush.sh b/ci/txpush.sh index cf1c3b883..84166fac6 100755 --- a/ci/txpush.sh +++ b/ci/txpush.sh @@ -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 # diff --git a/src/modules/testpythonrun.sh b/src/modules/testpythonrun.sh new file mode 100644 index 000000000..be2b7800b --- /dev/null +++ b/src/modules/testpythonrun.sh @@ -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 " ; 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 + diff --git a/src/modules/unpackfs/main.py b/src/modules/unpackfs/main.py index 851335513..436ec6a5c 100644 --- a/src/modules/unpackfs/main.py +++ b/src/modules/unpackfs/main.py @@ -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 get_supported_filesystems(): + """ + 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. """ - PATH_PROCFS = '/proc/filesystems' - 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)) diff --git a/src/modules/unpackfs/runtests.sh b/src/modules/unpackfs/runtests.sh new file mode 100644 index 000000000..2b9b704c0 --- /dev/null +++ b/src/modules/unpackfs/runtests.sh @@ -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 diff --git a/src/modules/unpackfs/tests/1.global b/src/modules/unpackfs/tests/1.global new file mode 100644 index 000000000..02ae840cb --- /dev/null +++ b/src/modules/unpackfs/tests/1.global @@ -0,0 +1,2 @@ +--- +bogus: true diff --git a/src/modules/unpackfs/tests/2.global b/src/modules/unpackfs/tests/2.global new file mode 100644 index 000000000..f496ade61 --- /dev/null +++ b/src/modules/unpackfs/tests/2.global @@ -0,0 +1,2 @@ +--- +rootMountPoint: /tmp/unpackfs-test-run-rootdir/ diff --git a/src/modules/unpackfs/tests/3.global b/src/modules/unpackfs/tests/3.global new file mode 100644 index 000000000..2e6b37ab5 --- /dev/null +++ b/src/modules/unpackfs/tests/3.global @@ -0,0 +1,2 @@ +--- +rootMountPoint: /tmp/unpackfs-test-run-rootdir3/ diff --git a/src/modules/unpackfs/tests/3.job b/src/modules/unpackfs/tests/3.job new file mode 100644 index 000000000..429f65b3c --- /dev/null +++ b/src/modules/unpackfs/tests/3.job @@ -0,0 +1,2 @@ +--- +unpack: [] diff --git a/src/modules/unpackfs/tests/4.global b/src/modules/unpackfs/tests/4.global new file mode 100644 index 000000000..2e6b37ab5 --- /dev/null +++ b/src/modules/unpackfs/tests/4.global @@ -0,0 +1,2 @@ +--- +rootMountPoint: /tmp/unpackfs-test-run-rootdir3/ diff --git a/src/modules/unpackfs/tests/4.job b/src/modules/unpackfs/tests/4.job new file mode 100644 index 000000000..ab76dcbeb --- /dev/null +++ b/src/modules/unpackfs/tests/4.job @@ -0,0 +1,4 @@ +--- +unpack: + - source: . + sourcefs: bogus diff --git a/src/modules/unpackfs/tests/5.global b/src/modules/unpackfs/tests/5.global new file mode 100644 index 000000000..2e6b37ab5 --- /dev/null +++ b/src/modules/unpackfs/tests/5.global @@ -0,0 +1,2 @@ +--- +rootMountPoint: /tmp/unpackfs-test-run-rootdir3/ diff --git a/src/modules/unpackfs/tests/5.job b/src/modules/unpackfs/tests/5.job new file mode 100644 index 000000000..2f8d732d0 --- /dev/null +++ b/src/modules/unpackfs/tests/5.job @@ -0,0 +1,5 @@ +--- +unpack: + - source: ./fakesource + sourcefs: ext4 + destination: fakedest diff --git a/src/modules/unpackfs/tests/6.global b/src/modules/unpackfs/tests/6.global new file mode 100644 index 000000000..2e6b37ab5 --- /dev/null +++ b/src/modules/unpackfs/tests/6.global @@ -0,0 +1,2 @@ +--- +rootMountPoint: /tmp/unpackfs-test-run-rootdir3/ diff --git a/src/modules/unpackfs/tests/6.job b/src/modules/unpackfs/tests/6.job new file mode 100644 index 000000000..c1110a106 --- /dev/null +++ b/src/modules/unpackfs/tests/6.job @@ -0,0 +1,5 @@ +--- +unpack: + - source: . + sourcefs: ext4 + destination: fakedest diff --git a/src/modules/unpackfs/tests/7.global b/src/modules/unpackfs/tests/7.global new file mode 100644 index 000000000..2e6b37ab5 --- /dev/null +++ b/src/modules/unpackfs/tests/7.global @@ -0,0 +1,2 @@ +--- +rootMountPoint: /tmp/unpackfs-test-run-rootdir3/ diff --git a/src/modules/unpackfs/tests/7.job b/src/modules/unpackfs/tests/7.job new file mode 100644 index 000000000..a31068e5d --- /dev/null +++ b/src/modules/unpackfs/tests/7.job @@ -0,0 +1,5 @@ +--- +unpack: + - source: . + sourcefs: ext4 + destination: realdest