Merge branch 'python-bits'

This commit is contained in:
Adriaan de Groot 2017-07-10 12:03:33 -04:00
commit 8ca94db0fa
7 changed files with 57 additions and 35 deletions

View File

@ -228,6 +228,7 @@ PythonJob::PythonJob( const QString& scriptFile,
: Job( parent )
, m_scriptFile( scriptFile )
, m_workingPath( workingPath )
, m_description()
, m_configurationMap( moduleConfiguration )
{
}
@ -247,8 +248,11 @@ PythonJob::prettyName() const
QString
PythonJob::prettyStatusMessage() const
{
if ( m_description.isEmpty() )
return tr( "Running %1 operation." )
.arg( QDir( m_workingPath ).dirName() );
else
return m_description;
}
@ -293,6 +297,17 @@ 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() ).trimmed();
auto i_newline = m_description.indexOf('\n');
if ( i_newline > 0 )
m_description.truncate( i_newline );
cDebug() << "Job" << prettyName() << "->" << m_description;
emit progress( 0 );
}
bp::object runResult = entryPoint();

View File

@ -53,6 +53,7 @@ private:
CalamaresPython::Helper* helper();
QString m_scriptFile;
QString m_workingPath;
QString m_description;
QVariantMap m_configurationMap;
};

View File

@ -82,13 +82,15 @@ 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" )
{
if ( intfString == "qtplugin" )
@ -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;
}

View File

@ -19,22 +19,22 @@
# You should have received a copy of the GNU General Public License
# along with Calamares. If not, see <http://www.gnu.org/licenses/>.
"""
=== 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"

View File

@ -28,7 +28,7 @@ import libcalamares
def run():
"""
Set hardware clock
Set hardware clock.
"""
root_mount_point = libcalamares.globalstorage.value("rootMountPoint")

View File

@ -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'

View File

@ -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: ""