[libcalamares] Add a save() method to global storage
- This is a quick way to dump GS to JSON, which is useful for the preservefiles module #928 - Also useful for, e.g., #466
This commit is contained in:
parent
6779a44991
commit
ac287a0ac5
@ -1,7 +1,7 @@
|
|||||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
*
|
*
|
||||||
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
|
* Copyright 2014-2015, 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
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -22,6 +22,9 @@
|
|||||||
|
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
|
#include <QFile>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
|
||||||
#ifdef WITH_PYTHON
|
#ifdef WITH_PYTHON
|
||||||
#include "PythonHelper.h"
|
#include "PythonHelper.h"
|
||||||
|
|
||||||
@ -94,6 +97,19 @@ GlobalStorage::debugDump() const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
GlobalStorage::save(const QString& filename)
|
||||||
|
{
|
||||||
|
QFile f( filename );
|
||||||
|
if ( !f.open( QFile::WriteOnly ) )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
f.write( QJsonDocument::fromVariant( m ).toJson() ) ;
|
||||||
|
f.close();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace Calamares
|
} // namespace Calamares
|
||||||
|
|
||||||
#ifdef WITH_PYTHON
|
#ifdef WITH_PYTHON
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
*
|
*
|
||||||
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
|
* Copyright 2014-2015, 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
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -58,7 +58,16 @@ public:
|
|||||||
int remove( const QString& key );
|
int remove( const QString& key );
|
||||||
QVariant value( const QString& key ) const;
|
QVariant value( const QString& key ) const;
|
||||||
|
|
||||||
|
/// @brief dump keys and values to the debug log
|
||||||
void debugDump() const;
|
void debugDump() const;
|
||||||
|
/** @brief write as JSON to the given filename
|
||||||
|
*
|
||||||
|
* No tidying, sanitization, or censoring is done -- for instance,
|
||||||
|
* the user module sets a slightly-obscured password in global storage,
|
||||||
|
* and this JSON file will contain that password in-the-only-slightly-
|
||||||
|
* obscured form.
|
||||||
|
*/
|
||||||
|
bool save( const QString& filename );
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void changed();
|
void changed();
|
||||||
|
Loading…
Reference in New Issue
Block a user