Merge pull request #1619 from deprov447/Upload_Install_Log

[libcalamaresui] Implementing LogUpload functionality from branding
This commit is contained in:
Adriaan de Groot 2021-02-26 13:13:16 +01:00 committed by GitHub
commit cc3017be53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 91 additions and 8 deletions

View File

@ -219,3 +219,16 @@ slideshow: "show.qml"
slideshowAPI: 2 slideshowAPI: 2
# These options are to customize online uploading of logs to pastebins:
# - type : Defines the kind of pastebin service to be used.Currently
# it accepts two values:
# - none : disables the pastebin functionality
# - fiche : use fiche pastebin server
# - url : Defines the address of pastebin service to be used.
# Takes string as input
# - port : Defines the port number to be used to send logs. Takes
# integer as input
uploadServer :
type : "fiche"
url : "termbin.com"
port : 9999

View File

@ -4,6 +4,7 @@
* SPDX-FileCopyrightText: 2017-2019 Adriaan de Groot <groot@kde.org> * SPDX-FileCopyrightText: 2017-2019 Adriaan de Groot <groot@kde.org>
* SPDX-FileCopyrightText: 2018 Raul Rodrigo Segura (raurodse) * SPDX-FileCopyrightText: 2018 Raul Rodrigo Segura (raurodse)
* SPDX-FileCopyrightText: 2019 Camilo Higuita <milo.h@aol.com> * SPDX-FileCopyrightText: 2019 Camilo Higuita <milo.h@aol.com>
* SPDX-FileCopyrightText: 2021 Anubhav Choudhary <ac.10edu@gmail.com>
* SPDX-License-Identifier: GPL-3.0-or-later * SPDX-License-Identifier: GPL-3.0-or-later
* *
* Calamares is Free Software: see the License-Identifier above. * Calamares is Free Software: see the License-Identifier above.
@ -86,6 +87,13 @@ const QStringList Branding::s_styleEntryStrings =
"sidebarTextSelect", "sidebarTextSelect",
"sidebarTextHighlight" "sidebarTextHighlight"
}; };
const QStringList Branding::s_uploadServerStrings =
{
"type",
"url",
"port"
};
// clang-format on // clang-format on
// *INDENT-ON* // *INDENT-ON*
@ -218,6 +226,12 @@ Branding::Branding( const QString& brandingFilePath, QObject* parent )
return imageFi.absoluteFilePath(); return imageFi.absoluteFilePath();
} ); } );
loadStrings( m_style, doc, "style", []( const QString& s ) -> QString { return s; } ); loadStrings( m_style, doc, "style", []( const QString& s ) -> QString { return s; } );
const QVariantMap temp = CalamaresUtils::yamlMapToVariant( doc[ "uploadServer" ] );
for ( auto it = temp.constBegin(); it != temp.constEnd(); ++it )
{
m_uploadServer.insert( it.key(), it.value().toString() );
}
} }
catch ( YAML::Exception& e ) catch ( YAML::Exception& e )
{ {
@ -278,6 +292,11 @@ Branding::imagePath( Branding::ImageEntry imageEntry ) const
return m_images.value( s_imageEntryStrings.value( imageEntry ) ); return m_images.value( s_imageEntryStrings.value( imageEntry ) );
} }
QString
Branding::uploadServer( Branding::UploadServerEntry uploadServerEntry ) const
{
return m_uploadServer.value( s_uploadServerStrings.value( uploadServerEntry ) );
}
QPixmap QPixmap
Branding::image( Branding::ImageEntry imageEntry, const QSize& size ) const Branding::image( Branding::ImageEntry imageEntry, const QSize& size ) const

View File

@ -4,6 +4,7 @@
* SPDX-FileCopyrightText: 2017-2018 Adriaan de Groot <groot@kde.org> * SPDX-FileCopyrightText: 2017-2018 Adriaan de Groot <groot@kde.org>
* SPDX-FileCopyrightText: 2018 Raul Rodrigo Segura (raurodse) * SPDX-FileCopyrightText: 2018 Raul Rodrigo Segura (raurodse)
* SPDX-FileCopyrightText: 2019 Camilo Higuita <milo.h@aol.com> * SPDX-FileCopyrightText: 2019 Camilo Higuita <milo.h@aol.com>
* SPDX-FileCopyrightText: 2021 Anubhav Choudhary <ac.10edu@gmail.com>
* SPDX-License-Identifier: GPL-3.0-or-later * SPDX-License-Identifier: GPL-3.0-or-later
* *
* Calamares is Free Software: see the License-Identifier above. * Calamares is Free Software: see the License-Identifier above.
@ -22,6 +23,7 @@
#include <QPixmap> #include <QPixmap>
#include <QSize> #include <QSize>
#include <QStringList> #include <QStringList>
#include <QUrl>
namespace YAML namespace YAML
{ {
@ -42,6 +44,7 @@ public:
* e.g. *Branding::ProductName to get the string value for * e.g. *Branding::ProductName to get the string value for
* the product name. * the product name.
*/ */
enum StringEntry enum StringEntry
{ {
ProductName, ProductName,
@ -80,6 +83,14 @@ public:
}; };
Q_ENUM( StyleEntry ) Q_ENUM( StyleEntry )
enum UploadServerEntry : short
{
Type,
URL,
Port
};
Q_ENUM( UploadServerEntry )
/** @brief Setting for how much the main window may expand. */ /** @brief Setting for how much the main window may expand. */
enum class WindowExpansion enum class WindowExpansion
{ {
@ -223,6 +234,7 @@ public slots:
QString styleString( StyleEntry styleEntry ) const; QString styleString( StyleEntry styleEntry ) const;
QString imagePath( ImageEntry imageEntry ) const; QString imagePath( ImageEntry imageEntry ) const;
QString uploadServer( UploadServerEntry uploadServerEntry ) const;
PanelSide sidebarSide() const { return m_sidebarSide; } PanelSide sidebarSide() const { return m_sidebarSide; }
PanelSide navigationSide() const { return m_navigationSide; } PanelSide navigationSide() const { return m_navigationSide; }
@ -233,12 +245,14 @@ private:
static const QStringList s_stringEntryStrings; static const QStringList s_stringEntryStrings;
static const QStringList s_imageEntryStrings; static const QStringList s_imageEntryStrings;
static const QStringList s_styleEntryStrings; static const QStringList s_styleEntryStrings;
static const QStringList s_uploadServerStrings;
QString m_descriptorPath; // Path to descriptor (e.g. "/etc/calamares/default/branding.desc") QString m_descriptorPath; // Path to descriptor (e.g. "/etc/calamares/default/branding.desc")
QString m_componentName; // Matches last part of full path to containing directory QString m_componentName; // Matches last part of full path to containing directory
QMap< QString, QString > m_strings; QMap< QString, QString > m_strings;
QMap< QString, QString > m_images; QMap< QString, QString > m_images;
QMap< QString, QString > m_style; QMap< QString, QString > m_style;
QMap< QString, QString > m_uploadServer;
/* The slideshow can be done in one of two ways: /* The slideshow can be done in one of two ways:
* - as a sequence of images * - as a sequence of images

View File

@ -4,6 +4,7 @@
* SPDX-FileCopyrightText: 2017-2018 Adriaan de Groot <groot@kde.org> * SPDX-FileCopyrightText: 2017-2018 Adriaan de Groot <groot@kde.org>
* SPDX-FileCopyrightText: 2019 Dominic Hayes <ferenosdev@outlook.com> * SPDX-FileCopyrightText: 2019 Dominic Hayes <ferenosdev@outlook.com>
* SPDX-FileCopyrightText: 2019 Gabriel Craciunescu <crazy@frugalware.org> * SPDX-FileCopyrightText: 2019 Gabriel Craciunescu <crazy@frugalware.org>
* SPDX-FileCopyrightText: 2021 Anubhav Choudhary <ac.10edu@gmail.com>
* SPDX-License-Identifier: GPL-3.0-or-later * SPDX-License-Identifier: GPL-3.0-or-later
* *
* Calamares is Free Software: see the License-Identifier above. * Calamares is Free Software: see the License-Identifier above.
@ -141,7 +142,8 @@ ViewManager::insertViewStep( int before, ViewStep* step )
void void
ViewManager::onInstallationFailed( const QString& message, const QString& details ) ViewManager::onInstallationFailed( const QString& message, const QString& details )
{ {
bool shouldOfferWebPaste = false; // TODO: config var QString serverType = Calamares::Branding::instance()->uploadServer( Calamares::Branding::Type );
bool shouldOfferWebPaste = CalamaresUtils::UploadServersList.contains( serverType );
cError() << "Installation failed:" << message; cError() << "Installation failed:" << message;
cDebug() << Logger::SubEntry << "- message:" << message; cDebug() << Logger::SubEntry << "- message:" << message;
@ -187,8 +189,16 @@ ViewManager::onInstallationFailed( const QString& message, const QString& detail
connect( msgBox, &QMessageBox::buttonClicked, [msgBox]( QAbstractButton* button ) { connect( msgBox, &QMessageBox::buttonClicked, [msgBox]( QAbstractButton* button ) {
if ( msgBox->buttonRole( button ) == QMessageBox::ButtonRole::YesRole ) if ( msgBox->buttonRole( button ) == QMessageBox::ButtonRole::YesRole )
{ {
// TODO: host and port should be configurable QString pasteUrlMsg;
QString pasteUrlMsg = CalamaresUtils::sendLogToPastebin( msgBox, QStringLiteral( "termbin.com" ), 9999 ); QString serverType = Calamares::Branding::instance()->uploadServer( Calamares::Branding::Type );
if ( serverType == "fiche" )
{
pasteUrlMsg = CalamaresUtils::ficheLogUpload( msgBox );
}
else
{
pasteUrlMsg = QString();
}
QString pasteUrlTitle = tr( "Install Log Paste URL" ); QString pasteUrlTitle = tr( "Install Log Paste URL" );
if ( pasteUrlMsg.isEmpty() ) if ( pasteUrlMsg.isEmpty() )

View File

@ -9,20 +9,35 @@
#include "Paste.h" #include "Paste.h"
#include "Branding.h"
#include "utils/Logger.h" #include "utils/Logger.h"
#include <QFile> #include <QFile>
#include <QRegularExpression> #include <QRegularExpression>
#include <QTcpSocket> #include <QTcpSocket>
#include <QUrl> #include <QUrl>
#include <QClipboard>
#include <QApplication>
#include <QStringList>
namespace CalamaresUtils namespace CalamaresUtils
{ {
QStringList UploadServersList = {
"fiche"
// In future more serverTypes can be added as Calamares support them
// "none" serverType is explicitly not mentioned here
};
QString QString
sendLogToPastebin( QObject* parent, const QString& ficheHost, quint16 fichePort ) ficheLogUpload( QObject* parent )
{ {
QString pasteUrlFmt = parent->tr( "Install log posted to:\n%1" );
const QString& ficheHost = Calamares::Branding::instance()->uploadServer( Calamares::Branding::URL );
quint16 fichePort = Calamares::Branding::instance()->uploadServer( Calamares::Branding::Port ).toInt();
QString pasteUrlFmt = parent->tr( "Install log posted to\n\n%1\n\nLink copied to clipboard" );
QFile pasteSourceFile( Logger::logFile() ); QFile pasteSourceFile( Logger::logFile() );
if ( !pasteSourceFile.open( QIODevice::ReadOnly | QIODevice::Text ) ) if ( !pasteSourceFile.open( QIODevice::ReadOnly | QIODevice::Text ) )
{ {
@ -78,7 +93,17 @@ sendLogToPastebin( QObject* parent, const QString& ficheHost, quint16 fichePort
QRegularExpression pasteUrlRegex( "^http[s]?://" + ficheHost ); QRegularExpression pasteUrlRegex( "^http[s]?://" + ficheHost );
QString pasteUrlMsg = QString( pasteUrlFmt ).arg( pasteUrlStr ); QString pasteUrlMsg = QString( pasteUrlFmt ).arg( pasteUrlStr );
if ( nBytesRead < 8 || !pasteUrl.isValid() || !pasteUrlRegex.match( pasteUrlStr ).hasMatch() ) if ( nBytesRead >= 8 && pasteUrl.isValid() && pasteUrlRegex.match( pasteUrlStr ).hasMatch() )
{
QClipboard* clipboard = QApplication::clipboard();
clipboard->setText(pasteUrlStr, QClipboard::Clipboard);
if (clipboard->supportsSelection())
{
clipboard->setText(pasteUrlStr, QClipboard::Selection);
}
}
else
{ {
cError() << "No data from paste server"; cError() << "No data from paste server";
return QString(); return QString();

View File

@ -10,7 +10,7 @@
#ifndef UTILS_PASTE_H #ifndef UTILS_PASTE_H
#define UTILS_PASTE_H #define UTILS_PASTE_H
#include <qglobal.h> // for quint16 #include<QStringList>
class QObject; class QObject;
class QString; class QString;
@ -22,7 +22,9 @@ namespace CalamaresUtils
* *
* Returns the (string) URL that the pastebin gives us. * Returns the (string) URL that the pastebin gives us.
*/ */
QString sendLogToPastebin( QObject* parent, const QString& ficheHost, quint16 fichePort ); QString ficheLogUpload( QObject* parent );
extern QStringList UploadServersList;
} // namespace CalamaresUtils } // namespace CalamaresUtils