mirror of
https://github.com/parchlinux/calamares.git
synced 2025-06-26 08:58:22 -04:00
[libcalamares] another convenience for running commands
Back targetEnvCommand() with a more general runCommand() that takes an argument selecting the location to run the command in. This allows us also to use the same API for running processes in the host during install, as we do for running them in the target system. One reason for this change is wanting to run (user-specified) commands and independently from the global dontChroot setting, run those commands in the live system or the target. This changes the ABI of the DLL, since targetEnvCommand() is no longer exported. Plugins will need to be recompiled. - refactor targetEnvCommand() into more general runCommand(). - While here, allow host system commands to run even if there is no global storage. - provide convenience accessors for ProcessResult members - Move explanation of process errors out of ProcessJob - Move from ProcessJob to ProcessResult, so it can be reused outside of ProcessJob (e.g. from ShellProcessJob). - Add some convenience functions, too.
This commit is contained in:
parent
6e01bb0fa4
commit
4ff1a0d5ea
4 changed files with 108 additions and 52 deletions
|
@ -1,7 +1,7 @@
|
|||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||
*
|
||||
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
|
||||
* Copyright 2017, Adriaan de Groot <groot@kde.org>
|
||||
* Copyright 2017-2018, Adriaan de Groot <groot@kde.org>
|
||||
*
|
||||
* Calamares is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -93,7 +93,8 @@ System::mount( const QString& devicePath,
|
|||
}
|
||||
|
||||
ProcessResult
|
||||
System::targetEnvCommand(
|
||||
System::runCommand(
|
||||
System::RunLocation location,
|
||||
const QStringList& args,
|
||||
const QString& workingPath,
|
||||
const QString& stdInput,
|
||||
|
@ -105,8 +106,8 @@ System::targetEnvCommand(
|
|||
return -3;
|
||||
|
||||
Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage();
|
||||
if ( !gs ||
|
||||
( m_doChroot && !gs->contains( "rootMountPoint" ) ) )
|
||||
if ( ( location == System::RunLocation::RunInTarget ) &&
|
||||
( !gs || !gs->contains( "rootMountPoint" ) ) )
|
||||
{
|
||||
cLog() << "No rootMountPoint in global storage";
|
||||
return -3;
|
||||
|
@ -116,7 +117,7 @@ System::targetEnvCommand(
|
|||
QString program;
|
||||
QStringList arguments;
|
||||
|
||||
if ( m_doChroot )
|
||||
if ( location == System::RunLocation::RunInTarget )
|
||||
{
|
||||
QString destDir = gs->value( "rootMountPoint" ).toString();
|
||||
if ( !QDir( destDir ).exists() )
|
||||
|
@ -249,4 +250,42 @@ System::doChroot() const
|
|||
return m_doChroot;
|
||||
}
|
||||
|
||||
Calamares::JobResult
|
||||
ProcessResult::explainProcess( const QObject* parent, int ec, const QString& command, const QString& output, int timeout )
|
||||
{
|
||||
using Calamares::JobResult;
|
||||
|
||||
if ( ec == 0 )
|
||||
return JobResult::ok();
|
||||
|
||||
if ( ec == -1 ) //Crash!
|
||||
return JobResult::error( parent->tr( "External command crashed" ),
|
||||
parent->tr( "Command %1 crashed.\nOutput:\n%2" )
|
||||
.arg( command )
|
||||
.arg( output ) );
|
||||
|
||||
if ( ec == -2 )
|
||||
return JobResult::error( parent->tr( "External command failed to start" ),
|
||||
parent->tr( "Command %1 failed to start." )
|
||||
.arg( command ) );
|
||||
|
||||
if ( ec == -3 )
|
||||
return JobResult::error( parent->tr( "Internal error when starting command" ),
|
||||
parent->tr( "Bad parameters for process job call." ) );
|
||||
|
||||
if ( ec == -4 )
|
||||
return JobResult::error( parent->tr( "External command failed to finish" ),
|
||||
parent->tr( "Command %1 failed to finish in %2s.\nOutput:\n%3" )
|
||||
.arg( command )
|
||||
.arg( timeout )
|
||||
.arg( output ) );
|
||||
|
||||
//Any other exit code
|
||||
return JobResult::error( parent->tr( "External command finished with errors" ),
|
||||
parent->tr( "Command %1 finished with exit code %2.\nOutput:\n%3" )
|
||||
.arg( command )
|
||||
.arg( ec )
|
||||
.arg( output ) );
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue