[SCM] Git repository for devscripts branch, master, updated. v2.12.0-9-gebfc784

Benjamin Drung bdrung at debian.org
Thu Jul 26 14:34:44 UTC 2012


The following commit has been merged in the master branch:
commit ebfc7841096c1c6566a48c5dd6688dfc2aa2b211
Author: Benjamin Drung <bdrung at debian.org>
Date:   Thu Jul 26 16:34:31 2012 +0200

    licensecheck: add --machine option that outputs results in a machine readable format.
    
    Thanks: Eric Lavarde
    Closes: #583750

diff --git a/debian/changelog b/debian/changelog
index a901b06..928f8fd 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -4,6 +4,8 @@ devscripts (2.12.2) UNRELEASED; urgency=low
     - Don't truncate other licenses on Public domain or WTFPL presence.
       Thanks to Garrett Holmstrom from Fedora for the patch.
     - Remove trailing spaces.
+    - add --machine option that outputs results in a machine readable format.
+      Thanks to Eric Lavarde for the patch. (Closes: #583750)
 
  -- Benjamin Drung <bdrung at debian.org>  Thu, 26 Jul 2012 12:17:51 +0200
 
diff --git a/scripts/licensecheck.pl b/scripts/licensecheck.pl
index 324dcea..4c1affe 100755
--- a/scripts/licensecheck.pl
+++ b/scripts/licensecheck.pl
@@ -28,7 +28,8 @@ B<licensecheck> B<--help>|B<--version>
 
 B<licensecheck> [B<--no-conf>] [B<--verbose>] [B<--copyright>]
 [B<-l>|B<--lines=>I<N>] [B<-i>|B<--ignore=>I<regex>] [B<-c>|B<--check=>I<regex>]
-[B<-r>|B<--recursive>] I<list of files and directories to check>
+[B<-m>|B<--machine>] [B<-r>|B<--recursive>]
+I<list of files and directories to check>
 
 =head1 DESCRIPTION
 
@@ -77,6 +78,13 @@ The default includes common source files.
 
 Also display copyright text found within the file
 
+=item B<-m>, B<--machine>
+
+Displays the information in a machine readable way, i.e. in the form
+<file><tab><license>[<tab><copyright>] so that it can be easily sorted
+and/or filtered, e.g. with the F<awk> and F<sort> commands.
+Note that using the B<--verbose> option will kill the readibility.
+
 =item B<--no-conf>, B<--noconf>
 
 Do not read any configuration files. This can only be used as the first
@@ -163,6 +171,7 @@ my ($opt_verbose, $opt_lines, $opt_noconf, $opt_ignore_regex, $opt_check_regex)
   = ('', '', '', '', '');
 my $opt_recursive = 0;
 my $opt_copyright = 0;
+my $opt_machine = 0;
 my ($opt_help, $opt_version);
 my $def_lines = 60;
 
@@ -218,6 +227,7 @@ GetOptions("help|h" => \$opt_help,
 	   "recursive|r" => \$opt_recursive,
 	   "check|c=s" => \$opt_check_regex,
 	   "copyright" => \$opt_copyright,
+	   "machine|m" => \$opt_machine,
 	   "noconf" => \$opt_noconf,
 	   "no-conf" => \$opt_noconf,
 	   )
@@ -297,12 +307,18 @@ while (@files) {
     $content =~ tr/ //s;
 
     $license = parselicense($content);
-    print "$file: ";
-    print "*No copyright* " unless $copyright;
-    print $license . "\n";
-    print "  [Copyright: " . $copyright . "]\n"
-      if $copyright and $opt_copyright;
-    print "\n" if $opt_copyright;
+    if ($opt_machine) {
+	print "$file\t$license";
+	print "\t" . ($copyright or "*No copyright*") if $opt_copyright;
+	print "\n";
+    } else {
+	print "$file: ";
+	print "*No copyright* " unless $copyright;
+	print $license . "\n";
+	print "  [Copyright: " . $copyright . "]\n"
+	  if $copyright and $opt_copyright;
+	print "\n" if $opt_copyright;
+    }
 }
 
 sub parse_copyright($) {
@@ -356,6 +372,7 @@ Valid options are:
    --check, -c            Specify a pattern indicating which files should
                              be checked
                              (Default: '$default_check_regex')
+   --machine, -m          Display in a machine readable way (good for awk)
    --recursive, -r        Add the contents of directories recursively
    --copyright            Also display the file's copyright
    --ignore, -i           Specify that files / directories matching the
diff --git a/test/test_licensecheck b/test/test_licensecheck
index 1b89915..a8814d1 100755
--- a/test/test_licensecheck
+++ b/test/test_licensecheck
@@ -24,6 +24,11 @@ license() {
     runCommand "licensecheck/$1" "licensecheck/$1: $2" "" 0
 }
 
+license2() {
+    cd "$WORKDIR"
+    runCommand "$1 licensecheck/$2" "licensecheck/$2	$3" "" 0
+}
+
 testBeerware() {
     license "beerware.cpp" "Beerware"
 }
@@ -41,4 +46,10 @@ testDual() {
     license "dual.c" "Public domain GPL (v3)"
 }
 
+testMachine() {
+    license2 "-m" "beerware.cpp" "Beerware"
+    license2 "--machine" "lgpl-2.1.h" "LGPL (v2.1)"
+    license2 "-m --copyright" "gpl-2" "GPL (v2)	2012 Devscripts developers"
+}
+
 . shunit2

-- 
Git repository for devscripts



More information about the devscripts-devel mailing list