commit-womb
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[commit-womb] gnumaint gnufsd-psql


From: Kaloian Doganov
Subject: [commit-womb] gnumaint gnufsd-psql
Date: Mon, 20 Apr 2009 07:32:58 +0000

CVSROOT:        /sources/womb
Module name:    gnumaint
Changes by:     Kaloian Doganov <kaloian>       09/04/20 07:32:58

Modified files:
        .              : gnufsd-psql 

Log message:
        Export more fields: user_level, short_description, full_description,
        entry_compiled_by, updated, and checkout_command.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnumaint/gnufsd-psql?cvsroot=womb&r1=1.4&r2=1.5

Patches:
Index: gnufsd-psql
===================================================================
RCS file: /sources/womb/gnumaint/gnufsd-psql,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- gnufsd-psql 19 Apr 2009 07:14:46 -0000      1.4
+++ gnufsd-psql 20 Apr 2009 07:32:58 -0000      1.5
@@ -1,15 +1,16 @@
 #!/usr/bin/env perl
-# $Id: gnufsd-psql,v 1.4 2009/04/19 07:14:46 kaloian Exp $
+# $Id: gnufsd-psql,v 1.5 2009/04/20 07:32:58 kaloian Exp $
 # Extract information about GNU packages from the Free Software
 # Directory's PostgreSQL database.
 #
 # Dependencies:
-#   perl (5.8.x), libdbd-pg-perl, libdate-calc-perl
+#   perl (5.8.x), libdbd-pg-perl, libdate-calc-perl, libipc-run-perl
 
 use warnings;
 use strict;
 use DBI;
 use Date::Calc qw ( check_date Delta_Days Add_Delta_YMD Today );
+use IPC::Run qw( run timeout );
 
 # Configuration:
 # ==============================
@@ -31,6 +32,12 @@
 my ($dbh, $sth_homepage, $sth_download_url, $sth_activity_status,
     $sth_categories, $sth_category);
 
+my %user_level_enum = (
+  0 => "unknown",
+  1 => "beginner",
+  2 => "intermediate",
+  3 => "advanced");
+
 exit (&main ());
 
 # Connect to the database and prepare all reusable statements in
@@ -83,8 +90,10 @@
 
   my $type = ref ($input);
   if ($type eq "SCALAR") {
+    return $input if ! defined $$input;
     $$input =~ s/^\s+//; # leading whitespace
     $$input =~ s/\s+$//; # trailing whitespace
+    $$input =~ s/\r//g; # delete all carriage returns
   }
   elsif ($type eq "HASH") {
     trim_whitespace (\$_) foreach (values %$input);
@@ -126,7 +135,10 @@
 # Fetch all GNU projects.
 sub projects()
 {
-  return all ("SELECT id, slug, name FROM directory_project
+  return all ("SELECT id, name, slug, user_level, short_description,
+                 full_description, entry_compiled_by, updated,
+                 checkout_command
+               FROM directory_project
               WHERE gnu IS TRUE  ORDER BY slug;");
 }
 
@@ -195,6 +207,13 @@
   return @ymd;
 }
 
+# Converts Date::Calc YMD to string.
+sub iso_date_to_str($) {
+  my ($date) = @_;
+  $date =~ s/-//g;
+  return $date;
+}
+
 # Fetch activity-status for a project.
 sub activity_status(\%)
 {
@@ -234,7 +253,7 @@
   return $result;
 }
 
-# Formats a category_id suitable for printing.
+# Formats a category_id to be suitable for dumping.
 sub format_category($)
 {
   my ($id) = @_;
@@ -270,6 +289,19 @@
   return sort (@result);
 }
 
+# Formats long muliparagraph text to be suitable for dumping.
+sub format_full_descr($)
+{
+  my ($descr) = @_;
+  my @cmd = "fmt";
+  my $out;
+  my $err;
+  run address@hidden, \$descr, \$out, \$err, timeout (20) or die "fmt: $?";
+  $out =~ s/\n/\n /g; # add space after every newline
+  $out =~ s/\s+$//; # trim trailing whitespace
+  return " " . $out;
+}
+
 # Dump a project to STDOUT.
 sub project(\%)
 {
@@ -288,11 +320,28 @@
   my $download_url = download_url (%$project);
   print "download-url: $download_url\n" if $download_url;
 
+  my $checkout_cmd = $project->{"checkout_command"};
+  if (defined $checkout_cmd and ! ($checkout_cmd eq '')) {
+    print "checkout-command: $checkout_cmd\n";
+  }
+
   my $activity_status = activity_status (%$project);
   print "activity-status: $activity_status\n";
 
+  my $user_level = $user_level_enum{$project->{"user_level"}};
+  print "user-level: $user_level\n";
+
   print "category: $_\n" foreach (categories (%$project));
 
+  print "entry-compiled-by: $project->{entry_compiled_by}\n";
+
+  my @updated = iso_date_to_str ($project->{"updated"});
+  print "updated: @updated\n";
+
+  my $full_descr = format_full_descr($project->{"full_description"});
+  print "description: $project->{short_description}\n";
+  print "$full_descr\n";
+
   print "\n";
 }
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]