home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2593 < prev    next >
Encoding:
Text File  |  1991-01-22  |  8.5 KB  |  251 lines

  1. Newsgroups: news.admin,alt.sources,news.software.b
  2. From: urlichs@smurf.sub.org (Matthias Urlichs)
  3. Subject: Re: decent checkgroups message, please?
  4. Message-ID: <-!nbh2.x[8@smurf.sub.org>
  5. Date: Sat, 19 Jan 91 16:43:30 GMT
  6.  
  7. In news.admin, article <1990Nov7.214526.16594@ccu1.aukuni.ac.nz>,
  8.   russell@ccu1.aukuni.ac.nz (Russell J Fulton;ccc032u) writes:
  9. < grady@fx.com (Steven Grady) writes:
  10. < >    c) A couple of checkgroups messages have been issued,
  11. < >       but they complain about lots of reasonable groups,
  12. < >       like comp.lang.perl, news.software.nn, and others
  13. < >       I subscribe to (so I know they aren't bogus), as
  14. < >       well as a number of perfectly good alt groups.
  15. < >       (The last checkgroups I received complained about almost
  16. < >       200 groups.)
  17. < I have the same problem. I think it is the checkgroup message for bionet
  18. < from lear@genbank... This message only lists the bionet groups and so Cnews
  19. < bitches about the rest. Is there anything that can be done about this?
  20.  
  21. Yes. Use the checkgroups program below. (Perl.) Put it in /usr/newsbin/ctl or
  22. wherever.
  23. (Sorry about semi-wildly crossposting this. Flame with email if you feel that
  24.  that is necessary.)
  25.  
  26. It has the advantages that it'll only bitch about hierarchies mentioned in the
  27. checkgroups / whatever message, can cope with the "Alternate newsgroup
  28. hierarchies" posting (no need to edit), maintains a reasonable "newsgroups"
  29. file without more than one lines per newsgroup (and proper indenting per
  30. hierarchy), can cope with more than one file on the command line, updates the
  31. comments in your newsgroups file -- well, enough hype.
  32.  
  33. You'll need a "distributions" file in /usr/lib/news, which lists the
  34. distributions you get, one per line, with an optional description next to it
  35. just like the "newsgroups" file.
  36.  
  37. Disclaimer: It works here.
  38.  
  39.  
  40. #!/usr/local/bin/perl
  41. # checkgroups.pl V0.9
  42.  
  43. chdir "/usr/lib/news"; ## where "newsgroups" and "distributions" is
  44.  
  45. ## this code performs the following, highly useful functions:
  46. # Read the "distributions" file to find out what hierarchies you want.
  47. #  I didn't want to analyze the sys file...
  48. # Read & analyze your newsgroups file.
  49. # Read & analyze input files (extracting any newsgroups-style lines),
  50. #  discarding anything unintelligible or excluded.
  51. #  stdin is read if no files are specified.
  52. #   newsgroups-style lines are defined as lines with a newsgroup name in front,
  53. #   a sequence of tabs, and a description.
  54. #   Optional: a ! in front means that the newsgroup (or distribution, if there
  55. #    are no dots in the newsgroup name) is to be excluded, the trailer
  56. #    " (Moderated)" means just that, and the tabs+description may be missing.
  57. # Read your active file.
  58. # Output a new newsgroups file, appropriately tabulated (per top-level),
  59. #   sorted, which collects all definitions ever encountered, in case you need
  60. #   them again.
  61. # Writes recommendations as to which groups to delete/add/(un)moderate.
  62. #  The command line option "-del" says don't emit delgroup lines unless
  63. #   they seem to be definite.
  64. # Never complain about hierarchies which aren't even mentioned in the
  65. #  checkgroups message.
  66. #
  67. # Public Domain. -- Matthias Urlichs
  68. #   Changes, additions, pretty-upifications, et al., welcome.
  69.  
  70. %desc = (); ## textual descriptions
  71. # state
  72. %reject = (); ## !ed out
  73. %mod = ();    ## marked moderated?
  74. %unmod = ();  ## marked unmoderated?
  75. %mentioned=();## distribution was present in input
  76.  
  77. # actions
  78. %domod = ();  ## change to moderated
  79. %dounmod = ();## change to unmoderated
  80. %add = ();    ## missing
  81. %delete = (); ## present, but superfluous
  82. %there = ();  ## x-ed out, but add it.
  83. %inthere = ();## n-ed out, but add it.
  84.  
  85. open (DIST, "distributions") || die "No distributions file";
  86.  
  87. Config:
  88. while(<DIST>) {
  89.    chop;
  90.    s/\s*#.*//; # drop all comments
  91.    next Config if /^$/; # and empty lines
  92.    if (s/^!//) {
  93.       ($dist, $desc) = split(/\s+/, $_, 2);
  94.       $nondist{$dist} = 1;
  95.    } else {
  96.       ($dist, $desc) = split(/\s+/, $_, 2);
  97.       $dist{$dist} = $desc;
  98.    }
  99. }
  100. close(DIST);
  101.  
  102. if($ARGV[$[] eq '-del') {
  103.    $defdelete = 1;
  104.    shift @ARGV;
  105. }
  106.  
  107. unshift (@ARGV, "-") if $#ARGV < $[; # required because of next line
  108. unshift (@ARGV, "newsgroups");
  109. $examine = 0;
  110. die "No Newsgroups file" unless -r "newsgroups";
  111.  
  112. Newsgroups:
  113. while(<>) {
  114.    chop;
  115.    s/\s*#.*//; # remove comments, as usual
  116.    next Newsgroups if /^$/;
  117.    $exclude = ($_ =~ s/^!//); # remember for later
  118.    next Newsgroups unless (($group, $desc, $dummy) = split(/\t\s*/, $_, 3)) < 3;
  119.    next Newsgroups unless $group =~ /^[a-z]/;
  120.    next Newsgroups if $group =~ /\s/;
  121.    ($dist) = split(/\./, $group, 2);
  122.    next Newsgroups if $nondist{$dist} || $nondist{$group};
  123.    if ($exclude) { 
  124.       $nondist{$group} = 1;
  125.       $mentioned{$dist} = 1 unless $group eq $dist;
  126.       next Newsgroups;
  127.    }
  128.    next Newsgroups unless $dist{$dist};
  129.    $mentioned{$dist} = 1 if $examine;
  130.    if ($desc =~ /\s*\([Mm]oderated\)$/) {
  131.       $mod{$group} = 1;
  132.    } else {
  133.       $mod{$group} = -1;
  134.    }
  135.    if (length($desc) > 5 && ($mod{$group} == -1 || length($desc) > 16)) {
  136.       $desc{$group} = $desc; # replace old descriptions with new version,
  137.           # taking Moderated flag and non-empty-text-requirement into account
  138.    }
  139.    if ($examine && ($reject{$group} != 1)) {
  140.       $add{$group} = 1;
  141.    }
  142. } continue {
  143.    $examine = 1 if (eof);
  144. }
  145.  
  146. open(ACT,"/usr/local/news/admin/active") || die "Couldn't open active file";
  147. Active:
  148. while(<ACT>) {
  149.    chop;
  150.    next Active if /^#/;
  151.    next Active if /^$/;
  152.    ($group, $max,$min, $flag) = split;
  153.    ($dist) = split(/\./, $group, 2);
  154.    next Active unless $mentioned{$dist};
  155.  
  156.    if (   $reject{$group}
  157.        || ($add{$group} != 1)
  158.        || $nondist{$group}
  159.        || $nondist{$dist}) {
  160.       $delete{$group} = 1 unless $flag =~ /^x/;
  161.  
  162.    } elsif ($flag =~ /^x/) {
  163.       $there{$group} = 1;
  164.    } elsif ($flag =~ /^n/ || $flag =~ /^=/) {
  165.       $inthere{$group} = 1;
  166.    } elsif ($flag =~ /^m/) {
  167.       $dounmod{$group} = 1 if $mod{$group} == -1;
  168.    } elsif ($flag =~ /^y/) {
  169.       $domod{$group} = 1 if $mod{$group} == 1;
  170.    }
  171.    if ($flag =~ /^m/ || $flag =~ /^y/) {
  172.       $delete{$group} = 1 unless $add{$group};
  173.    }
  174.    delete $add{$group};
  175. }
  176. close(ACT);
  177.  
  178. open (NG, ">newsgroups");
  179.  
  180. $maxlen = 0;
  181. $olddist = "-";
  182. foreach $group (sort keys %desc) {
  183.    ($dist) = split(/\./, $group, 2);
  184.    if ($olddist ne $dist) {
  185.       $maxlen{$olddist} = int(($maxlen / 8) + 1) * 8;
  186.       $olddist = $dist;
  187.       $maxlen = 0;
  188.    }
  189.    $maxlen = length($group) if length($group) > $maxlen;
  190. }
  191. $maxlen{$olddist} = int (($maxlen / 8) + 1) * 8; #// last one 
  192.  
  193. foreach $group (sort keys %desc) {
  194.    ($dist) = split(/\./, $group, 2);
  195.    $tabs = int(($maxlen{$dist} - length($group) - 1) / 8) + 1;
  196.    print NG $group, "\t" x $tabs, $desc{$group}, "\n";
  197. }
  198. close(NG);
  199.  
  200. open (STDOUT,"|mail -s Checkgroups news");
  201.  
  202. $head = 0; Del: foreach $group (sort keys %delete) {
  203.    ($dist) = split(/\./, $group, 2);
  204.    next Del unless $mentioned{$dist};
  205.    print ("\n#** The following groups should (*:definitely) be removed:\n") unless $head;
  206.    print ((($nondist{$group} || $nondist{$dist}) ? "#*" : "# "),
  207.       $group,"\t",$desc{$group},"\n")
  208.      unless $defdelete || $nondist{$group} || $nondist{$dist};
  209.    print ((($nondist{$group} || $nondist{$dist}) ? "addgroup $group x" : "delgroup $group"),
  210.       "\n")
  211.      unless $defdelete || $nondist{$group} || $nondist{$dist};
  212.    $head = 1;
  213. }
  214.  
  215. $head = 0; Add: foreach $group (sort keys %add) {
  216.    ($dist) = split(/\./, $group, 2);
  217.    next Add unless $dist{$dist};
  218.    next Add unless $mentioned{$dist};
  219.    print ("\n#** The following groups should be created (*:moderated):\n") unless $head;
  220.    print ((($mod{$group} > 0)? "#*" : "# "), $group,"\t",$desc{$group},"\n");
  221.    print "addgroup $group ", (($mod{$group} > 0) ? "m" : "y"), "\n";
  222.    $head = 1;
  223. }
  224.  
  225. $head = 0; DoMod: foreach $group (sort keys %domod) {
  226.    ($dist) = split(/\./, $group, 2);
  227.    next DoMod unless $mentioned{$dist};
  228.    next DoMod if $mod{$group} > 0;
  229.    print ("\n#** The following groups should be made moderated:\n") unless $head;
  230.    print "# ", $group,"\t",$desc{$group},"\n";
  231.    print "addgroup $group m\n";
  232.    $head = 1;
  233. }
  234.  
  235. $head = 0; DoUnmod: foreach $group (sort keys %dounmod) {
  236.    ($dist) = split(/\./, $group, 2);
  237.    next DoUnmod unless $mentioned{$dist};
  238.    next DoUnmod if $mod{$group} == 1;
  239.    print ("\n#** The following groups should be made unmoderated:\n") unless $head;
  240.    print "#  ", $group,"\t",$desc{$group},"\n";
  241.    print "addgroup $group y\n";
  242.    $head = 1;
  243. }
  244.  
  245. -- 
  246. Matthias Urlichs -- urlichs@smurf.sub.org -- urlichs@smurf.ira.uka.de     /(o\
  247. Humboldtstrasse 7 - 7500 Karlsruhe 1 - FRG -- +49+721+621127(0700-2330)   \o)/
  248.