debian.pl 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #!/usr/bin/perl
  2. #
  3. # parsechangelog/debian
  4. #
  5. # Copyright © 1996 Ian Jackson
  6. # Copyright © 2005,2007 Frank Lichtenheld
  7. # Copyright © 2006-2012 Guillem Jover <guillem@debian.org>
  8. #
  9. # This program is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation; either version 2 of the License, or
  12. # (at your option) any later version.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. use strict;
  22. use warnings;
  23. use Getopt::Long qw(:config posix_default bundling no_ignorecase);
  24. use POSIX;
  25. use Dpkg;
  26. use Dpkg::Gettext;
  27. use Dpkg::ErrorHandling;
  28. use Dpkg::Changelog::Debian;
  29. textdomain("dpkg-dev");
  30. $progname = "parsechangelog/$progname";
  31. sub version {
  32. printf _g("Debian %s version %s.\n"), $progname, $version;
  33. printf _g("
  34. This is free software; see the GNU General Public License version 2 or
  35. later for copying conditions. There is NO warranty.
  36. ");
  37. }
  38. sub usage {
  39. printf _g(
  40. "Usage: %s [<option>...] [<changelogfile>]
  41. Options:
  42. -?, --help print usage information
  43. --version, -V print version information
  44. --label, -l <file> name of the changelog file to
  45. use in error messages
  46. --file <file> changelog file to parse, defaults
  47. to '-' (standard input)
  48. --format <outputformat> see man page for list of available
  49. output formats, defaults to 'dpkg'
  50. for compatibility with dpkg-dev
  51. --since, -s, -v <version> include all changes later than version
  52. --until, -u <version> include all changes earlier than version
  53. --from, -f <version> include all changes equal or later
  54. than version
  55. --to, -t <version> include all changes up to or equal
  56. than version
  57. --count, -c, -n <number> include <number> entries from the top
  58. (or the tail if <number> is lower than 0)
  59. --offset, -o <number> change the starting point for --count,
  60. counted from the top (or the tail if
  61. <number> is lower than 0)
  62. --all include all changes
  63. "), $progname;
  64. }
  65. my ( $since, $until, $from, $to, $all, $count, $offset, $file, $label );
  66. my $default_file = '-';
  67. my $format = 'dpkg';
  68. my %allowed_formats = (
  69. dpkg => 1,
  70. rfc822 => 1,
  71. );
  72. sub set_format {
  73. my ($opt, $val) = @_;
  74. unless ($allowed_formats{$val}) {
  75. usageerr(_g('output format %s not supported'), $val );
  76. }
  77. $format = $val;
  78. }
  79. GetOptions( "file=s" => \$file,
  80. "label|l=s" => \$label,
  81. "since|v=s" => \$since,
  82. "until|u=s" => \$until,
  83. "from|f=s" => \$from,
  84. "to|t=s" => \$to,
  85. "count|c|n=i" => \$count,
  86. "offset|o=i" => \$offset,
  87. "help|?" => sub{ usage(); exit(0) },
  88. "version|V" => sub{version();exit(0)},
  89. "format=s" => \&set_format,
  90. "all|a" => \$all,
  91. )
  92. or do { usage(); exit(2) };
  93. usageerr('too many arguments') if @ARGV > 1;
  94. if (@ARGV) {
  95. if ($file && ($file ne $ARGV[0])) {
  96. usageerr(_g('more than one file specified (%s and %s)'),
  97. $file, $ARGV[0] );
  98. }
  99. $file = $ARGV[0];
  100. }
  101. $file ||= $default_file;
  102. $label ||= $file;
  103. unless (defined($since) or defined($until) or defined($from) or
  104. defined($to) or defined($offset) or defined($count) or
  105. defined($all))
  106. {
  107. $count = 1;
  108. }
  109. my %all = $all ? ( all => $all ) : ();
  110. my $range = {
  111. since => $since, until => $until, from => $from, to => $to,
  112. count => $count, offset => $offset,
  113. %all
  114. };
  115. my $changes = Dpkg::Changelog::Debian->new(reportfile => $label, range => $range);
  116. if ($file eq '-') {
  117. $changes->parse(\*STDIN, _g("<standard input>"))
  118. or error(_g('fatal error occurred while parsing input'));
  119. } else {
  120. $changes->load($file)
  121. or error(_g('fatal error occurred while parsing %s'), $file);
  122. }
  123. eval qq{
  124. my \$output = \$changes->$format(\$range);
  125. print \$output if defined \$output;
  126. };
  127. if ($@) {
  128. error("%s", $@);
  129. }