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 "list.h"
0021 
0022 #include "../datasetdefinition.h"
0023 
0024 #include <QDebug>
0025 #include <QDir>
0026 #include <QObject>
0027 
0028 #include <iostream>
0029 
0030 namespace HAWD
0031 {
0032 
0033 List::List()
0034     : Module()
0035 {
0036     Syntax top("list", &List::list);
0037     setSyntax(top);
0038     setDescription(QObject::tr("Lists all dataset files or, when given one or more names"));
0039 }
0040 
0041 bool List::list(const QStringList &commands, State &state)
0042 {
0043     QDir project(state.projectPath());
0044 
0045     if (commands.isEmpty()) {
0046         project.setFilter(QDir::Files | QDir::Readable | QDir::NoDotAndDotDot | QDir::NoSymLinks);
0047         const QStringList entryList = project.entryList();
0048 
0049         if (entryList.isEmpty()) {
0050             std::cout << QObject::tr("No data sets in this project").toStdString() << std::endl;
0051         } else {
0052             std::cout << QObject::tr("Data sets in this project:").toStdString() << std::endl;
0053             for (const QString &file: project.entryList()) {
0054                 std::cout << '\t' << file.toStdString() << std::endl;
0055             }
0056         }
0057     } else {
0058         for (const QString &file: commands) {
0059             DatasetDefinition dataset(project.absoluteFilePath(file));
0060             if (dataset.isValid()) {
0061                 DatasetDefinition dataset(project.absoluteFilePath(file));
0062                 std::cout << '\t' << QObject::tr("Dataset: %1").arg(dataset.name()).toStdString() << std::endl;
0063                 for (const auto &column : dataset.columns()) {
0064                     std::cout << "\t\t" << column.second.typeString().toStdString() << ' ' << column.first.toStdString() << std::endl;
0065                 }
0066             } else {
0067                 std::cout << QObject::tr("Problem with dataset %1. Check with 'check' command.").arg(file).toStdString() << std::endl;
0068             }
0069         }
0070     }
0071 
0072     return true;
0073 }
0074 
0075 } // namespace HAWD
0076