[libcalamares] Stub of saveYaml
- This belongs alongside loadYaml, so place it in libcalamares - Doesn't actually save anything yet (it isn't used yet)
This commit is contained in:
parent
5efbf51ed3
commit
5e1bcd9b4a
@ -21,6 +21,7 @@
|
|||||||
#include "JobQueue.h"
|
#include "JobQueue.h"
|
||||||
|
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
#include "utils/YamlUtils.h"
|
||||||
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
@ -110,6 +111,23 @@ GlobalStorage::save(const QString& filename)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
GlobalStorage::saveYaml( const QString& filename )
|
||||||
|
{
|
||||||
|
return CalamaresUtils::saveYaml( filename, m );
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
GlobalStorage::loadYaml( const QString& filename )
|
||||||
|
{
|
||||||
|
bool ok = false;
|
||||||
|
auto gs = CalamaresUtils::loadYaml( filename, &ok );
|
||||||
|
if ( ok )
|
||||||
|
m = gs;
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace Calamares
|
} // namespace Calamares
|
||||||
|
|
||||||
#ifdef WITH_PYTHON
|
#ifdef WITH_PYTHON
|
||||||
|
@ -203,4 +203,38 @@ loadYaml(const QString& filename, bool* ok)
|
|||||||
return QVariantMap();
|
return QVariantMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief Convenience function writes @p indent times four spaces
|
||||||
|
static void
|
||||||
|
writeIndent( QFile& f, int indent )
|
||||||
|
{
|
||||||
|
while ( indent > 0 )
|
||||||
|
f.write( " " );
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @brief Recursive helper to dump @p map to file
|
||||||
|
static bool
|
||||||
|
dumpYaml( QFile& f, const QVariantMap& map, int indent )
|
||||||
|
{
|
||||||
|
for ( auto it = map.cbegin(); it != map.cend(); ++it )
|
||||||
|
{
|
||||||
|
writeIndent( f, indent );
|
||||||
|
f.write( it.key().toUtf8() );
|
||||||
|
f.write( "\n" );
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
saveYaml( const QString& filename, const QVariantMap& map )
|
||||||
|
{
|
||||||
|
QFile f( filename );
|
||||||
|
if ( !f.open( QFile::WriteOnly ) )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
f.write( "# YAML dump\n---\n" );
|
||||||
|
return dumpYaml( f, map, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -51,6 +51,9 @@ QVariant yamlScalarToVariant( const YAML::Node& scalarNode );
|
|||||||
QVariant yamlSequenceToVariant( const YAML::Node& sequenceNode );
|
QVariant yamlSequenceToVariant( const YAML::Node& sequenceNode );
|
||||||
QVariant yamlMapToVariant( const YAML::Node& mapNode );
|
QVariant yamlMapToVariant( const YAML::Node& mapNode );
|
||||||
|
|
||||||
|
/// @brief Save a @p map to @p filename as YAML
|
||||||
|
bool saveYaml( const QString& filename, const QVariantMap& map );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given an exception from the YAML parser library, explain
|
* Given an exception from the YAML parser library, explain
|
||||||
* what is going on in terms of the data passed to the parser.
|
* what is going on in terms of the data passed to the parser.
|
||||||
|
Loading…
Reference in New Issue
Block a user