@ -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
@ -21,6 +21,8 @@
# include "DllMacro.h"
# include "Job.h"
# include <QObject>
# include <QPair>
# include <QString>
@ -33,6 +35,37 @@ public:
/** @brief Implicit one-argument constructor has no output, only a return code */
ProcessResult ( int r ) : QPair < int , QString > ( r , QString ( ) ) { }
ProcessResult ( int r , QString s ) : QPair < int , QString > ( r , s ) { }
int getExitCode ( ) const { return first ; }
QString getOutput ( ) const { return second ; }
/** @brief Explain a typical external process failure.
*
* @ param parent Used as context for translation calls .
* @ param errorCode Return code from runCommand ( ) or similar
* ( negative values get special explanation ) . The member
* function uses the exit code stored in the ProcessResult
* @ param output ( error ) output from the command , used when there is
* an error to report ( exit code > 0 ) . The member
* function uses the output stored in the ProcessResult .
* @ param command String or split - up string of the command
* that was invoked .
* @ param timeout Timeout passed to the process runner , for explaining
* error code - 4 ( timeout ) .
*/
static Calamares : : JobResult explainProcess ( const QObject * parent , int errorCode , const QString & command , const QString & output , int timeout ) ;
/// @brief Convenience wrapper for explainProcess()
inline Calamares : : JobResult explainProcess ( const QObject * parent , const QString & command , int timeout ) const
{
return explainProcess ( parent , getExitCode ( ) , command , getOutput ( ) , timeout ) ;
}
/// @brief Convenience wrapper for explainProcess()
inline Calamares : : JobResult explainProcess ( const QObject * parent , const QStringList & command , int timeout ) const
{
return explainProcess ( parent , getExitCode ( ) , command . join ( ' ' ) , getOutput ( ) , timeout ) ;
}
} ;
/**
@ -71,15 +104,20 @@ public:
const QString & options = QString ( ) ) ;
/** (Typed) Boolean describing where a particular command should be run,
* whether in the host ( live ) system or in the ( chroot ) target system .
*/
enum class RunLocation { RunInHost , RunInTarget } ;
/**
* Runs the specified command in the chroot of the target system .
* @ param args the command with arguments , as a string list .
* @ param workingPath the current working directory for the QProcess
* call ( optional ) .
* call ( optional ) .
* @ param stdInput the input string to send to the running process as
* standard input ( optional ) .
* standard input ( optional ) .
* @ param timeoutSec the timeout after which the process will be
* killed ( optional , default is 0 i . e . no timeout ) .
* killed ( optional , default is 0 i . e . no timeout ) .
*
* @ returns the program ' s exit code and its output ( if any ) . Special
* exit codes ( which will never have any output ) are :
@ -88,12 +126,32 @@ public:
* - 3 = bad arguments
* - 4 = QProcess timeout
*/
DLLEXPORT ProcessResult targetEnvCommand (
static DLLEXPORT ProcessResult runCommand (
RunLocation location ,
const QStringList & args ,
const QString & workingPath = QString ( ) ,
const QString & stdInput = QString ( ) ,
int timeoutSec = 0 ) ;
/** @brief Convenience wrapper for runCommand().
* Runs the command in the location specified through the boolean
* doChroot ( ) , which is what you usually want for running commands
* during installation .
*/
inline ProcessResult targetEnvCommand (
const QStringList & args ,
const QString & workingPath = QString ( ) ,
const QString & stdInput = QString ( ) ,
int timeoutSec = 0 )
{
return runCommand (
m_doChroot ? RunLocation : : RunInTarget : RunLocation : : RunInHost ,
args ,
workingPath ,
stdInput ,
timeoutSec ) ;
}
/** @brief Convenience wrapper for targetEnvCommand() which returns only the exit code */
inline int targetEnvCall ( const QStringList & args ,
const QString & workingPath = QString ( ) ,