reindex.pl 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/usr/bin/perl -w
  2. # Copyright 2007 Nick Mathewson. See LICENSE for licensing information.
  3. use strict;
  4. my $propdir = ".";
  5. local *DIR;
  6. local *F;
  7. opendir(DIR, $propdir) || die "Can't open $propdir";
  8. my @files = sort grep { /^\d\d\d-.*[^\~]$/ } readdir(DIR);
  9. closedir DIR;
  10. my %title = ();
  11. my %status = ();
  12. my @KNOWN_STATUSES = qw{
  13. DRAFT OPEN NEEDS-REVISION NEEDS-RESEARCH ACCEPTED META FINISHED CLOSED
  14. SUPERSEDED DEAD};
  15. for my $f (@files) {
  16. my $num = substr($f, 0, 3);
  17. my $status = undef;
  18. my $title = undef;
  19. my $implemented_in = undef;
  20. my $target = undef;
  21. my $alleged_fname = undef;
  22. if ($f !~ /\.txt/) { print "$f doesn't end with .txt\n"; }
  23. open(F, "$f");
  24. while (<F>) {
  25. last if (/^\s*$/);
  26. if (/^Status: (.*)/) {
  27. $status = uc $1;
  28. chomp $status;
  29. }
  30. if (/^Filename: (.*)/) {
  31. $alleged_fname = $1;
  32. chomp $alleged_fname;
  33. }
  34. if (/^Title: (.*)/) {
  35. $title = $1;
  36. $title =~ s/\.$//;
  37. chomp $title;
  38. }
  39. if (/^Implemented-In: (.*)/) {
  40. $implemented_in = $1;
  41. chomp $implemented_in;
  42. }
  43. if (/^Target: (.*)/) {
  44. $target = $1;
  45. chomp $target;
  46. }
  47. }
  48. close F;
  49. die "I've never heard of status $status in proposal $num"
  50. unless (grep(/$status/, @KNOWN_STATUSES) == 1);
  51. die "Proposal $num has a bad status line" if (!defined $status);
  52. die "Proposal $num has a bad title line" if (!defined $title);
  53. die "Proposal $num has no Filename line" unless (defined $alleged_fname);
  54. die "Proposal $num says its fname is $alleged_fname, but it's really $f"
  55. if ($alleged_fname ne $f);
  56. print "No Target for proposal $num\n" if (($status eq 'OPEN' or
  57. $status eq 'ACCEPTED')
  58. and !defined $target);
  59. print "No Implemented-In for proposal $num\n"
  60. if (($status eq 'CLOSED' or $status eq 'FINISHED')
  61. and !defined $implemented_in);
  62. $title{$num} = $title;
  63. $status{$num} = $status;
  64. }
  65. local *OUT;
  66. open(OUT, ">000-index.txt.tmp");
  67. open(F, "000-index.txt") or die "Can't open index file.";
  68. while (<F>) {
  69. print OUT;
  70. last if (/^={3,}/);
  71. }
  72. close(F);
  73. print OUT "Proposals by number:\n\n";
  74. for my $num (sort keys %title) {
  75. print OUT "$num $title{$num} [$status{$num}]\n";
  76. }
  77. print OUT "\n\nProposals by status:\n\n";
  78. for my $status (@KNOWN_STATUSES) {
  79. print OUT " $status:\n";
  80. for my $num (sort keys %status) {
  81. next unless ($status{$num} eq $status);
  82. print OUT " $num $title{$num}\n";
  83. }
  84. }
  85. rename('000-index.txt.tmp', '000-index.txt');