- Timestamp:
- May 3, 2010, 8:50:52 AM (16 years ago)
- Location:
- branches/simtest_nebulous_branches
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
pstamp/scripts/pstamp_get_image_job.pl (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/simtest_nebulous_branches
- Property svn:mergeinfo changed
-
branches/simtest_nebulous_branches/pstamp/scripts/pstamp_get_image_job.pl
r20220 r27840 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 die $errif $err;53 my_die( $err, $PS_EXIT_PROG_ERROR) 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 . ".mdc"; 56 if (! open(INPUT, "<$params_file") ) { 57 my_die("failed to open params file: $params_file", $PS_EXIT_UNKNOWN_ERROR); 58 } 64 59 65 my @path = split(/\//, $out_dir);60 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 66 61 67 my $nelem = @path; 68 if ($nelem < 2) { 69 die("$out_dir is not a valid output fileset directory"); 62 my $data = $mdcParser->parse(join "", (<INPUT>)) or my_die("failed to parse metadata config doc", $PS_EXIT_UNKNOWN_ERROR); 63 my $components = parse_md_list($data); 64 my $n = scalar @$components; 65 if ($n != 1) { 66 my_die("params file $params_file contains unexpected number of components: $n", $PS_EXIT_PROG_ERROR); 70 67 } 71 $fileset = $path[$nelem-1]; 72 $product = $path[$nelem-2]; 73 74 $_ = $out_dir; 75 my ($ds_dir) = m%(.*)/$product/$fileset%; 68 my $comp = $components->[0]; 69 my $stage = $comp->{stage}; 70 my $stage_id = $comp->{stage_id}; 71 my $component = $comp->{component}; 72 my $path_base = $comp->{path_base}; 73 my $camera = $comp->{camera}; 74 my $magicked = $comp->{magicked}; 76 75 77 76 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"; 77 print STDERR "\nstage is $stage\n"; 78 print STDERR "stage_id is $stage_id\n"; 79 print STDERR "path_base is $path_base\n"; 80 print STDERR "path_base is $path_base\n"; 81 print STDERR "CAMERA is $camera\n"; 82 print STDERR "magicked is " . (defined $magicked ? $magicked : "undefined") . "\n"; 82 83 } 83 84 84 85 if (!stat("$ds_dir/index.txt")) { 86 $err .= "Data Store not found at '$ds_dir'.\n" 85 if (!$camera or !$path_base or !$component or !$stage_id or !$stage) { 86 my_die("failed to parse params from: $params_file", $PS_EXIT_UNKNOWN_ERROR); 87 87 } 88 88 89 show_usage("Invalid product '$product'.") 90 unless defined stat("$ds_dir/$product/index.txt"); 89 my $out_dir = dirname($output_base); 90 my $prefix = basename($output_base) . "_"; 91 my $results_file = $output_base . ".bundle_results"; 91 92 92 if (! open(INPUT, "<$uri") ) { 93 die("failed to open file list: $uri"); 93 # Look for programs we need 94 my $missing_tools; 95 my $dist_bundle = can_run('dist_bundle.pl') or (warn "Can't find dist_bundle.pl" and $missing_tools = 1); 96 if ($missing_tools) { 97 warn("Can't find required tools."); 98 exit($PS_EXIT_CONFIG_ERROR); 94 99 } 95 100 96 my $reglist = "$out_dir/reglist"; 97 if (! open(REGLIST, ">$reglist$job_id") ) { 98 die("failed to open registration list: $reglist"); 101 { 102 my $command = "$dist_bundle --camera $camera --stage $stage --stage_id $stage_id"; 103 $command .= " --component $component"; 104 $command .= " --path_base $path_base --outdir $out_dir --results_file $results_file"; 105 $command .= " --prefix $prefix"; 106 $command .= " --magicked" if $magicked; 107 $command .= " --dbname $dbname" if $dbname; 108 $command .= " --verbose" if $verbose; 109 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 110 run(command => $command, verbose => $verbose); 111 unless ($success) { 112 my_die("Unable to perform $command: $error_code", $error_code >> 8); 113 } 99 114 } 100 115 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; 116 if (! open(RESULTS, "<$results_file")) { 117 my_die("failed to open bundle results file: $results_file", $PS_EXIT_UNKNOWN_ERROR); 118 } 109 119 110 ($pathname , my $filename) = resolvepath($pathname); 120 my $file_name; 121 my $bytes; 122 my $md5sum; 123 foreach my $line (<RESULTS>) { 124 chomp $line; 125 next if !$line; 126 next if $line =~ /bundleResults/; 127 last if $line =~ /END/; 111 128 112 if ($verbose) { 113 print STDERR "$pathname @fields\n"; 129 my ($tag, $type, $val) = split " ", $line; 130 if ($tag eq "name") { 131 $file_name = $val; 132 } elsif ($tag eq "bytes") { 133 $bytes = $val; 134 } elsif ($tag eq "md5sum") { 135 $md5sum = $val; 136 } else { 137 my_die("unexpected tag: $tag found in results file: $results_file", $PS_EXIT_PROG_ERROR); 114 138 } 139 } 115 140 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 } 141 my $reglist = "$out_dir/reglist$job_id"; 142 if (! open(REGLIST, ">$reglist") ) { 143 my_die("failed to open registration list: $reglist", $PS_EXIT_UNKNOWN_ERROR); 144 } 122 145 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 } 146 print REGLIST "$file_name|$bytes|$md5sum|tgz|\n"; 131 147 132 148 close(REGLIST); … … 134 150 exit 0; 135 151 136 sub resolvepath { 137 my $pathname = $_[0]; 152 sub my_die { 153 my $msg = shift; 154 my $rc = shift; 138 155 139 # use the basename of the unresolved file as the name of the file 140 # in order to avoid nebulous name mangled paths in the datastore 141 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); 156 print STDERR $msg; 157 exit $rc ? $rc : $PS_EXIT_UNKNOWN_ERROR; 153 158 } 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.
