2018-01-10 14:58:15 +01:00
|
|
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
|
|
|
*
|
|
|
|
* Copyright 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
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef COMMANDLIST_H
|
|
|
|
#define COMMANDLIST_H
|
|
|
|
|
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>
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
struct CommandLine : public QPair< QString, int >
|
|
|
|
{
|
2018-01-29 21:25:18 +01:00
|
|
|
enum { TimeoutNotSet = -1 };
|
|
|
|
|
2018-01-29 21:08:42 +01:00
|
|
|
/// An invalid command line
|
|
|
|
CommandLine()
|
2018-01-29 21:25:18 +01:00
|
|
|
: QPair< QString, int >( QString(), TimeoutNotSet )
|
2018-01-29 21:08:42 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-01-29 17:01:28 +01:00
|
|
|
CommandLine( const QString& s )
|
2018-01-29 21:25:18 +01:00
|
|
|
: QPair< QString, int >( s, TimeoutNotSet )
|
2018-01-29 17:01:28 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CommandLine( const QString& s, int t )
|
|
|
|
: QPair< QString, int >( s, t)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QString command() const
|
|
|
|
{
|
|
|
|
return first;
|
|
|
|
}
|
|
|
|
|
|
|
|
int timeout() const
|
|
|
|
{
|
|
|
|
return second;
|
|
|
|
}
|
2018-01-29 21:08:42 +01: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).
|
|
|
|
*/
|
|
|
|
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. */
|
|
|
|
CommandList( bool doChroot = true, int timeout = 10 );
|
|
|
|
CommandList( const QVariant& v, bool doChroot = true, int timeout = 10 );
|
2018-01-10 14:58:15 +01:00
|
|
|
~CommandList();
|
|
|
|
|
2018-01-15 11:59:44 +01:00
|
|
|
bool doChroot() const
|
|
|
|
{
|
|
|
|
return m_doChroot;
|
|
|
|
}
|
|
|
|
|
|
|
|
Calamares::JobResult run( const QObject* parent );
|
2018-01-15 10:57:41 +01:00
|
|
|
|
2018-01-29 17:01:28 +01:00
|
|
|
using CommandList_t::isEmpty;
|
|
|
|
using CommandList_t::count;
|
|
|
|
using CommandList_t::cbegin;
|
|
|
|
using CommandList_t::cend;
|
|
|
|
using CommandList_t::const_iterator;
|
2018-01-29 21:08:42 +01:00
|
|
|
using CommandList_t::at;
|
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;
|
2018-01-29 17:01:28 +01:00
|
|
|
int m_timeout;
|
2018-01-10 14:58:15 +01:00
|
|
|
} ;
|
|
|
|
|
2018-01-15 11:59:44 +01:00
|
|
|
} // namespace
|
2018-01-10 14:58:15 +01:00
|
|
|
#endif // COMMANDLIST_H
|