view tools/bins_addtext @ 8:c28af937b9bd

log verbosity fix (entr)
author Peter Gervai <grin@grin.hu>
date Thu, 16 Oct 2008 00:06:40 +0200
parents a84c32f131df
children
line wrap: on
line source

#!/usr/bin/perl -w
#-*- mode: perl -*-

sub process_file {
   my ($dir, $file, $title, $desc) = @_;
   chomp $desc;
   #print "File: $file\n\tTitle: $title\n\tDesc: $desc\n";
   #print "\n$file\n";
   if($file eq "album") {
      ($longdesc, $shortdesc, $sample) = split /\|/, $desc;
      if($sample) {
         $cmd_str = "bins_edit -a -m --sample \"$sample\" $dir";
         print "$cmd_str\n";
         `$cmd_str`;
      }
      if($shortdesc) {
         $cmd_str = "bins_edit -a -m --shortdesc \"$shortdesc\" $dir";
         print "$cmd_str\n";
         `$cmd_str`;
      }
      if($longdesc) {
         $cmd_str = "bins_edit -a -m --longdesc \"$longdesc\" $dir";
         print "$cmd_str\n";
         `$cmd_str`;
      }
      #print "\t$cmd_str\n";
      $cmd_str = "bins_edit -a -m --title \"$title\" $dir";
      print "$cmd_str\n";
      `$cmd_str`;
   }
   else {
      $cmd_str = "bins_edit -m -t \"$title\" $dir/$file";
      print "$cmd_str\n";
      `$cmd_str`;
      #print "\t$cmd_str\n";
      $cmd_str = "bins_edit -m -d \"$desc\" $dir/$file";
      print "$cmd_str\n";
      `$cmd_str`;
      #print "\t$cmd_str\n\n";
   }
}

$inc_file = "include_images.txt";

for($i=0; $i<=$#ARGV; $i++) {
   $dir = $ARGV[$i];
   if($dir eq "-f" && $i<$#ARGV ) {
      $i++;
      $inc_file=$ARGV[$i];
      next;
   }

   open(FILE, "$dir/$inc_file") or die "Could not open: $dir/$inc_file";

   $title = "";
   $desc = "";
   $img_file = "album";
   $section = 1;

   while(<FILE>)
   {
      chomp;
      $line=$_;
      if(substr($line, 0 , 1) eq "") {
         next;
      }

      if(substr($line, 0 , 1) ne "#") {
         process_file($dir, $img_file, $title, $desc);
         $img_file = $line;
         $title = "";
         $desc = "";
         $section = 1;
      }
      else {
         if ($section == 1) {
            $title = substr($line, 1);
            $section++;
         }
         elsif ($section == 2) {
            $desc .= substr($line, 1)."\n";
         }
      }

   }

   if($section) {
      process_file($dir, $img_file, $title, $desc);
   }

   close(FILE) ;
}