418 else { |
418 else { |
419 return $tmpParam."/"; |
419 return $tmpParam."/"; |
420 } |
420 } |
421 } |
421 } |
422 |
422 |
423 # Make sure paths are as windows likes 'em |
|
424 # change '/' ==> '\\' and make sure last char is \\ |
|
425 sub UnFixPaths { |
|
426 my $tmpParam = shift; |
|
427 $tmpParam =~ s/\//\\/g; |
|
428 |
|
429 if( substr( $tmpParam, -1 ) eq "\\" ) { |
|
430 return $tmpParam; |
|
431 } |
|
432 else { |
|
433 return $tmpParam."\\"; |
|
434 } |
|
435 } |
|
436 |
|
437 # smarter handling of logging |
423 # smarter handling of logging |
438 sub printLog { |
424 sub printLog { |
439 foreach my $trace ( @_ ) { |
425 foreach my $trace ( @_ ) { |
440 if( $param_debug ) { |
426 if( $param_debug ) { |
441 # we should print traces for STDOUT as well |
427 # we should print traces for STDOUT as well |
610 print "Unable to access $wantedServer\nPlease select another network share.\n"; |
596 print "Unable to access $wantedServer\nPlease select another network share.\n"; |
611 } |
597 } |
612 } |
598 } |
613 my $wantedService = $serviceList[ ReturnMenuIndex( "Please select GRACE Service.", @serviceNameList)]; |
599 my $wantedService = $serviceList[ ReturnMenuIndex( "Please select GRACE Service.", @serviceNameList)]; |
614 printLog( "selected: $wantedServer.$wantedService - accessing.." ); |
600 printLog( "selected: $wantedServer.$wantedService - accessing.." ); |
615 local *GRACETEST2; |
601 local *GRACETEST2; |
616 if( opendir( GRACETEST2, $wantedServer.$wantedService ) ) { |
602 if( opendir( GRACETEST2, $wantedServer.$wantedService ) ) { |
617 printLog( "serviceconnection tested OK" ); |
603 printLog( "serviceconnection tested OK" ); |
618 $defaultServiceName = $wantedService |
604 $defaultServiceName = $wantedService |
619 } |
605 } |
620 else { |
606 else { |
850 |
836 |
851 # parse dl directory into $releaseDirectory |
837 # parse dl directory into $releaseDirectory |
852 $releaseLocationInServer = $data->{releaseDetails}->{releaseID}->{service}->{name} . "/"; |
838 $releaseLocationInServer = $data->{releaseDetails}->{releaseID}->{service}->{name} . "/"; |
853 $releaseLocationInServer .= $data->{releaseDetails}->{releaseID}->{product}->{name} ."/"; |
839 $releaseLocationInServer .= $data->{releaseDetails}->{releaseID}->{product}->{name} ."/"; |
854 $releaseLocationInServer .= $data->{releaseDetails}->{releaseID}->{release}->{name} ."/"; |
840 $releaseLocationInServer .= $data->{releaseDetails}->{releaseID}->{release}->{name} ."/"; |
855 local *DEPTEST; |
841 local *DEPTEST; |
856 |
842 |
857 # check if we can find this release from GRACE |
843 # check if we can find this release from GRACE |
858 if( $graceServer ) { |
844 if( $graceServer ) { |
859 if( -e $graceServer.$releaseLocationInServer."grace.txt" ) { |
845 if( -e $graceServer.$releaseLocationInServer."grace.txt" ) { |
860 printLog( "dl dir: $graceServer$releaseLocationInServer" ); |
846 printLog( "dl dir: $graceServer$releaseLocationInServer" ); |
881 # param: xml data handle |
867 # param: xml data handle |
882 sub GeneratePackageHash { |
868 sub GeneratePackageHash { |
883 my( $xmlDataHandle, $releaseInServer ) = @_; |
869 my( $xmlDataHandle, $releaseInServer ) = @_; |
884 my $finalState = 0; |
870 my $finalState = 0; |
885 printLog( "parse filenames to extract to packageHah" ); |
871 printLog( "parse filenames to extract to packageHah" ); |
886 |
872 no strict 'refs'; |
|
873 |
|
874 # Incase if we have only one package in the release to extract, then in the case |
|
875 # the Xml::Simple::XMLin is not creating keys inside $xmlDataHandle->{releaseFiles}->{package} |
|
876 # with package names. So to address it, the below part of code is done.. |
|
877 #### |
|
878 if(exists $xmlDataHandle->{releaseFiles}->{package}->{name}){ |
|
879 my $pkgName = $xmlDataHandle->{releaseFiles}->{package}->{name}; |
|
880 my $tmphash = $xmlDataHandle->{releaseFiles}->{package}; |
|
881 delete $tmphash->{name} ; |
|
882 delete $xmlDataHandle->{releaseFiles}->{package}; |
|
883 $xmlDataHandle->{releaseFiles}->{package}->{$pkgName} = $tmphash; |
|
884 } |
|
885 ##### |
|
886 |
887 # generate new hash of zips to DL for %packageHash |
887 # generate new hash of zips to DL for %packageHash |
888 # foreach my $key( sort { $xmlDataHandle{a}->{'state'} <=> $xmlDataHandle{b}->{'state'} } %{$xmlDataHandle->{releaseFiles}->{'package'} } ){ |
888 # foreach my $key( sort { $xmlDataHandle{a}->{'state'} <=> $xmlDataHandle{b}->{'state'} } %{$xmlDataHandle->{releaseFiles}->{'package'} } ){ |
889 foreach my $key( keys(%{$xmlDataHandle->{releaseFiles}->{package} } ) ) { |
889 foreach my $key( keys(%{$xmlDataHandle->{releaseFiles}->{package} } ) ) { |
890 printLog( "adding $key to packageHash" ); |
890 printLog( "adding $key to packageHash" ); |
891 ${packageHash}{$key}{path} = FixPaths( $releaseInServer ); |
891 ${packageHash}{$key}{path} = FixPaths( $releaseInServer ); |
1081 my $dependsOfServiceToRemove = FixPaths( $currentReleaseXmlHandle->{releaseDetails}->{dependsOf}->{service}->{name} ); |
1081 my $dependsOfServiceToRemove = FixPaths( $currentReleaseXmlHandle->{releaseDetails}->{dependsOf}->{service}->{name} ); |
1082 my $dependsOfProductToRemove = FixPaths( $currentReleaseXmlHandle->{releaseDetails}->{dependsOf}->{product}->{name} ); |
1082 my $dependsOfProductToRemove = FixPaths( $currentReleaseXmlHandle->{releaseDetails}->{dependsOf}->{product}->{name} ); |
1083 my $dependsOfReleaseToRemove = FixPaths( $currentReleaseXmlHandle->{releaseDetails}->{dependsOf}->{release}->{name} ); |
1083 my $dependsOfReleaseToRemove = FixPaths( $currentReleaseXmlHandle->{releaseDetails}->{dependsOf}->{release}->{name} ); |
1084 |
1084 |
1085 my $dependsOf = $dependsOfServiceToRemove.$dependsOfProductToRemove.$dependsOfReleaseToRemove; |
1085 my $dependsOf = $dependsOfServiceToRemove.$dependsOfProductToRemove.$dependsOfReleaseToRemove; |
1086 local *TMPTEST; |
1086 local *TMPTEST; |
1087 |
1087 |
1088 # find out where the release came from |
1088 # find out where the release came from |
1089 if( $param_release_path ) { |
1089 if( $param_release_path ) { |
1090 # best guess is $param_release_path\..\..\..\$dependsOf even though it is not very common situation |
1090 # best guess is $param_release_path\..\..\..\$dependsOf even though it is not very common situation |
1091 my $dependencyPath = FixPaths( $param_release_path ) . "../../../" . FixPaths( $dependsOf ); |
1091 my $dependencyPath = FixPaths( $param_release_path ) . "../../../" . FixPaths( $dependsOf ); |
1127 foreach my $finalZip( @finalZipList ) { |
1127 foreach my $finalZip( @finalZipList ) { |
1128 # path contains ../../../ so wont match ==> |
1128 # path contains ../../../ so wont match ==> |
1129 # if( $finalZip->{filename} eq $zips and |
1129 # if( $finalZip->{filename} eq $zips and |
1130 # $finalZip->{path} eq %packageHash->{$zips}->{'path'} ) { |
1130 # $finalZip->{path} eq %packageHash->{$zips}->{'path'} ) { |
1131 if( $finalZip->{filename} eq $zips ) { |
1131 if( $finalZip->{filename} eq $zips ) { |
1132 printLog( "removing $finalZip->{path} $finalZip->{filename} from dl list" ); |
1132 printLog( "removing $finalZip->{path}/$finalZip->{filename} from dl list" ); |
1133 $finalZip->{default} = "false"; |
1133 $finalZip->{default} = "false"; |
1134 } |
1134 } |
1135 } |
1135 } |
1136 } |
1136 } |
1137 } |
1137 } |
1257 } |
1257 } |
1258 elsif( $file->{extract} eq 'double' ) { |
1258 elsif( $file->{extract} eq 'double' ) { |
1259 # unzip double zipped zips to $tmpDlDir |
1259 # unzip double zipped zips to $tmpDlDir |
1260 # there shouldnt be much of these anymore |
1260 # there shouldnt be much of these anymore |
1261 printLog( "parent: double zipped - unzip to $tmpDlDir" ); |
1261 printLog( "parent: double zipped - unzip to $tmpDlDir" ); |
1262 my $extrCmd = "7za x -y \""; |
1262 my $extrCmd = q{7za x -y "}; |
1263 $extrCmd .= $file->{path} . $file->{filename}; |
1263 $extrCmd .= $file->{path} . $file->{filename}; |
1264 $extrCmd .= "\" -o" . $tmpDlDir; |
1264 $extrCmd .= q{" -o} . $tmpDlDir; |
1265 $extrCmd .= " > NUL"; |
1265 if ( $^O =~ /linux/i){ |
|
1266 $extrCmd .= " > /dev/null"; |
|
1267 }else{ |
|
1268 $extrCmd .= " > NUL"; |
|
1269 } |
1266 print "system: $extrCmd\n" if( $param_print_only ); |
1270 print "system: $extrCmd\n" if( $param_print_only ); |
1267 printLog( "parent: system: $extrCmd" );; |
1271 printLog( "parent: system: $extrCmd" );; |
1268 system( $extrCmd ) if( !$param_print_only ); |
1272 system( $extrCmd ) if( !$param_print_only ); |
1269 if( $? ) { |
1273 if( $? ) { |
1270 printLog( "Problem processing $file->{path} $file->{filename}: $?" );; |
1274 printLog( "Problem processing $file->{path} $file->{filename}: $?" );; |
1311 next if $file =~ /^\.[\.]?$/; |
1315 next if $file =~ /^\.[\.]?$/; |
1312 $somethingToCopy = 1; |
1316 $somethingToCopy = 1; |
1313 } |
1317 } |
1314 |
1318 |
1315 if( $somethingToCopy ) { |
1319 if( $somethingToCopy ) { |
1316 printLog( "move everything from $tmpDlDir to $tmpDir > NUL" ); |
1320 printLog( "move everything from $tmpDlDir to $tmpDir" ); |
1317 my $moveCmd = "move $tmpDlDir\\*.* $tmpDir > NUL"; |
1321 opendir( DLTEMP , $tmpDlDir ); |
1318 printLog( "running moveCmd: $moveCmd" ); |
1322 for (grep( !/^\.\.?$/, readdir(DLTEMP))){ |
1319 system( $moveCmd ) if( !$param_print_only ); |
1323 move("$tmpDlDir/$_", $tmpDir) or die("$tmpDlDir/$_ move failed :$!"); |
1320 # move( "$tmpDlDir/*.*", "$tmpDir" ) or die( "move failed: $!" ); |
1324 } |
|
1325 closedir( DLTEMP ); |
1321 } |
1326 } |
1322 |
1327 |
1323 if( $returnValue == 0 ) { |
1328 if( $returnValue == 0 ) { |
1324 print "done\n"; |
1329 print "done\n"; |
1325 printLog( "done" ); |
1330 printLog( "done" ); |
1329 printLog( "done, but errors occured" ); |
1334 printLog( "done, but errors occured" ); |
1330 } |
1335 } |
1331 } |
1336 } |
1332 |
1337 |
1333 # current forking mechanism is leaving last package(s) to $tmpDir |
1338 # current forking mechanism is leaving last package(s) to $tmpDir |
1334 UnzipFromTempToEnv( ); |
1339 opendir(TEMPDIR, $tmpDir); |
|
1340 UnzipFromTempToEnv() if(scalar(grep( !/^\.\.?$/, readdir(TEMPDIR))) > 0); |
|
1341 closedir(TEMPDIR); |
1335 |
1342 |
1336 if( -e FixPaths( getcwd )."currentRelease.xml" ) { |
1343 if( -e FixPaths( getcwd )."currentRelease.xml" ) { |
1337 unlink( FixPaths( getcwd )."currentRelease.xml" ) if( ! $param_print_only ); |
1344 unlink( FixPaths( getcwd )."currentRelease.xml" ) if( ! $param_print_only ); |
1338 } |
1345 } |
1339 # copy the xml into $extractDir\buildData from $serverPath.$serviceName.$metaDataFile |
1346 # copy the xml into $extractDir\buildData from $serverPath.$serviceName.$metaDataFile |
1351 } |
1358 } |
1352 |
1359 |
1353 sub UnzipFromTempToEnv { |
1360 sub UnzipFromTempToEnv { |
1354 # extract from temp to extractDir |
1361 # extract from temp to extractDir |
1355 printLog( "child: unzip from temp" ); |
1362 printLog( "child: unzip from temp" ); |
1356 my $finalUnzipCmd = "7za x -y \"".UnFixPaths( $tmpDir )."\\*.zip\" -o\"".UnFixPaths( getcwd )."\""; |
1363 my $finalUnzipCmd = qq{7za x -y "$tmpDir/*.zip" -o"}.getcwd.q{"}; |
1357 $finalUnzipCmd .= " > NUL"; |
1364 if ( $^O =~ /linux/i){ |
|
1365 $finalUnzipCmd .= " > /dev/null"; |
|
1366 }else{ |
|
1367 $finalUnzipCmd .= " > NUL"; |
|
1368 } |
|
1369 |
1358 print "system: $finalUnzipCmd\n" if( $param_print_only ); |
1370 print "system: $finalUnzipCmd\n" if( $param_print_only ); |
1359 printLog( "child: system: $finalUnzipCmd" ); |
1371 printLog( "child: system: $finalUnzipCmd" ); |
1360 system( $finalUnzipCmd ) if( !$param_print_only ); |
1372 system( $finalUnzipCmd ) if( !$param_print_only ); |
1361 # if( $? ) { |
1373 # if( $? ) { |
1362 # $returnValue = $?; |
1374 # $returnValue = $?; |
1363 # HandleZipError( $file->{path} . $file->{filename}, $? ); |
1375 # HandleZipError( $file->{path} . $file->{filename}, $? ); |
1364 # } |
1376 # } |
1365 |
1377 |
1366 # empty temp dir |
1378 # empty temp dir |
1367 printLog( "child: empty temp dir" ); |
1379 printLog( "child: empty temp dir" ); |
1368 $tmpDir =~ s/\//\\/g; |
|
1369 printLog( "child: unlink: $tmpDir" ); |
1380 printLog( "child: unlink: $tmpDir" ); |
1370 |
1381 |
1371 # dont handle errors - temp might be empty as well! |
1382 # dont handle errors - temp might be empty as well! |
1372 opendir( TEMPDIR, $tmpDir ); |
1383 opendir( TEMPDIR, $tmpDir ); |
1373 my @zipFiles = grep /zip/, readdir TEMPDIR; |
1384 my @zipFiles = grep /zip/, readdir TEMPDIR; |