Jul 192006
 

On FreshPorts, virtual categories have no description.

What are virtual cagtegories? Those categories that do not have a corresponding subdirectory in the ports tree. They are only used as secondary categories, and only for search purposes.

FreshPorts can easily detect the creation of a new category, be it virtual or real (non-virtual). FreshPorts can grab the description of each new real category using the make command. For example:

$ cd /usr/ports/sysutils
$ make -V COMMENT
System utilities

For virtual categories, there is no directory that FreshPorts can use. As a result, several categories have no description in FreshPorts. For example, the hamradio page has “This is a virtual category. No description is available.” at the top of the page. This isn’t ideal in my humble opinion.

This is where I solicit your help.

To my knowledge, there is only one authoritative place that contains a description of virtual categories: The Porter’s Handbook, specifically, the link listed above.

I would appreciate it if someone could write a script (perferably in Perl, but I’m also open to Python). What I need is a list of virtual category names and their description. What I’d like is a function that, given a filename on disk, will return an array/hash/something that contains this information. To get you started, you want this file (368KB) from the FreeBSD CVS tree. Scan through the file until you find “Current list of categories”. Just after that, you will see the table of categories. I need every category that ends with a *. For example, afterstep*.

After posting the above, Mark Linimon pointed me at a much better source for this information. I would appreciate it if someone could write a script (perferably in Perl, but I’m also open to Python). What I need is a list of category names (both virtual and non-virtual), the description, and the category (that bit on the end of the line). What I’d like is a function that, given a filename on disk, will return an array/hash/something that contains this information.

Up for it? It’d be great if I could have this script by Thursday night, so I can code with it on the trip back to Ottawa on Friday…

Please post the results here, or email me via dan at langille dot org.

Thanks.

Success

A mere 22 minutes after I posted to the FreeBSD ports mailing list, Anton Berezin sent me a solution. It appears below:

#! /usr/bin/perl

use 5.006;
use warnings;
use strict;

use Text::CSV_XS;  # textproc/p5-Text-CSV_XS

# = for testing
use Data::Dumper;
print Dumper [parse_categories(shift)];
# = end of test

# Input:  filename
# Output: an array of hashes representing categories,
#         each hash having fields named "category",
#         "description", and "class"
sub parse_categories
{
   my ($fn) = @_;

   open my $fh, "<", $fn or die "cannot open $fn: $!\n";
   my $csv = Text::CSV_XS->new();
   my @r;
   while (<$fh>)
   {
      chomp;
      next if /^\s*#/;
      next if /^\s*$/;

      if ($csv->parse($_)) {
         my @c = $csv->fields;
         if (@c != 3) {
            warn "oops, got " . scalar(@c) . " fields at line $. while expecting 3\n";
            next;
         }
         push @r, {
            category    => $c[0],
            description => $c[1],
            class       => $c[2],
         };
      } else {
         warn "oops, cannot parse line $.\n";
      }
   }
   close $fh;
   return @r;
}
Website Pin Facebook Twitter Myspace Friendfeed Technorati del.icio.us Digg Google StumbleUpon Premium Responsive