view tools/bins_addtext @ 2:c44d020e5f8a 1.1.29-extended

Importing extended patched version from http://www.uli-eckhardt.de/bins/index.en.html
author Peter Gervai <grin@grin.hu>
date Wed, 15 Oct 2008 23:31:54 +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) ;
}