Changeset 760


Ignore:
Timestamp:
Apr 8, 2006, 10:03:14 AM (15 years ago)
Author:
Dominic Hargreaves
Message:

Support DOAP

File:
1 edited

Legend:

Unmodified
Added
Removed
  • utils/get-guide-versions

    r755 r760  
    55use strict;
    66use warnings;
    7 use WWW::Mechanize;
     7use XML::Simple;
     8use LWP::UserAgent;
    89
    910my $out = "/srv/www/dev.openguides.org/html/static/versions.html";
     
    2627               'Boston, MA' => 'http://boston.openguides.org/',
    2728               'Saint Paul, MN' => 'http://saintpaul.openguides.org/',
    28                'The Tourist Engineer' => 'http://engineer.openguides.org/'
     29               'The Tourist Engineer' => 'http://engineer.openguides.org/',
     30               "Earle's testing" => 'http://openguides.org/testing/'
    2931             );
    3032
    31 my $mech = WWW::Mechanize->new(agent => "OpenGuides get-guide-versions",
    32                                autocheck => 1);
     33my $ua = LWP::UserAgent->new(agent => "OpenGuides get-guide-versions");
    3334
    3435open OUT, ">$out" or die $!;
    3536
    3637print OUT "<html><head><title>Versions of OpenGuides in use</title></head>\n";
    37 print OUT "<body><table>\n";
     38print OUT "<body>\n";
     39print OUT "Last updated: " . scalar(localtime(time)) . "\n";
     40print OUT "<table>\n";
    3841
    39 foreach my $guide (keys %guides) {
     42foreach my $guide (sort keys %guides) {
    4043    print OUT "<tr><td><a href=\"$guides{$guide}\">$guide</td><td>";
    41     $mech->add_header( Referer => undef );
    42     $mech->get($guides{$guide});
    43     my $content = $mech->content;
    44     if ($content =~ /version.(0\.\d+)/s) {
    45         print OUT $1;
    46     } else {
    47         print OUT "Not found";
     44
     45    # Try DOAP
     46    my $success = 0;
     47    my $response = $ua->get("$guides{$guide}?action=about;format=rdf");
     48    if ($response->is_success) {
     49        my $doap = eval { XMLin($response->content)} ;
     50        if ($@) {
     51            # fall through
     52        } else {
     53            if (my $version = eval { $doap->{Project}->{release}->{Version}->{revision} }) {
     54                print OUT "$version (DOAP)";
     55                $success++;
     56            }
     57        }
    4858    }
    49     print OUT "</td></tr>\n";
     59    if ($success == 0) {
     60        $response = $ua->get($guides{$guide});
     61        if ($response->is_success) {
     62            my $content = $response->content;
     63            if ($content =~ /version.(0\.\d+)/s) {
     64                print OUT $1;
     65            } else {
     66                print OUT "Not found";
     67            }
     68            print OUT " (HTML)";
     69        } else {
     70            print "No methods worked";
     71        }
     72        print OUT "</td></tr>\n";
     73    }
    5074}
    5175
Note: See TracChangeset for help on using the changeset viewer.