AppDocScript

Summary

This is the script used to generate Edubuntu/AppGuide and associated pages.

Usage

To run the script, you will need to do the following:

  1. Copy it into a file called appdoc.pl
  2. In the same directory as the script, create a writable directory called "wiki"
  3. Get a copy of the Edubuntu seed files: bzr branch lp:~ubuntu-core-dev/ubuntu-seeds/edubuntu.precise
  4. Run the script: perl ./appdoc.pl edubuntu.precise/ubuntu-edu-*
  5. Copy/Paste from ./wiki/AppGuide.moin into http://wiki.ubuntu.com/Edubuntu/AppGuide

Script

   1 #!/usr/bin/perl
   2 
   3 my @seedFiles = @ARGV || fail("No Seed File given");
   4 my $listFile = 'wiki/AppGuides.moin';
   5 
   6 open(G, '>', $listFile) || die "Could not open $listFile\n$!";
   7 
   8 for my $seedFile (@ARGV) {
   9     print G "== $seedFile ==\n";
  10     my @packages = packages($seedFile);
  11     for my $p (@packages) {
  12         print "Reading Package: ", $p, "\n";
  13         my $aptinfo = aptinfo($p);
  14         #writepage($aptinfo);
  15         
  16         print G " * [[https://apps.ubuntu.com/cat/applications/$p|$p]] - ", $aptinfo->{'shortDescription'}, "\n";
  17     }
  18     print G "\n";
  19 }
  20 close(G);
  21 
  22 sub fail {
  23     my $msg = shift;
  24     print STDERR $msg, "\n";
  25     usage(STDERR);
  26     exit 1;
  27 }
  28 
  29 sub usage {
  30     my $out = shift || STDOUT;
  31     print $out "Usage: ./appdoc.pl seed_file\n\n";
  32 }
  33 
  34 sub packages {
  35     my $seedFile = shift || die "No Seed file given to sub: packages";
  36     open(S, '<', $seedFile) || die "Could not open seed file: $seedFile\n$!";
  37     my @packages = ();
  38     while (my $line = <S>) {
  39         if ($line =~ /^\s+\*\s+\(([a-zA-z0-9_-]+)\)/) {
  40             push(@packages, $1);
  41         }
  42         
  43     }
  44     close(S);
  45     return @packages;
  46 }
  47 
  48 sub aptinfo {
  49     my $package = shift || die "No Package name given to sub: aptinfo";
  50     my %info = ();
  51     open(A, '-|', "apt-cache show $package") || die "Could not open apt-cache for reading $package\n$!";
  52     my $inDesc = 0;
  53     while (my $line = <A>){
  54         chomp $line;
  55         if ($inDesc > 0 && substr($line, 0, 1) eq ' ') {
  56             if ($line eq " .") {
  57                 $info{'Description'} .= "\n ";
  58             } else {
  59                 $info{'Description'} .= "\n" . substr($line, 1);
  60             }
  61         } else {
  62             $inDesc = 0;
  63             my ($key, $val) = split(': ', $line, 2);
  64             if ($key eq 'Description' || $key eq 'Description-en') {
  65                 $inDesc = 1;   
  66                 $info{'shortDescription'} = $val;
  67             } else {
  68                 $info{$key} = $val;
  69             }
  70         }
  71     }
  72     close(A);
  73     return \%info;
  74 }
  75 
  76 sub sections {
  77     my $info = shift || die "No Package Info given to sub: sections";
  78     my %sections = ();
  79     for my $section (split('/', $info->{'Section'})) {
  80         unless ($section =~ m/(main|restricted|universe|multiverse)/) {
  81             if ($section =~ /(science|education|math)/i) {
  82                 $sections{'Educational'} = 1;
  83             }
  84             elsif ($section =~ /(game|entertainment)/i) {
  85                 $sections{'Game'} = 1;
  86             } else {
  87                 $sections{$section} = 1;
  88             }
  89         }
  90     }
  91     return keys %sections;
  92 }
  93 sub languages {
  94     my $info = shift || die "No Package Info given to sub: languages";
  95     my %langs = ();
  96     if ($info->{'Depends'} =~ /libc[^a-zA-Z]/i) {
  97         $langs{'C'} = 1;
  98     }
  99     if ($info->{'Depends'} =~ /libstdc\+\+/i) {
 100         $langs{'C++'} = 1;
 101     }
 102     if ($info->{'Depends'} =~ /python/i) {
 103         $langs{'Python'} = 1;
 104     }
 105     if ($info->{'Depends'} =~ /ruby/i) {
 106         $langs{'Ruby'} = 1;
 107     }
 108     if ($info->{'Depends'} =~ /(java|jvm)/i) {
 109         $langs{'Java'} = 1;
 110     }
 111     return keys %langs;
 112 }
 113 
 114 sub toolkits {
 115     my $info = shift || die "No Package Info given to sub: toolkits";
 116     my %tk = ();
 117     if ($info->{'Depends'} =~ /gtk/i) {
 118         $tk{'GTK'} = 1;
 119     }
 120     if ($info->{'Depends'} =~ /qt/i) {
 121         $tk{'QT'} = 1;
 122     }
 123     if ($info->{'Depends'} =~ /gnome/i) {
 124         $tk{'Gnome'} = 1;
 125     }
 126     if ($info->{'Depends'} =~ /kde/i) {
 127         $tk{'KDE'} = 1;
 128     }
 129     if ($info->{'Depends'} =~ /libsdl/i) {
 130         $tk{'SDL'} = 1;
 131     }
 132     return keys %tk;
 133 }
 134 
 135 sub writepage {
 136     my $info = shift || die "No Package Info given to sub: writepage";
 137     my $pagefile = 'wiki/'.$info->{'Package'}.'.moin';
 138     open(P, '>', $pagefile) || die "Could not open file for writing: $pagefile\n$!";
 139     
 140     my $package = $info->{'Package'};
 141     my $screenshot = "http://screenshots.debian.net/screenshot/$package";
 142     my $type = join(', ', sections($info));
 143     my $desc = $info->{'Description'} || '';
 144     my $langs = join(', ', languages($info));
 145     my $tk = join(', ', toolkits($info));
 146     my $launchpad = "https://launchpad.net/ubuntu/maverick/+source/$package";
 147     my $homepage = $info->{'Homepage'} || '';
 148     my $short = $info->{'shortDescription'} || '';
 149     print P <<EOF;
 150 ##master-page:Edubuntu/AppTemplate
 151 #format wiki
 152 #language en
 153 #title $package
 154 
 155 ||<tablestyle="float:right; font-size: 0.9em; width:40%; background:#F1F1ED; margin: 0 0 1em 1em;" style="padding:0.5em;"><<TableOfContents>>||
 156 
 157 $short
 158 
 159 == Summary ==
 160 $desc
 161 
 162 == Technical Details ==
 163 
 164 || Type || $type ||
 165 || Age Range || Recommended age range ||
 166 || Profile || Edubuntu profile(s) that include this ||
 167 || Website || $homepage ||
 168 || Launchpad || $launchpad ||
 169 || License || License(s) the application is available under ||
 170 || Language || $langs ||
 171 || Toolkit || $tk ||
 172 
 173 == Screenshots ==
 174 
 175 {{$screenshot|$package Screenshot}}
 176 
 177 If a screen shot is not available, submit your own according to the debian screenshot [[http://screenshots.debian.net/upload|guidelines]].
 178 
 179 == User Comments ==
 180 
 181 This space is for users to share their experiences and opinions about the application
 182 
 183 EOF
 184     close(P);
 185 }

Edubuntu/AppGuide/AppDocScript (last edited 2012-05-24 15:24:43 by mhall119)