File indexing completed on 2024-12-15 04:56:11

0001 /*
0002  * Copyright (C) 2014 Aaron Seigo <aseigo@kde.org>
0003  *
0004  *   This program is free software; you can redistribute it and/or modify
0005  *   it under the terms of the GNU General Public License as published by
0006  *   the Free Software Foundation; either version 2 of the License, or
0007  *   (at your option) any later version.
0008  *
0009  *   This program is distributed in the hope that it will be useful,
0010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012  *   GNU General Public License for more details.
0013  *
0014  *   You should have received a copy of the GNU General Public License
0015  *   along with this program; if not, write to the
0016  *   Free Software Foundation, Inc.,
0017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
0018  */
0019 
0020 #include "check.h"
0021 
0022 #include "../datasetdefinition.h"
0023 
0024 #include <QDir>
0025 #include <QObject>
0026 
0027 #include <iostream>
0028 
0029 namespace HAWD
0030 {
0031 
0032 CheckAll::CheckAll()
0033     : Module()
0034 {
0035     setSyntax(Syntax("checkall", &CheckAll::check));
0036     setDescription(QObject::tr("Checks all dataset descriptions for validity and prints out any errors it finds"));
0037 }
0038 
0039 bool CheckAll::check(const QStringList &commands, State &state)
0040 {
0041     QDir project(state.projectPath());
0042     project.setFilter(QDir::Files | QDir::Readable | QDir::NoDotAndDotDot | QDir::NoSymLinks);
0043     for (const QString &entry: project.entryList()) {
0044         Check::checkFile(entry, state);
0045     }
0046 
0047     return true;
0048 }
0049 
0050 Check::Check()
0051     : Module()
0052 {
0053     Syntax top("check", &Check::check);
0054     setSyntax(top);
0055 
0056     setDescription(QObject::tr("Checks one or more dataset descriptions for validity and prints out any errors it finds"));
0057 }
0058 
0059 bool Check::check(const QStringList &commands, State &state)
0060 {
0061     if (commands.isEmpty()) {
0062         std::cout << QObject::tr("Please provide the name of a dataset definition file. (Use the 'list' command to see available datasets.)").toStdString() << std::endl;
0063     } else {
0064         for (const QString &name: commands) {
0065             checkFile(name, state);
0066         }
0067     }
0068 
0069     return true;
0070 }
0071 
0072 void Check::checkFile(const QString &name, State &state)
0073 {
0074     DatasetDefinition def = state.datasetDefinition(name);
0075     if (def.isValid()) {
0076         std::cout << QObject::tr("%1 is OK").arg(name).toStdString() << std::endl;
0077     } else {
0078         std::cout << QObject::tr("%1 has errors: %2").arg(name).arg(def.lastError()).toStdString() << std::endl;
0079     }
0080 }
0081 
0082 } // namespace HAWD
0083