no message
[mir.git] / dbscripts / pg_imageimport.pl
1 #!/usr/local/bin/perl -w
2 use Pg;
3
4 if (!defined($ARGV[0])) {
5         print "Usage: $0 name_of_filelist_file\n";
6         exit 1;
7 }
8
9 $dump="$ARGV[0]";
10
11 my $conn = Pg::connectdb("dbname=indy user=indy host=192.168.4.8");
12 ( PGRES_CONNECTION_OK eq $conn->status )
13     and print "Pg::connectdb ........... ok\n"
14     or  die   "Pg::connectdb ........... not ok: ", $conn->errorMessage;
15
16
17 open(DUMP,"$dump") || die "can't open dump file $dump";
18
19 $basedir="";
20
21 while(<DUMP>) {
22         chomp;
23         next if (/^$/ || /^\s*$/);
24
25                 # exception liste einlesen...
26                                 $filename=$basedir.$_;
27                                 $comment=$filename;
28                                 $titel="unklassifiziert";
29                                 $ort="unklassifiziert"; 
30                         
31                                 $_ = `/usr/X11R6/bin/identify $filename`;
32                                 /(\d+)x(\d+)/;
33                                 $img_width=$1;
34                                 $img_height=$2;
35                                 
36                                 $layout=0;                                              # undefined
37                                 if ( $img_width>$img_height ) {$layout=1;}              # querformat
38                                 if ( $img_width<$img_height ) {$layout=2;}              # hochformat
39                                 if ( $img_width==$img_height) {$layout=3;}    # quadratisch
40
41                                 # hier insert:
42                                 print "making icon: $filename \n";
43                                 `cp $filename /tmp/iconblob.jpg`;
44                                 `/usr/X11R6/bin/mogrify -geometry 120x120 /tmp/iconblob.jpg`;
45                                 
46                                 print "trying to insert: $filename \n";
47                                 
48                                 $conn->exec("BEGIN");
49                                 $oid= $conn->lo_import("$filename");
50                                 print $conn->errorMessage."\n";
51                                 print "trying to insert icon\n";
52                                 $ioid= $conn->lo_import("/tmp/iconblob.jpg");
53                                 print $conn->errorMessage."\n";
54                                 $sql="INSERT INTO images (title,date,place,author,to_img_layout,to_img_type,is_classified,to_media_folder,to_img_color,comment,webdb_create,img_width,img_height,image_data,icon_data) ".
55                                          "VALUES ('".$titel."','20010109','".$ort.
56                                          "','huh','".$layout."','1','0','3','2','".$comment."',now(),'".$img_width."','".$img_height.
57                                          "','".$oid."','".$ioid."')";
58                                 print $sql."\n";
59                                 $conn->exec( $sql );
60                                 print $conn->errorMessage."\n";
61                                 $conn->exec("END");
62         
63                         
64
65 }
66 # end of while