[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#813904: lintian: Check if upstream/metadata files are well formed



Package: lintian
Version: 2.5.40.2
Tags: patch

The Debian Med project is using the upstream/metadata YAML files to
store bibliographical references and other stuff, and would like a
lintian check to verify that the files are well formed.  Here is  a
draft patch for doing so.

Is this the correct approach?  This is my first lintian check written
from scratch, so I am a bit unsure about the details.

>From abd573bb63691af164095aa1af64d09d6fa547ff Mon Sep 17 00:00:00 2001
From: Petter Reinholdtsen <pere@hungry.com>
Date: Sat, 6 Feb 2016 15:50:09 +0100
Subject: [PATCH] Add draft lintian check for debian/upstream/metadata.

---
 checks/upstream-metadata.desc | 11 +++++++++
 checks/upstream-metadata.pm   | 57 +++++++++++++++++++++++++++++++++++++++++++
 profiles/debian/main.profile  |  3 ++-
 3 files changed, 70 insertions(+), 1 deletion(-)
 create mode 100644 checks/upstream-metadata.desc
 create mode 100644 checks/upstream-metadata.pm

diff --git a/checks/upstream-metadata.desc b/checks/upstream-metadata.desc
new file mode 100644
index 0000000..2947d9b
--- /dev/null
+++ b/checks/upstream-metadata.desc
@@ -0,0 +1,11 @@
+Check-Script: upstream-metadata
+Author: Petter Reinholdtsen <pere@hungry.com>
+Type: source
+Needs-Info: unpacked, diffstat, file-info, md5sums
+Info: This script checks the <tt>upstream/metadata</tt> file for problems.
+
+Tag: upstream-metadata-yaml-invalid
+Severity: normal
+Certainty: certain
+Info: The DEP 12 metadata file is not well formed.  The formatting
+ need to be adjusted to match the YAML specification.
diff --git a/checks/upstream-metadata.pm b/checks/upstream-metadata.pm
new file mode 100644
index 0000000..98b183c
--- /dev/null
+++ b/checks/upstream-metadata.pm
@@ -0,0 +1,57 @@
+# upstream-metadata -- lintian check script -*- perl -*-
+
+# Copyright © 2016 Petter Reinholdtsen
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, you can find it on the World Wide
+# Web at http://www.gnu.org/copyleft/gpl.html, or write to the Free
+# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+# MA 02110-1301, USA.
+
+package Lintian::upstream_metadata;
+
+use strict;
+use warnings;
+
+use Lintian::Data;
+use Lintian::Tags qw(tag);
+
+use YAML;
+use Data::Dumper;
+
+sub run {
+    my (undef, undef, $info) = @_;
+    my $droot = $info->index_resolved_path('debian/');
+    return if not $droot;
+    my $dudir = $droot->resolve_path('upstream');
+    return if not $dudir;
+    my $yamlfile = $dudir->resolve_path('metadata') if $dudir;
+    my $path = $yamlfile->fs_path();
+    if ( -f $path ) {
+        # Handle invalid files, the library will die() when it find them.
+        my $yaml;
+        eval '$yaml = YAML::LoadFile($path);';
+        if (! $yaml) {
+            tag('upstream-metadata-yaml-invalid');
+        }
+    }
+    return;
+}
+
+1;
+
+# Local Variables:
+# indent-tabs-mode: nil
+# cperl-indent-level: 4
+# End:
+# vim: syntax=perl sw=4 sts=4 sr et
diff --git a/profiles/debian/main.profile b/profiles/debian/main.profile
index 92adb0d..6476de2 100644
--- a/profiles/debian/main.profile
+++ b/profiles/debian/main.profile
@@ -8,6 +8,7 @@ Enable-Tags-From-Check: apache2, application-not-library, automake, binaries,
  group-checks, huge-usr-share, infofiles, init.d, java, lintian, manpages,
  md5sums, menu-format, menus, nmu, obsolete-sites, ocaml, patch-systems, phppear,
  po-debconf, rules, scripts, shared-libs, source-copyright, standards-version,
- symlinks, systemd, testsuite, usrmerge, version-substvars, watch-file
+ symlinks, systemd, testsuite, upstream-metadata, usrmerge, version-substvars,
+ watch-file
 Disable-Tags: hardening-no-stackprotector
 
-- 
2.1.4

--
Happy hacking
Petter Reinholdtsen


Reply to: