[libcalamares] Start refactor of running-a-process support

The background idea is that, while CalamaresUtils::System::runCommand()
is a useful general API, it is
- still missing flexibility
- lacking a way to process output from the command "as it happens"

Waiting until the process ends, and then reading all stdout, is
inconvenient for processes that produce a **lot** of output,
and also makes it impossible to report progress. One module
in calamares-extensions has its own run-a-process implementation
for reading output, and this branch aims to introduce something
similar into Calamares core.
This commit is contained in:
Adriaan de Groot 2021-07-28 13:11:06 +02:00
parent a9a287fa59
commit 2de09d4001
2 changed files with 92 additions and 0 deletions

View File

@ -0,0 +1,38 @@
/* === This file is part of Calamares - <https://calamares.io> ===
*
* SPDX-FileCopyrightText: 2021 Adriaan de Groot <groot@kde.org>
* SPDX-License-Identifier: GPL-3.0-or-later
*
* Calamares is Free Software: see the License-Identifier above.
*
*
*/
#include "Runner.h"
namespace
{
}
namespace Calamares
{
namespace Utils
{
struct Runner::Private
{
QStringList m_command;
};
Runner::Runner() {}
Runner::Runner( const QStringList& command )
: d( std::make_unique< Private >() )
{
d->m_command = command;
}
Runner::~Runner() {}
} // namespace Utils
} // namespace Calamares

View File

@ -0,0 +1,54 @@
/* === This file is part of Calamares - <https://calamares.io> ===
*
* SPDX-FileCopyrightText: 2021 Adriaan de Groot <groot@kde.org>
* SPDX-License-Identifier: GPL-3.0-or-later
*
* Calamares is Free Software: see the License-Identifier above.
*
*
*/
#ifndef UTILS_RUNNER_H
#define UTILS_RUNNER_H
#include "CalamaresUtilsSystem.h"
#include <QObject>
#include <QStringList>
#include <chrono>
#include <memory>
#include <optional>
namespace Calamares
{
namespace Utils
{
using RunLocation = CalamaresUtils::System::RunLocation;
class Runner : public QObject
{
Q_OBJECT
public:
Runner();
Runner( const QStringList& command );
virtual ~Runner() override;
Runner& setCommand( const QStringList& command );
Runner& setLocation( RunLocation r );
Runner& setWorkingDirectory( const QString& directory );
// TODO: maybe with QDir as well?
Runner& setTimeout( std::chrono::seconds timeout );
Runner& setInput( const QString& stdin );
private:
struct Private;
std::unique_ptr< Private > d;
};
} // namespace Utils
} // namespace Calamares
#endif