2018-01-10 14:58:15 +01:00
|
|
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
2020-05-30 16:15:03 +02:00
|
|
|
*
|
|
|
|
* SPDX-FileCopyrightText: 2018 Adriaan de Groot <groot@kde.org>
|
2018-01-10 14:58:15 +01:00
|
|
|
*
|
|
|
|
* Calamares is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Calamares is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
2020-05-30 16:15:03 +02:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
* License-Filename: LICENSE
|
|
|
|
*
|
2018-01-10 14:58:15 +01:00
|
|
|
*/
|
|
|
|
|
2019-04-29 12:12:18 +02:00
|
|
|
#ifndef UTILS_COMMANDLIST_H
|
|
|
|
#define UTILS_COMMANDLIST_H
|
2018-01-10 14:58:15 +01:00
|
|
|
|
2018-01-15 11:59:44 +01:00
|
|
|
#include "Job.h"
|
|
|
|
|
2018-01-10 17:01:39 +01:00
|
|
|
#include <QStringList>
|
2018-01-10 14:58:15 +01:00
|
|
|
#include <QVariant>
|
|
|
|
|
2019-08-01 22:47:42 +02:00
|
|
|
#include <chrono>
|
|
|
|
|
2018-01-15 11:59:44 +01:00
|
|
|
namespace CalamaresUtils
|
|
|
|
{
|
|
|
|
|
2018-01-29 17:01:28 +01:00
|
|
|
/**
|
|
|
|
* Each command can have an associated timeout in seconds. The timeout
|
|
|
|
* defaults to 10 seconds. Provide some convenience naming and construction.
|
|
|
|
*/
|
2019-08-01 22:47:42 +02:00
|
|
|
struct CommandLine : public QPair< QString, std::chrono::seconds >
|
2018-01-29 17:01:28 +01:00
|
|
|
{
|
2019-08-04 21:22:54 +02:00
|
|
|
static inline constexpr std::chrono::seconds TimeoutNotSet() { return std::chrono::seconds( -1 ); }
|
2018-01-29 21:25:18 +01:00
|
|
|
|
2018-01-29 21:08:42 +01:00
|
|
|
/// An invalid command line
|
|
|
|
CommandLine()
|
2019-08-01 22:47:42 +02:00
|
|
|
: QPair( QString(), TimeoutNotSet() )
|
2018-01-29 21:08:42 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-01-29 17:01:28 +01:00
|
|
|
CommandLine( const QString& s )
|
2019-08-01 22:47:42 +02:00
|
|
|
: QPair( s, TimeoutNotSet() )
|
2018-01-29 17:01:28 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-08-01 22:47:42 +02:00
|
|
|
CommandLine( const QString& s, std::chrono::seconds t )
|
2019-08-04 21:22:54 +02:00
|
|
|
: QPair( s, t )
|
2018-01-29 17:01:28 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-08-04 21:22:54 +02:00
|
|
|
QString command() const { return first; }
|
2018-01-29 17:01:28 +01:00
|
|
|
|
2019-08-04 21:22:54 +02:00
|
|
|
std::chrono::seconds timeout() const { return second; }
|
2018-01-29 21:08:42 +01:00
|
|
|
|
2019-08-04 21:22:54 +02:00
|
|
|
bool isValid() const { return !first.isEmpty(); }
|
|
|
|
};
|
2018-01-29 17:01:28 +01:00
|
|
|
|
|
|
|
/** @brief Abbreviation, used internally. */
|
|
|
|
using CommandList_t = QList< CommandLine >;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A list of commands; the list may have its own default timeout
|
|
|
|
* for commands (which is then applied to each individual command
|
|
|
|
* that doesn't have one of its own).
|
2018-05-23 15:25:57 +02:00
|
|
|
*
|
|
|
|
* Documentation for the format of commands can be found in
|
|
|
|
* `shellprocess.conf`.
|
2018-01-29 17:01:28 +01:00
|
|
|
*/
|
|
|
|
class CommandList : protected CommandList_t
|
2018-01-10 14:58:15 +01:00
|
|
|
{
|
|
|
|
public:
|
2018-01-29 17:01:28 +01:00
|
|
|
/** @brief empty command-list with timeout to apply to entries. */
|
2019-08-01 22:47:42 +02:00
|
|
|
CommandList( bool doChroot = true, std::chrono::seconds timeout = std::chrono::seconds( 10 ) );
|
|
|
|
CommandList( const QVariant& v, bool doChroot = true, std::chrono::seconds timeout = std::chrono::seconds( 10 ) );
|
2018-01-10 14:58:15 +01:00
|
|
|
~CommandList();
|
|
|
|
|
2019-08-04 21:22:54 +02:00
|
|
|
bool doChroot() const { return m_doChroot; }
|
2018-01-15 11:59:44 +01:00
|
|
|
|
2018-02-07 17:12:49 +01:00
|
|
|
Calamares::JobResult run();
|
2018-01-15 10:57:41 +01:00
|
|
|
|
2019-08-04 21:22:54 +02:00
|
|
|
using CommandList_t::at;
|
2018-01-29 17:01:28 +01:00
|
|
|
using CommandList_t::cbegin;
|
|
|
|
using CommandList_t::cend;
|
|
|
|
using CommandList_t::const_iterator;
|
2019-08-04 21:22:54 +02:00
|
|
|
using CommandList_t::count;
|
|
|
|
using CommandList_t::isEmpty;
|
2018-01-29 17:01:28 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
using CommandList_t::append;
|
|
|
|
void append( const QString& );
|
2018-01-15 10:57:41 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool m_doChroot;
|
2019-08-01 22:47:42 +02:00
|
|
|
std::chrono::seconds m_timeout;
|
2019-08-04 21:22:54 +02:00
|
|
|
};
|
2018-01-10 14:58:15 +01:00
|
|
|
|
2019-08-04 21:22:54 +02:00
|
|
|
} // namespace CalamaresUtils
|
2019-04-29 12:12:18 +02:00
|
|
|
#endif
|