Changeset 26151 for trunk/pstamp/scripts/pstamp_get_image_job.pl
- Timestamp:
- Nov 15, 2009, 1:53:33 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/pstamp/scripts/pstamp_get_image_job.pl (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pstamp/scripts/pstamp_get_image_job.pl
r20220 r26151 16 16 use File::Basename; 17 17 use Digest::MD5::File qw( file_md5_hex ); 18 use IPC::Cmd 0.36 qw( can_run run ); 18 19 19 use PS::IPP::Config qw($PS_EXIT_SUCCESS 20 $PS_EXIT_UNKNOWN_ERROR 21 $PS_EXIT_SYS_ERROR 22 $PS_EXIT_CONFIG_ERROR 23 $PS_EXIT_PROG_ERROR 24 $PS_EXIT_DATA_ERROR 25 $PS_EXIT_TIMEOUT_ERROR 26 metadataLookupStr 27 metadataLookupBool 28 caturi 29 ); 20 21 use PS::IPP::Config qw( :standard ); 22 30 23 my $product; 31 24 my $fileset; 32 25 33 my $uri; 34 my $out_dir; 26 my $output_base; 35 27 36 my $verbose = 1;28 my $verbose; 37 29 my $ipprc; 38 30 my $dbname; 31 my $dbserver; 39 32 my $job_id; 40 33 my $rownum; … … 47 40 'job_id=s' => \$job_id, 48 41 'rownum=s' => \$rownum, 49 'uri=s' => \$uri, 50 'out_dir=s' => \$out_dir, 42 'output_base=s' => \$output_base, 51 43 'dbname=s' => \$dbname, 44 'dbserver=s' => \$dbserver, 45 'verbose' => \$verbose, 52 46 ) or pod2usage(2); 53 47 … … 55 49 $err .= "--job_id is required\n" if (!$job_id); 56 50 $err .= "--rownum is required\n" if (!$rownum); 57 $err .= "--uri is required to specify the file list\n" if (!$uri); 58 $err .= "--out_dir is required to specify the output fileset\n" if (!$out_dir); 51 $err .= "--output_base is required to specify the output fileset\n" if (!$output_base); 59 52 60 53 die $err if $err; 61 54 62 # collapse any multiple slashes in output_dir 63 $out_dir = File::Spec->canonpath($out_dir); 55 my $params_file = $output_base . ".params"; 56 if (! open(INPUT, "<$params_file") ) { 57 die("failed to open params file: $params_file"); 58 } 64 59 65 my @path = split(/\//, $out_dir);60 my $params = join "", (<INPUT>); 66 61 67 my $nelem = @path; 68 if ($nelem < 2) { 69 die("$out_dir is not a valid output fileset directory"); 62 print STDERR "\nparams is $params\n"; 63 64 my ($stage, $stage_id, $component, $path_base, $camera) = split " ", $params; 65 if (!$camera or !$path_base or !$component or !$stage_id or !$stage) { 66 die "failed to parse params: $params"; 70 67 } 71 $fileset = $path[$nelem-1];72 $product = $path[$nelem-2];73 68 74 $_ = $out_dir; 75 my ($ds_dir) = m%(.*)/$product/$fileset%; 69 print STDERR "\nCAMERA is $camera\n"; 76 70 77 if ($verbose) { 78 print STDERR "DS root: $ds_dir\n"; 79 print STDERR "Product: $product\n"; 80 print STDERR "Fileset: $fileset\n"; 81 print STDERR "Filelist: $uri\n"; 71 my $out_dir = dirname($output_base); 72 my $prefix = basename($output_base); 73 my $results_file = $output_base . ".bundle_results"; 74 75 # Look for programs we need 76 my $missing_tools; 77 my $dist_bundle = can_run('dist_bundle.pl') or (warn "Can't find dist_bundle.pl" and $missing_tools = 1); 78 if ($missing_tools) { 79 warn("Can't find required tools."); 80 exit($PS_EXIT_CONFIG_ERROR); 82 81 } 83 82 84 83 85 if (!stat("$ds_dir/index.txt")) { 86 $err .= "Data Store not found at '$ds_dir'.\n" 84 { 85 my $command = "$dist_bundle --camera $camera --stage $stage --stage_id $stage_id --component $component"; 86 $command .= " --path_base $path_base --outdir $out_dir --results_file $results_file"; 87 $command .= " --prefix $prefix"; 88 # ignore magic for now 89 $command .= " --no_magic"; 90 91 $command .= " --dbname $dbname" if $dbname; 92 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 93 run(command => $command, verbose => $verbose); 94 unless ($success) { 95 die("Unable to perform $command: $error_code"); 96 } 87 97 } 88 98 89 show_usage("Invalid product '$product'.") 90 unless defined stat("$ds_dir/$product/index.txt"); 91 92 if (! open(INPUT, "<$uri") ) { 93 die("failed to open file list: $uri"); 99 if (! open(RESULTS, "<$results_file")) { 100 die("failed to open bundle results file: $results_file"); 94 101 } 95 102 96 my $reglist = "$out_dir/reglist"; 97 if (! open(REGLIST, ">$reglist$job_id") ) { 103 my $file_name; 104 my $bytes; 105 my $md5sum; 106 foreach my $line (<RESULTS>) { 107 chomp $line; 108 next if !$line; 109 next if $line =~ /bundleResults/; 110 last if $line =~ /END/; 111 112 my ($tag, $type, $val) = split " ", $line; 113 if ($tag eq "name") { 114 $file_name = $val; 115 } elsif ($tag eq "bytes") { 116 $bytes = $val; 117 } elsif ($tag eq "md5sum") { 118 $md5sum = $val; 119 } else { 120 die("unexpected tag: $tag found in results file: $results_file"); 121 } 122 } 123 124 my $reglist = "$out_dir/reglist$job_id"; 125 if (! open(REGLIST, ">$reglist") ) { 98 126 die("failed to open registration list: $reglist"); 99 127 } 100 128 101 my @files; 102 my $num = 0; 103 while (<INPUT>) { 104 chomp; 105 my @fields = split /\|/; 106 my $pathname = shift @fields; 107 my $filetype = shift @fields; 108 my $class_id = shift @fields; 109 110 ($pathname , my $filename) = resolvepath($pathname); 111 112 if ($verbose) { 113 print STDERR "$pathname @fields\n"; 114 } 115 116 $num++; 117 $filename = "${rownum}_${num}_$filename"; 118 my $dest_path = "$out_dir/$filename"; 119 if (! copy $pathname, "$dest_path" ) { 120 die("failed trying to copy $pathname to $out_dir"); 121 } 122 123 # XXX is pstamp always the right file type, if not where can we get the right one? 124 print REGLIST file_registration_line($filename, $dest_path, $filetype, $class_id); 125 126 foreach my $f (@fields) { 127 print REGLIST "$f|"; 128 } 129 print REGLIST "\n"; 130 } 129 print REGLIST "$file_name|$bytes|$md5sum|tgz|\n"; 131 130 132 131 close(REGLIST); 133 132 134 133 exit 0; 135 136 sub resolvepath {137 my $pathname = $_[0];138 139 # use the basename of the unresolved file as the name of the file140 # in order to avoid nebulous name mangled paths in the datastore141 my $file = basename($pathname);142 143 my $slash = index($pathname, "/");144 if ($slash != 0) {145 if (!$ipprc) {146 $ipprc = PS::IPP::Config->new();147 }148 $pathname = $ipprc->file_resolve($pathname);149 }150 151 152 return ($pathname, $file);153 }154 155 # XXX move this to a module so the code can be shared156 sub file_registration_line {157 my $filename = shift;158 my $path = shift;159 my $filetype = shift;160 my $chipname = shift;161 $chipname = $chipname ? "$chipname|" : "";162 163 if (-e $path) {164 my @finfo = stat($path);165 die "failed to stat $path" unless (@finfo); # XXX clean up166 my $bytes = $finfo[7];167 my $md5sum = file_md5_hex($path);168 169 return "$filename|$bytes|$md5sum|$filetype|$chipname";170 } else {171 die "$filename not found at $path";172 }173 }
Note:
See TracChangeset
for help on using the changeset viewer.
