debian.pl 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #!/usr/bin/perl
  2. #
  3. # parsechangelog/debian
  4. #
  5. # Copyright © 1996 Ian Jackson
  6. # Copyright © 2005,2007 Frank Lichtenheld
  7. # Copyright © 2006-2014 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 <https://www.gnu.org/licenses/>.
  21. use strict;
  22. use warnings;
  23. use Getopt::Long qw(:config posix_default bundling no_ignorecase);
  24. use Dpkg ();
  25. use Dpkg::Util qw(none);
  26. use Dpkg::Gettext;
  27. use Dpkg::ErrorHandling;
  28. use Dpkg::Changelog::Debian;
  29. textdomain('dpkg-dev');
  30. $Dpkg::PROGNAME = "parsechangelog/$Dpkg::PROGNAME";
  31. sub version {
  32. printf g_("Debian %s version %s.\n"), $Dpkg::PROGNAME, $Dpkg::PROGVERSION;
  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>...] [<changelog-file>]')
  41. . "\n\n" . g_(
  42. "Options:
  43. --file <file> changelog <file> to parse (defaults to '-').
  44. -l, --label <file> changelog <file> name to use in error messages.
  45. --format <output-format>
  46. set the output format (defaults to 'dpkg').
  47. --all include all changes.
  48. -s, --since <version> include all changes later than <version>.
  49. -v <version> ditto.
  50. -u, --until <version> include all changes earlier than <version>.
  51. -f, --from <version> include all changes equal or later than <version>.
  52. -t, --to <version> include all changes up to or equal than <version>.
  53. -c, --count <number> include <number> entries from the top (or tail if
  54. <number> is lower than 0).
  55. -n <number> ditto.
  56. -o, --offset <number> change starting point for --count, counted from
  57. the top (or tail if <number> is lower than 0).
  58. -?, --help print usage information.
  59. -V, --version print version information.
  60. "), $Dpkg::PROGNAME;
  61. }
  62. my ( $since, $until, $from, $to, $all, $count, $offset, $file, $label );
  63. my $default_file = '-';
  64. my $format = 'dpkg';
  65. my %allowed_formats = (
  66. dpkg => 1,
  67. rfc822 => 1,
  68. );
  69. sub set_format {
  70. my ($opt, $val) = @_;
  71. unless ($allowed_formats{$val}) {
  72. usageerr(g_('output format %s not supported'), $val );
  73. }
  74. $format = $val;
  75. }
  76. my @options_spec = (
  77. 'file=s' => \$file,
  78. 'label|l=s' => \$label,
  79. 'since|v=s' => \$since,
  80. 'until|u=s' => \$until,
  81. 'from|f=s' => \$from,
  82. 'to|t=s' => \$to,
  83. 'count|c|n=i' => \$count,
  84. 'offset|o=i' => \$offset,
  85. 'help|?' => sub{ usage(); exit(0) },
  86. 'version|V' => sub{version();exit(0)},
  87. 'format=s' => \&set_format,
  88. 'all|a' => \$all,
  89. );
  90. {
  91. local $SIG{__WARN__} = sub { usageerr($_[0]) };
  92. GetOptions(@options_spec);
  93. }
  94. usageerr('too many arguments') if @ARGV > 1;
  95. if (@ARGV) {
  96. if ($file && ($file ne $ARGV[0])) {
  97. usageerr(g_('more than one file specified (%s and %s)'),
  98. $file, $ARGV[0] );
  99. }
  100. $file = $ARGV[0];
  101. }
  102. $file //= $default_file;
  103. $label //= $file;
  104. my %all = $all ? ( all => $all ) : ();
  105. my $range = {
  106. since => $since, until => $until, from => $from, to => $to,
  107. count => $count, offset => $offset,
  108. %all
  109. };
  110. if (none { defined $range->{$_} } qw(since until from to offset count all)) {
  111. $range->{count} = 1;
  112. }
  113. my $changes = Dpkg::Changelog::Debian->new(reportfile => $label, range => $range);
  114. $changes->load($file)
  115. or error(g_('fatal error occurred while parsing %s'), $file);
  116. my $entries = $changes->format_range($format, $range);
  117. print $entries if defined $entries;