]> jspc29.x-matter.uni-frankfurt.de Git - daqtools.git/commitdiff
add automatic regenerate of xml-db cache files if none exists.
authorJan Michel <j.michel@gsi.de>
Fri, 8 Feb 2019 14:48:26 +0000 (15:48 +0100)
committerJan Michel <j.michel@gsi.de>
Fri, 8 Feb 2019 14:48:26 +0000 (15:48 +0100)
Does not check for updates of the xml file because of performance.

xml-db/get.pl

index de68502e6f6690276b3941c83b3f43498ff69179..0cdcebbbb5b96c8a52136916a766a315a65ea650 100755 (executable)
@@ -43,6 +43,7 @@ if (defined $ENV{'QUERY_STRING'}) {
 
 
 
+my $RealBin = ".";
 
 foreach my $req (@request) {
   ###############################
@@ -54,15 +55,14 @@ foreach my $req (@request) {
     if ($server =~ /HTTPi/i) {
       $isbrowser = 1;
       ($entity,$netaddr,$name,$style) = split("-",$req);
-      $file = "htdocs/xml-db/cache/$entity.entity";
+      $RealBin = 'htdocs/xml-db';
     } else {
       #     use FindBin qw($RealBin);
-      my $RealBin = ".";
+      $RealBin = ".";
       $isbrowser = 1;
       ($entity,$netaddr,$name,$style) = split("-",$req);
-      $file = "$RealBin/cache/$entity.entity";
     }
-    $storefile = "/dev/shm/xmldb-".$req.".store";
+    $storefile = "/dev/shm/xmldb-$req.store";
   } else {
     #   use FindBin qw($RealBin);
     my $RealBin = ".";
@@ -73,12 +73,13 @@ foreach my $req (@request) {
               ) or pod2usage(2);
     pod2usage(1) if $help;
     $entity  = $ARGV[0] || "";
-    $file    = "$RealBin/cache/$ARGV[0].entity";
     $netaddr = $ARGV[1] || "";
     $name    = $ARGV[2] || "";
     $style   = $ARGV[3] || "";
   }
 
+  $file    = "$RealBin/cache/$entity.entity";
+  
   $style = "" unless $style;
   my $isInline = $style =~ /inline/i;
   my $isColor  = $style =~ /color/i;
@@ -92,8 +93,17 @@ foreach my $req (@request) {
   #### Check arguments for validity
   ###############################
 
-  die "Entity $file not found.\n" unless(-e $file) ;
-
+  unless(-e $file) {
+    my $xmlfile = "$RealBin/database/$entity.xml";
+    if(-e $xmlfile) {
+      system("./$RealBin/xml-db.pl");
+      die "Entity $entity not found. Please run xml-db.pl manually.\n" unless(-e $file);
+      }
+    else {
+      die "Entity $entity not found.\n";
+      }
+    }
+  
 
   # trim whitespace from netaddr
   $netaddr =~ s/^\s+|\s+$//g;
@@ -101,7 +111,7 @@ foreach my $req (@request) {
   # split off some spi chain, if any, after reading the $db, it is parsed
   ($netaddr, $spi_chains[0]) = split(':',$netaddr);
 
-  if ($netaddr=~ m/^0x([0-9a-fA-F]{4})$/) {
+  if ($netaddr=~ m/^0x([0-9a-fA-F]{1,4})$/) {
     $netaddr = hex($1);
   } elsif ($netaddr=~ m/^([0-9]{1,5})$/) {
     $netaddr = $1;