source: appstream-generator/src/asgen/handlers/metainfovalidator.d @ 4841

Last change on this file since 4841 was 4841, checked in by Juanma, 2 years ago

Initial release

File size: 2.3 KB
Line 
1/*
2 * Copyright (C) 2016 Matthias Klumpp <matthias@tenstral.net>
3 *
4 * Licensed under the GNU Lesser General Public License Version 3
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 3 of the license, or
9 * (at your option) any later version.
10 *
11 * This software is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this software.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20module asgen.handlers.metainfovalidator;
21
22import std.path : baseName;
23import std.uni : toLower;
24import std.string : format;
25import std.stdio;
26import std.typecons : scoped;
27
28import appstream.Validator;
29import appstream.ValidatorIssue;
30import appstream.Component;
31import glib.ListG;
32import gobject.ObjectG;
33
34import asgen.result;
35import asgen.utils;
36
37
38void validateMetaInfoFile (GeneratorResult res, Component cpt, string data)
39{
40    auto validator = scoped!Validator ();
41
42    try {
43        validator.validateData (data);
44    } catch (Exception e) {
45        res.addHint (cpt.getId (), "metainfo-validation-issue", "The file could not be validated due to an error: " ~ e.msg);
46        return;
47    }
48
49    auto issueList = validator.getIssues ();
50    for (ListG l = issueList; l !is null; l = l.next) {
51        auto issue = ObjectG.getDObject!ValidatorIssue (cast (typeof(ValidatorIssue.tupleof[0])) l.data);
52
53        // we have a special hint tag for legacy metadata
54        if (issue.getKind () == IssueKind.LEGACY) {
55            res.addHint (cpt.getId (), "ancient-metadata");
56            continue;
57        }
58
59        auto importance = issue.getImportance ();
60        auto msg = issue.getMessage();
61
62        // we ignore pedantic hints by default and don't store or display them
63        if (importance == IssueImportance.PEDANTIC)
64            continue;
65
66        if (importance == IssueImportance.INFO)
67            res.addHint (cpt.getId (), "metainfo-validation-hint", msg);
68        else
69            res.addHint (cpt.getId (), "metainfo-validation-issue", msg);
70    }
71}
Note: See TracBrowser for help on using the repository browser.