+middleman
[MyWeb.git] / Project.pm
index 4cacd84..6fed111 100644 (file)
@@ -30,65 +30,93 @@ our @EXPORT=qw();
 our @ISA=qw(My::Web Exporter);
 
 
+sub ENTRIES     { return top_dir()."/project/CVS/Entries"; }
+sub ENTRIES_LOG { return top_dir()."/project/CVS/Entries.Log"; }
+
+
 sub print_project ($)
 {
 my($class,$ListItem)=@_;
 
-       print "<h1>".$ListItem->{"name"}."</h1>\n";
+       print "<h1>".$W->{"title"}."</h1>\n";
        print $ListItem->{"description"};
        print "<hr />\n";
        my @table=(
-               {"key"=>qr(^download\b.*),"text"=>sub ($) {
-                                               $_[0]=~s/^download//;
-                                               $_[0]=~s/^-/ /;
-                                               return "Download".$_[0];
-                                               },
-                               "format"=>sub ($) {
-                                               my $r;
-                                               if ($_[0]=~m#^[a-z]+://#) {
-                                                       $r=a_href($_[0],CGI::escapeHTML($_[0]));
-                                                       }
-                                               else {
-                                                       $r=a_href($_[0],CGI::escapeHTML(File::Basename::basename($_[0])));
-                                                       my $size=(stat $_[0])[7];
-                                                       die "Cannot stat \"".$_[0]."\": $!" if !defined $size;
-                                                                if ($size>=1024*1024) { $size=int($size/(1024*1024))." MB"; }
-                                                       elsif ($size>=1024     ) { $size=int($size/(1024     ))." KB"; }
-                                                       else                     { $size=int($size            )." B"; }
-                                                       $r.=" ($size)";
-                                                       }
-                                               return $r;
-                                               }},
-               {"key"=>qr(^link\b.*),"text"=>sub ($) {
-                                               $_[0]=~s/^link-//;
-                                               return $_[0];
-                                               },
-                               "format"=>sub ($) {
-                                               return a_href($_[0],CGI::escapeHTML($_[0]));
-                                               }},
                {"key"=>"summary","text"=>"Summary"},
-               {"key"=>"ownership","text"=>"Ownership"},
                {"key"=>"license","text"=>"License","format"=>sub ($) {
                                my %known=(
                                                "PD"=>"Public Domain",
                                                "GPL"=>a_href("http://www.gnu.org/licenses/gpl.html","GNU General Public License"),
                                                "LGPL"=>a_href("http://www.gnu.org/licenses/lgpl.html","GNU Lesser General Public License"),
+                                               "com"=>"Commercial"
                                                );
                                return $known{$_[0]};
                                }},
-               {"key"=>"maintenance","text"=>"Currently maintained?","format"=>sub ($) {
+               {"key"=>"maintenance","text"=>"State","format"=>sub ($) {
                                my %known=(
-                                               "finished"=>"Project is finished. Possible bug reports welcome although project not actively developed.",
-                                               "dead"=>"Project became dead code, some updates would be required. It is no longer used, project is not supported.",
-                                               "obsolete"=>"Obsolete as some other existing package superseded this one.",
-                                               "merge"=>"Functions of this package should be merged to some other one.",
-                                               "update"=>"Package needs updating to be fully usable, patches welcome.",
-                                               "accepted"=>"This patch was accepted by the original package author. It has no longer any separate meaning.",
+                                               "active"=>"Ready to use. Project is now actively developed.",
+                                               "ready"=>"Ready to use. Maintained.",
+                                               "pending"=>"Patch is ready to be applied to the mainstream.",
+                                               "dead"=>"Dead code, no longer supported.",
+                                               "merge"=>"Functions belong to existing other project.",
+                                               "obsolete"=>"Obsoleted.",
+                                               "update"=>"Package needs updating to recent software.",
+                                               "accepted"=>"This patch got already integrated by the original package maintainer.",
+                                               ""=>"",
                                                );
-                               return $known{$_[0]};
+                               my @r;
+                               for ($known{($_[0]=~/^([^-]*)-?/)[0] || ""}) {
+                                       push @r,$_ if $_;
+                                       push @r," $'" if $';
+                                       }
+                               return join(" ",@r);
                                }},
-               {"key"=>"reason","text"=>"Reason"},
-               {"key"=>"sponsorship","text"=>"Sponsoring Company"},
+               {"key"=>"aminet","text"=>a_href('http://www.aminet.net/','Aminet'),"format"=>sub ($) {
+                               return join(" ",
+                                               a_href('http://www.aminet.net/'.$_[0].".lha",$_[0].".lha"),
+                                               "(".a_href('http://www.aminet.net/'.$_[0].".readme","readme").")");
+                               }},
+               {"key"=>qr(^download\b),"text"=>sub ($) {
+                                               $_[0]=~s/^download//;
+                                               $_[0]=~s/^-/ /;
+                                               return "Download".$_[0];
+                                               },
+                               "format"=>sub ($) {
+                                               return a_href($_[0],CGI::escapeHTML(File::Basename::basename($_[0])));
+                                               }},
+               {"key"=>qr(^link\b),"text"=>sub ($) {
+                                               $_[0]=~s/^link-//;
+                                               return $_[0];
+                                               },
+                               "format"=>sub ($) {
+                                               return($_[0]=~/^<a\b/ ? $_[0] : a_href($_[0],CGI::escapeHTML($_[0])));
+                                               }},
+               {"key"=>qr(^cvs\b),"text"=>sub ($) {
+                                               $_[0]=~s/^cvs//;
+                                               $_[0]=~s/^-/ /;
+                                               return "CVS".$_[0];
+                                               },
+                               "format"=>sub ($$) {
+                                               my($val,$key)=@_;
+                                               $key=~s/^cvs//;
+                                               $key=~s/^-/ /;
+                                               my $branch="";
+                                               $branch=$1 if $val=~s/:(.*)//;
+                                               return join("<br />\n\t\t",
+                                                               CGI::escapeHTML("cvs -d ".$W->{"pserver"}.":".$W->{"pserver_path"}." -z3"
+                                                                               ." checkout".(!$branch ? "" : " -r $branch -kk")
+                                                                               .($val!~m#/# ? "" : " -d ".File::Basename::basename($val))
+                                                                               ." $val"),
+                                                               join(" | \n\t\t",
+                                                                               map({ a_href($_->[1],$_->[0]); }
+                                                                                               ["ViewCVS CVS repository",$W->{"project_viewcvs"}.$val."/".(!$branch ? "" : '?only_with_tag='.$branch)],
+                                                                                               ["Download CVS snapshot" ,
+                                                                                                               $W->{"project_viewcvs"}.$val."/".File::Basename::basename($val).".tar.gz?tarball=1"
+                                                                                                                               .(!$branch ? "" : '&only_with_tag='.$branch)],
+                                                                                               ["CVS ChangeLog"         ,top_dir()."/project/ChangeLog.txt.pl?cvs=$val"])));
+                                               }},
+               {"key"=>"ownership","text"=>"Ownership"},
+               {"key"=>"sponsorship","text"=>"Sponsorship"},
                {"key"=>"language","text"=>"Programming language","format"=>sub ($) {
                                return a_href("http://java.sun.com/",CGI::escapeHTML($_[0]))
                                                if $_[0]=~/^Java\b/;
@@ -97,43 +125,42 @@ my($class,$ListItem)=@_;
                                return undef();
                                }},
                );
-       print '<table border="0">'."\n";
 
 sub tableit_func
 {
 my($tableit,$val,$key,$ListItem)=@_;
 
-       print "<tr><td>";
-       if (!ref $tableit->{"text"}) {
-               print $tableit->{"text"};
-               }
-       else {
-               my $textfunc=$tableit->{"text"};
-               my $key=$key;
-               print &$textfunc($key);
-               }
-       print ":</td>";
-       if ($tableit->{"format"}) {
-               my $format=$tableit->{"format"};
-               my $valn=&$format($val);
-               $val=$valn if defined $valn;
-               }
-       print "<td>$val</td></tr>\n";
        delete $ListItem->{$key};
+       my $r="";
+       $r.="<tr>";
+               if ($tableit->{"text"}) {
+                       $r.="<td>";
+                               $r.=(!ref $_ ? $_ : &{$_}($key)) for ($tableit->{"text"});
+                       $r.="</td>";
+                       }
+               if ($tableit->{"format"}) {
+                       do { $val=$_ if defined $_; } for (&{$tableit->{"format"}}($val,$key));
+                       }
+               return join("",map("<tr><td>".$_->[0]."</td><td>".$_->[1]."</td></tr>\n",@$val))
+                               if ref $val;
+               $r.="<td>$val</td>";
+       $r.="</tr>\n";
 }
 
-       for my $tableit (@table) {
-               if (!ref $tableit->{"key"}) {
-                       tableit_func($tableit,$ListItem->{$tableit->{"key"}},$tableit->{"key"},$ListItem) if $ListItem->{$tableit->{"key"}};
-                       }
-               else {
-                       for my $key (@{$ListItem->{"keys_array"}}) {
-                               my $keyregex=$tableit->{"key"};
-                               next if $key!~/$keyregex/;
-                               tableit_func($tableit,$ListItem->{$key},$key,$ListItem);
+       print '<table border="0" class="print_project">'."\n";
+               for my $tableit (@table) {
+                       if (!ref $tableit->{"key"}) {
+                               print tableit_func($tableit,$ListItem->{$tableit->{"key"}},$tableit->{"key"},$ListItem)
+                                               if $ListItem->{$tableit->{"key"}};
+                               }
+                       else {
+                               for my $key (@{$ListItem->{"keys_array"}}) {
+                                       my $keyregex=$tableit->{"key"};
+                                       next if $key!~/$keyregex/;
+                                       print tableit_func($tableit,$ListItem->{$key},$key,$ListItem);
+                                       }
                                }
                        }
-               }
        print "</table>\n";
        print vskip;
 }
@@ -154,14 +181,42 @@ sub init_project ($%)
 my($class,%args)=@_;
 
        my $ListItem={ project_arr_to_hash(@{$args{"ListItem"}}) };
-       my $name=$ListItem->{"name"};
-       $name=~s#<a\s[^>]*>([^<]*)</a>#$1#g;
        my $W=$class->init(
-                       "title"=>$name,
-                       %args);
+                       "title"=>$ListItem->{"name"}.": ".$ListItem->{"summary"},
+                       %args,
+                       "head_css"=>($args{"head_css"} || "")."
+table.print_project td { vertical-align: top; }
+",
+                       );
        $class->heading();
        $class->print_project({ %$ListItem });
        return $W;
 }
 
+sub item_hash_read ()
+{
+       my %dirs;
+       for my $ENTRIES (ENTRIES(),ENTRIES_LOG()) {
+               local *E;
+               next if !open E,$ENTRIES;
+               while (<E>) {
+                       chomp;
+                       do { $dirs{$1}=1; next; } if m#^(?:A )?D/([^/]*)/#;
+                       next if m#^/([^/]*)/# ;
+                       next if /^D$/;
+                       warn "File $ENTRIES contains invalid line \"$_\": $!";
+                       }
+               close E;
+               }
+
+       my %item;
+       for my $dir (keys(%dirs)) {
+               Wrequire "project::${dir}::ListItem";
+               my $item=eval('\@project::'.$dir.'::ListItem::ListItem');
+               do { warn "Broken project/$dir/ListItem.pm"; next; } if !defined $item;
+               $item{$dir}={ My::Project::project_arr_to_hash(@$item) };
+               }
+       return %item;
+}
+
 1;