From 10eaf06f6012d054d52bfd69e79fd53c3c46bc00 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 4 Jul 2017 11:56:21 -0400 Subject: [PATCH 1/8] Python: Be more descriptive when modules can't be loaded. --- src/libcalamaresui/modulesystem/Module.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/libcalamaresui/modulesystem/Module.cpp b/src/libcalamaresui/modulesystem/Module.cpp index 6f19d36a4..09386d58c 100644 --- a/src/libcalamaresui/modulesystem/Module.cpp +++ b/src/libcalamaresui/modulesystem/Module.cpp @@ -82,12 +82,14 @@ Module::fromDescriptor( const QVariantMap& moduleDescriptor, { m = new ViewModule(); } -#ifdef WITH_PYTHONQT else if ( intfString == "pythonqt" ) { +#ifdef WITH_PYTHONQT m = new PythonQtViewModule(); - } +#else + cLog() << "PythonQt modules are not supported in this version of Calamares."; #endif + } } else if ( typeString == "job" ) { @@ -99,17 +101,20 @@ Module::fromDescriptor( const QVariantMap& moduleDescriptor, { m = new ProcessJobModule(); } -#ifdef WITH_PYTHON else if ( intfString == "python" ) { +#ifdef WITH_PYTHON m = new PythonJobModule(); - } +#else + cLog() << "Python modules are not supported in this version of Calamares."; #endif + } } if ( !m ) { - cLog() << Q_FUNC_INFO << "bad module type or interface string" - << instanceId << typeString << intfString; + cLog() << "Bad module type (" << typeString + << ") or interface string (" << intfString + << ") for module " << instanceId; return nullptr; } From e43f41a40245acbce83df9ce18a00db214a79453 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 5 Jul 2017 06:26:21 -0400 Subject: [PATCH 2/8] Python: separate description of dummy module from docs of run() --- src/modules/dummypython/main.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/modules/dummypython/main.py b/src/modules/dummypython/main.py index 4a68cf963..29837ba96 100644 --- a/src/modules/dummypython/main.py +++ b/src/modules/dummypython/main.py @@ -19,22 +19,22 @@ # You should have received a copy of the GNU General Public License # along with Calamares. If not, see . +""" +=== Example Python jobmodule. + +A Python jobmodule is a Python program which imports libcalamares and +has a function run() as entry point. run() must return None if everything +went well, or a tuple (str,str) with an error message and description +if something went wrong. +""" + import libcalamares import os from time import gmtime, strftime, sleep def run(): - """ - Example Python jobmodule. - - A Python jobmodule is a Python program which imports libcalamares and - has a function run() as entry point. run() must return None if everything - went well, or a tuple (str,str) with an error message and description - if something went wrong. - - :return: - """ + """Dummy python job.""" os.system("/bin/sh -c \"touch ~/calamares-dummypython\"") accumulator = strftime("%Y-%m-%d %H:%M:%S", gmtime()) + "\n" accumulator += "Calamares version: " + libcalamares.VERSION_SHORT + "\n" From f12ae5db3be4f850e4d3df8b6cdf5584dc691049 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 5 Jul 2017 06:28:32 -0400 Subject: [PATCH 3/8] Python: get docstring from run() method --- src/libcalamares/PythonJob.cpp | 5 +++++ src/libcalamares/PythonJob.h | 1 + 2 files changed, 6 insertions(+) diff --git a/src/libcalamares/PythonJob.cpp b/src/libcalamares/PythonJob.cpp index 32e019eb0..a7922145a 100644 --- a/src/libcalamares/PythonJob.cpp +++ b/src/libcalamares/PythonJob.cpp @@ -228,6 +228,7 @@ PythonJob::PythonJob( const QString& scriptFile, : Job( parent ) , m_scriptFile( scriptFile ) , m_workingPath( workingPath ) + , m_description() , m_configurationMap( moduleConfiguration ) { } @@ -293,6 +294,10 @@ PythonJob::exec() scriptNamespace ); bp::object entryPoint = scriptNamespace[ "run" ]; + bp::extract< std::string > entryPoint_doc_attr(entryPoint.attr( "__doc__" ) ); + + if ( entryPoint_doc_attr.check() ) + m_description = QString::fromStdString( entryPoint_doc_attr() ); bp::object runResult = entryPoint(); diff --git a/src/libcalamares/PythonJob.h b/src/libcalamares/PythonJob.h index 9bc9ddb0b..d13705ed8 100644 --- a/src/libcalamares/PythonJob.h +++ b/src/libcalamares/PythonJob.h @@ -53,6 +53,7 @@ private: CalamaresPython::Helper* helper(); QString m_scriptFile; QString m_workingPath; + QString m_description; QVariantMap m_configurationMap; }; From a72cc0eeb492a778d350f1f33991db81c9f6e026 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 5 Jul 2017 06:44:09 -0400 Subject: [PATCH 4/8] Python: use the module run().__doc__ as a pretty description. --- src/libcalamares/PythonJob.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libcalamares/PythonJob.cpp b/src/libcalamares/PythonJob.cpp index a7922145a..6de89d184 100644 --- a/src/libcalamares/PythonJob.cpp +++ b/src/libcalamares/PythonJob.cpp @@ -248,8 +248,11 @@ PythonJob::prettyName() const QString PythonJob::prettyStatusMessage() const { - return tr( "Running %1 operation." ) - .arg( QDir( m_workingPath ).dirName() ); + if ( m_description.isEmpty() ) + return tr( "Running %1 operation." ) + .arg( QDir( m_workingPath ).dirName() ); + else + return m_description; } From 11e5a6cbe062244dd9c0cc0969a3a121d2d5350f Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 5 Jul 2017 06:55:35 -0400 Subject: [PATCH 5/8] Python: trim description to the first line of run.__doc__ --- src/libcalamares/PythonJob.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/libcalamares/PythonJob.cpp b/src/libcalamares/PythonJob.cpp index 6de89d184..e02f9e210 100644 --- a/src/libcalamares/PythonJob.cpp +++ b/src/libcalamares/PythonJob.cpp @@ -300,7 +300,13 @@ PythonJob::exec() bp::extract< std::string > entryPoint_doc_attr(entryPoint.attr( "__doc__" ) ); if ( entryPoint_doc_attr.check() ) - m_description = QString::fromStdString( entryPoint_doc_attr() ); + { + m_description = QString::fromStdString( entryPoint_doc_attr() ).trimmed(); + auto i_newline = m_description.indexOf('\n'); + if ( i_newline > 0 ) + m_description.truncate( i_newline ); + cDebug() << "Job" << prettyName() << "->" << m_description; + } bp::object runResult = entryPoint(); From fcde28ca9d1eda05623002861fa3d4cdec4f9c9d Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 10 Jul 2017 11:29:22 -0400 Subject: [PATCH 6/8] Python: tidy description of hwclock module --- src/modules/hwclock/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/hwclock/main.py b/src/modules/hwclock/main.py index bfb3d1df7..8b31080dd 100644 --- a/src/modules/hwclock/main.py +++ b/src/modules/hwclock/main.py @@ -28,7 +28,7 @@ import libcalamares def run(): """ - Set hardware clock + Set hardware clock. """ root_mount_point = libcalamares.globalstorage.value("rootMountPoint") From 34b96148aeda3d5df9b3e4545d864d4e81cd36d6 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 10 Jul 2017 11:49:19 -0400 Subject: [PATCH 7/8] Python: at beginning of job, if pretty status has changed, emit progress to update it in the UI. --- src/libcalamares/PythonJob.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libcalamares/PythonJob.cpp b/src/libcalamares/PythonJob.cpp index e02f9e210..1955b64fc 100644 --- a/src/libcalamares/PythonJob.cpp +++ b/src/libcalamares/PythonJob.cpp @@ -306,6 +306,7 @@ PythonJob::exec() if ( i_newline > 0 ) m_description.truncate( i_newline ); cDebug() << "Job" << prettyName() << "->" << m_description; + emit progress( 0 ); } bp::object runResult = entryPoint(); From ae6a9cd822a323e95a257965f7fd089cbb44598c Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 10 Jul 2017 11:57:05 -0400 Subject: [PATCH 8/8] Python: move unsquash documentation to the config file --- src/modules/unpackfs/main.py | 17 +---------------- src/modules/unpackfs/unpackfs.conf | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/modules/unpackfs/main.py b/src/modules/unpackfs/main.py index c0970ddfe..9eaa5c622 100644 --- a/src/modules/unpackfs/main.py +++ b/src/modules/unpackfs/main.py @@ -263,22 +263,7 @@ class UnpackOperation: def run(): """ - Unsquashes filesystem from given image file. - - from globalstorage: rootMountPoint - from job.configuration: the path to where to mount the source image(s) for - copying an ordered list of unpack mappings for image file <-> target dir - relative to rootMountPoint, e.g.: - configuration: - unpack: - - source: "/path/to/filesystem.img" - sourcefs: "ext4" - destination: "" - - source: "/path/to/another/filesystem.sqfs" - sourcefs: "squashfs" - destination: "" - - :return: + Unsquash filesystem. """ PATH_PROCFS = '/proc/filesystems' diff --git a/src/modules/unpackfs/unpackfs.conf b/src/modules/unpackfs/unpackfs.conf index 68de113b5..34e7bc48d 100644 --- a/src/modules/unpackfs/unpackfs.conf +++ b/src/modules/unpackfs/unpackfs.conf @@ -1,5 +1,21 @@ +# Unsquash / unpack a filesystem. Multiple sources are supported, and +# they may be squashed or plain filesystems. +# +# Configuration: +# +# from globalstorage: rootMountPoint +# from job.configuration: the path to where to mount the source image(s) +# for copying an ordered list of unpack mappings for image file <-> +# target dir relative to rootMountPoint. + --- unpack: +# Each list item is unpacked, in order, to the target system. +# Each list item has the following attributes: +# source: path relative to the live / intstalling system to the image +# sourcefs: ext4 or squashfs (may be others if mount supports is) +# destination: path relative to rootMountPoint (so in the target +# system) where this filesystem is unpacked. - source: "/path/to/filesystem.img" sourcefs: "ext4" destination: ""