buildframework/helium/tools/preparation/getenv.pl
changeset 587 85df38eb4012
parent 179 d8ac696cc51f
child 588 c7c26511138f
equal deleted inserted replaced
217:0f5e3a7fb6af 587:85df38eb4012
    15 #Contributors:
    15 #Contributors:
    16 #
    16 #
    17 #Description: Cleaned version.
    17 #Description: Cleaned version.
    18 #============================================================================
    18 #============================================================================
    19 
    19 
    20 use strict;                 # strict naming rules
    20 use strict;         # strict naming rules
    21 use Cwd;                        # figuring out directories
    21 use Cwd;            # figuring out directories
    22 use Data::Dumper;       # debugging purposes
    22 use Data::Dumper;   # debugging purposes
    23 use XML::Simple;        # for using xml parser
    23 use XML::Simple;    # for using xml parser
    24 use File::Copy;         # for copying files
    24 use File::Copy;     # for copying files
    25 use SOAP::Lite;         # SOAP interface for s60build server
    25 use Getopt::Long;   # parameter handling
    26 use Getopt::Long;       # parameter handling
       
    27 Getopt::Long::Configure( "bundling_override","ignore_case_always" );
    26 Getopt::Long::Configure( "bundling_override","ignore_case_always" );
    28 # uncomment to get SOAP debug traces
    27 use File::Temp qw/ tempdir /; # for creating unique temp directories
    29 # use SOAP::Lite +trace => 'debug';
    28 
       
    29 # uncomment to get temp dir debug traces
       
    30 $File::Temp::DEBUG = 1;
    30 
    31 
    31 # variables for commandline params
    32 # variables for commandline params
    32 my( $param_help,                    # print help
    33 my( $param_help,          # print help
    33         $param_server,              # manually select server
    34     $param_server,        # manually select server
    34         $param_release_path,    # where are the releases located in the server
    35     $param_release_path,  # where are the releases located in the server
    35         $param_debug,                   # parameter for controlling extra debug prints
    36     $param_debug,         # parameter for controlling extra debug prints
    36         $param_latest,              # just grab the latest build (requires product name)
    37     $param_latest,        # just grab the latest build (requires product name)
    37         $param_keepgoing,           # continue even if dependency is missing
    38     $param_keepgoing,     # continue even if dependency is missing
    38         $param_print_only,      # do nothing but print system calls
    39     $param_print_only,    # do nothing but print system calls
    39         $param_skipITD,             # do not extract internal, testsources and documentation
    40     $param_skipITD,       # do not extract internal, testsources and documentation
    40         $param_emuenv,              # extract only emulator environment
    41     $param_emuenv,        # extract only emulator environment
    41         $param_start_directly,# starts extracting directly without waiting user acceptance
    42     $param_start_directly,# starts extracting directly without waiting user acceptance
    42         $param_product,             # manually insert product name
    43     $param_product,       # manually insert product name
    43         $param_skip_deps,           # do not extract dependencies
    44     $param_skip_deps,     # do not extract dependencies
    44         $param_grace,                   # do not check for grace access
    45     $param_grace,         # do not check for grace access
    45         $param_no_soap,             # dont use soap connection
    46     @param_exclude,       # exclude list
    46         @param_exclude,             # exclude list
    47     @param_include,       # include list
    47         @param_include );           # include list
    48     @force_include,       # force include list
       
    49     $param_all );         # extract all zips
    48 
    50 
    49 # read commandline parameters
    51 # read commandline parameters
    50 my $result = GetOptions('help'          => \$param_help,                        # print help
    52 my $result = GetOptions('help'      => \$param_help,            # print help
    51                                                 'h'                 => \$param_help,                        # print help
    53                         'h'         => \$param_help,            # print help
    52                                                 'latest'        => \$param_latest,                  # just grab the latest build (requires product name)
    54                         'latest'    => \$param_latest,          # just grab the latest build (requires product name)
    53                                                 'server=s'  => \$param_server,                  # manually select server
    55                         'server=s'  => \$param_server,          # manually select server
    54                                                 'path=s'        => \$param_release_path,        # extract this release directly
    56                         'path=s'    => \$param_release_path,    # extract this release directly
    55                                                 'verbose'       => \$param_debug,                       # verbose debug print
    57                         'verbose'   => \$param_debug,           # verbose debug print
    56                                                 'k'                 => \$param_keepgoing,               # continue even if there is any problems
    58                         'k'         => \$param_keepgoing,       # continue even if there is any problems
    57                                                 'p'                 => \$param_print_only,          # do nothing but print system calls
    59                         'p'         => \$param_print_only,      # do nothing but print system calls
    58                                                 'skipitd'       => \$param_skipITD,                 # Deprecated: do not extract internal, testsources and documentation
    60                         'skipitd'   => \$param_skipITD,         # Deprecated: do not extract internal, testsources and documentation
    59                                                 'emu'               => \$param_emuenv,                  # Deprecated: extract only emulator environment
    61                         'emu'       => \$param_emuenv,          # Deprecated: extract only emulator environment
    60                                                 'start'         => \$param_start_directly,  # starts extracting directly without waiting user acceptance
    62                         'start'     => \$param_start_directly,  # starts extracting directly without waiting user acceptance
    61                                                 'product=s' => \$param_product,                 # manually insert product name
    63                         'product=s' => \$param_product,         # manually insert product name
    62                                                 'x=s'               => \@param_exclude,                 # filer list for excluding zips
    64                         'x=s'       => \@param_exclude,         # filer list for excluding zips
    63                                                 'exclude=s' => \@param_exclude,                 # filer list for excluding zips
    65                         'exclude=s' => \@param_exclude,         # filer list for excluding zips
    64                                                 'i=s'               => \@param_include,                 # filer list for including zips
    66                         'i=s'       => \@param_include,         # filer list for including zips
    65                                                 'include=s' => \@param_include,                 # filer list for including zips
    67                         'include=s' => \@param_include,         # filer list for including zips
    66                                                 'nodeps'        => \$param_skip_deps,               # do not extract dependencies
    68                         'f=s'       => \@force_include,         # filer list for including zips if default tag is false
    67                                                 'grace'         => \$param_grace,                       # try to DL from GRACE
    69                         'force=s'   => \@force_include,         # filer list for including zips if default tag is false
    68                                                 'nosoap'        => \$param_no_soap );               # dont try using SOAP for s60builds server
    70                         'all'       => \$param_all,             # extract all zip whether default tag is true or false
       
    71                         'nodeps'    => \$param_skip_deps,       # do not extract dependencies
       
    72                         'grace'     => \$param_grace);          # try to DL from GRACE
    69 
    73 
    70 # enums for error situations
    74 # enums for error situations
    71 my $warning = 1;
    75 my $warning = 1;
    72 my $promptUser = 2;
    76 my $promptUser = 2;
    73 my $dependencyMissing = 3;
    77 my $dependencyMissing = 3;
    74 my $cannotContinue = 4;
    78 my $cannotContinue = 4;
    75 
    79 
    76 # common global variables
    80 # common global variables
    77 my $metaDataXml;                    # path to metadata file
    81 my $metaDataXml;            # path to metadata file
    78 my $currentReleaseXml;      # path to currentRelease.xml if exists
    82 my $currentReleaseXml;      # path to currentRelease.xml if exists
    79 my $pathToReleaseFolder;    # path to server that has releases
    83 my $pathToReleaseFolder;    # path to server that has releases
    80 my $defaultServiceName;     # default name for service (s60rnd)
    84 my $defaultServiceName;     # default name for service (s60rnd)
    81 my $pathToUnzip;                    # path to unzip tool
    85 my $pathToUnzip;            # path to unzip tool
    82 my $tmpDlDir;                           # path to temp dir where we'll DL packages to
    86 my $tmpDlDir;               # path to temp dir where we'll DL packages to
    83 my $tmpDir;                             # path to temp dir where we extract packages from
    87 my $tmpDir;                 # path to temp dir where we extract packages from
    84 my $returnValue;                    # holds the error codes coming from 7-zip
    88 my $returnValue;            # holds the error codes coming from 7-zip
    85 my $graceServer;                    # path to local grace server if accessible
    89 my $graceServer;            # path to local grace server if accessible
    86 my $logFile;                            # log file for troubleshooting
    90 my $logFile;                # log file for troubleshooting
    87 my %packageHash;                    # hash containing zips to extract
    91 my %packageHash;            # hash containing zips to extract
    88 my @finalZipList;                   # contains final list of files to unzip
    92 my @finalZipList;           # contains final list of files to unzip
    89 my $getEnvVersion;              # version of this getenv script
    93 my $getEnvVersion;          # version of this getenv script
    90 my $soapConnection;             # holding boolean value wheter we have connection s60builds server
       
    91 my $soapSessionID;              # holds the session ID received from SOAP server
       
    92 my $defaultPathToServer;    # default value for the server
    94 my $defaultPathToServer;    # default value for the server
    93 my $soapServiceURL = undef;
       
    94 
    95 
    95 # list of GRACE samba shares - must match to @graceNameList
    96 # list of GRACE samba shares - must match to @graceNameList
    96 my @graceList = ();
    97 my @hydraList = ();
    97 # must match to @graceList
    98 # must match to @graceList
    98 my @graceNameList = ();
    99 my @hydraNameList = ();
    99 
   100 
   100 #these 2 lists need to match                    
   101 #these 2 lists need to match                    
   101 my @serviceList = ();
   102 my @serviceList = ();
   102 my @serviceNameList = ();
   103 my @serviceNameList = ();
   103 
   104 
   107 $defaultServiceName = undef;
   108 $defaultServiceName = undef;
   108 #$logFile = getcwd."/getenv.log";
   109 #$logFile = getcwd."/getenv.log";
   109 $pathToReleaseFolder = undef;
   110 $pathToReleaseFolder = undef;
   110 $defaultPathToServer = undef;
   111 $defaultPathToServer = undef;
   111 $pathToUnzip = "7za";
   112 $pathToUnzip = "7za";
   112 $getEnvVersion = "2.4.0";
   113 $getEnvVersion = "2.4.9";
   113 
   114 
   114 # first open/create log file
   115 # first open/create log file
   115 #open( LOGFILE, ">> $logFile" ) or handleError( "cant create log file: $!", $warning );
   116 #open( LOGFILE, ">> $logFile" ) or handleError( "cant create log file: $!", $warning );
   116 eval {
   117 eval {
   117   open( LOGFILE, ">> getcwd.'/output/logs/getenv.log'" );
   118   open( LOGFILE, ">> getcwd.'/output/logs/getenv.log'" );
   134 }
   135 }
   135 ValidateInputs( );
   136 ValidateInputs( );
   136 printLog( "Following release we will extract: $metaDataXml" );
   137 printLog( "Following release we will extract: $metaDataXml" );
   137 PrintFinalWarning( );
   138 PrintFinalWarning( );
   138 DownloadRelease( );
   139 DownloadRelease( );
   139 # if we have SOAP connection we should end it
       
   140 if( $soapConnection ) {
       
   141     my $sessionInfo = EndSoapConnection( );
       
   142     print "\n\n".$sessionInfo->{'Info'}."\n\n" if( $sessionInfo->{'Info'} );
       
   143 }
       
   144 
   140 
   145 exit 0;
   141 exit 0;
   146 
   142 
   147 
   143 
   148 sub ValidateInputs {
   144 sub ValidateInputs {
   149     print_help( ) if ( $param_help );
   145   print_help( ) if ( $param_help );
   150     
   146 
   151     # try to get version info from s60builds SOAP server
   147   if( @param_exclude and @param_include ) {
   152     my $versionInfoFromServer = GetSoapVersion( ) if( !$param_no_soap );
   148     HandleError( "you cant specify include and exclude lists at the same time!", $cannotContinue );
   153     if( $versionInfoFromServer ) {
   149   }
   154         # we have access to SOAP server
   150 
   155         printLog( "SOAP: access OK" );
   151   # checking wheter we are in root of the substituted drive (if -start param is not specified)
   156         $soapConnection = 1;
   152   if( ! $param_start_directly and
   157         
   153       ! getcwd =~ /[a-zA-Z]:\// and
   158         # lets not start soap if prompt only is defined
   154         $param_keepgoing ) {
   159         $soapConnection = 0 if $param_print_only;
   155     HandleError( "You should run getenv only in root of the substituted drive\nYou can use -k as keep going parameter if you think it is ok to proceed", $cannotContinue );
   160         
   156   }
   161         printLog( "SOAP: latest OK version: ".$versionInfoFromServer->{'LatestOK'}->{'Version'} );
   157 
   162         printLog( "SOAP: latest OK date: ".$versionInfoFromServer->{'LatestOK'}->{'Date'} );
   158   # ok we are in root. Is the drive empty?
   163         printLog( "SOAP: latest version: ".$versionInfoFromServer->{'Latest'}->{'Version'} );
   159   my $xmlFile = 0;
   164         printLog( "SOAP: latest date: ".$versionInfoFromServer->{'Latest'}->{'Date'} );
   160   my $driveEmpty = 1;
   165         
   161   
   166         # compare version nmbrs and prompt user if outdated getenv
   162   opendir( ROOT, "/" ) or HandleError( "cant read root dir: $!", $warning );
   167         if( $getEnvVersion < $versionInfoFromServer->{'LatestOK'}->{'Version'} ) {
   163   my @filesFound = readdir( ROOT );
   168             HandleError( "Your getenv is outdated and can not be usedanymore\nPlease get newer from the server.", $cannotContinue );
   164   closedir( ROOT );
   169         }       
   165   foreach my $file( @filesFound ) {
       
   166       next if $file =~ /^\.[\.]?$/;
       
   167       next if $file =~ /getenv/;
       
   168       $xmlFile = 1 if $file =~ /.*metadata.*\.xml/;
       
   169       $xmlFile = 1 if $file =~ /currentRelease\.xml/;
       
   170       $driveEmpty = 0;
       
   171   }
       
   172   
       
   173   printLog( "xml files: $xmlFile" );
       
   174   printLog( "drive empty: $driveEmpty" );
       
   175 
       
   176   # if drive is not empty and no xmls found ==> print warning (if -start param not specified)
       
   177   if( ! $param_start_directly and ! $xmlFile and ! $driveEmpty ) {
       
   178       HandleError( "The drive you are about to extract environment is not empty!\nHit CTRL-C to break now or <enter> to continue", $promptUser );
       
   179   }
       
   180 
       
   181   # if there is valid metadata.xml in root, params like path or latest doesn't make any sense
       
   182   if( $xmlFile ) {
       
   183       foreach my $file( @filesFound ) {
       
   184           if( $file =~ /.*metadata(_(\d*))?.xml$/i ) {
       
   185               print "metadata file found!\n";
       
   186               if( ValidateXmlFile( getcwd.$file ) ) {
       
   187                   $metaDataXml = getcwd.$file;
       
   188                   last;
       
   189               }
       
   190           }
       
   191       }
       
   192   }
       
   193 
       
   194   if( $metaDataXml ) {
       
   195     if( $param_latest or $param_release_path ) {
       
   196           print "It doesnt make sense to use 'path' or 'latest' parameter while having metadata.xml in root!\n\n";
       
   197           print_help( );
       
   198           exit 0;
       
   199     }
       
   200 
       
   201   # we should ask correct grace share if xmlfile !server !start       
       
   202     if( !$param_server and ! $param_start_directly ) {
       
   203       print "For your convenience it is recommended to use HYDRA samba share close to you.\n";
       
   204       # prompt user wheter he wants to use GRACE
       
   205       my $networkAccessVerified = 0;
       
   206       while( $networkAccessVerified eq 0 ) {
       
   207         my $wantedServer = FixPaths( $hydraList[ ReturnMenuIndex( "Please select share closest to you", @hydraNameList ) ] );
       
   208     
       
   209         if( $wantedServer eq FixPaths( $hydraList[0] ) ) {
       
   210               HandleError( "Please notice that access to $hydraList[0] will be removed from wk50 onwards. Now would be perfect time to get yourself a GRACE access.", $promptUser );
       
   211         }
       
   212       
       
   213         printLog( "selected: $wantedServer - accessing.." );
       
   214         if( opendir( GRACETEST, $wantedServer ) ) {
       
   215           printLog( "connection tested OK" );
       
   216           $networkAccessVerified = 1;
       
   217           $pathToReleaseFolder = $wantedServer;
       
   218         }
       
   219         else {
       
   220               print "Unable to access $wantedServer\nPlease select another network share.\n";
       
   221         }
       
   222       }
       
   223     }
       
   224           
       
   225           # in case we have metadata in \ and -start defined, look grace automatically
       
   226     elsif( !$param_server and $param_start_directly ) {
       
   227               $pathToReleaseFolder = FindGraceServer( );
       
   228     }
       
   229   }
       
   230     
       
   231   # ToDo: if there is not metadata.xml in root check if we have already env. Possibly update?
       
   232   
       
   233   # is 'path' parameter is used, find out (wheter there exists) valid metadata.xml
       
   234   if( $param_release_path ) {
       
   235     if( $param_latest or $param_product ) {
       
   236       print "It doesnt make sense to use 'path' or 'latest' parameter while having metadata.xml in root!\n\n";
       
   237       print_help( );
       
   238       exit 0;
       
   239     }
       
   240     $metaDataXml = FixPaths( $param_release_path );
       
   241     $metaDataXml .= SearchValidXml( $metaDataXml );
       
   242     printLog( "setting metadata: $metaDataXml" );
       
   243   }
       
   244   
       
   245   # handle server parameter
       
   246   # simply just verify accessablility and fix path
       
   247   if( $param_server ) {
       
   248       $pathToReleaseFolder = FixPaths( $param_server );
       
   249       opendir( OPENTEST, $pathToReleaseFolder ) or HandleError( "Unable to access given server path: $pathToReleaseFolder\n$!", $cannotContinue );
       
   250       closedir( OPENTEST );
       
   251   }
       
   252   
       
   253   # param_latest is used to just get latest release - requires product
       
   254   if( $param_latest ) {
       
   255     if( $param_product ) {
       
   256       $param_product = FixPaths( $param_product );
       
   257       
       
   258       # once the network share is unavailable then tries to find grace share
       
   259       $pathToReleaseFolder = FindGraceServer( );
       
   260       
       
   261       opendir( RELDIR, $pathToReleaseFolder.$defaultServiceName.$param_product ) or die "unable to open $pathToReleaseFolder$defaultServiceName$param_product\n$!";
       
   262       # scan all xml files to @files_found
       
   263 # salmarko starts
       
   264       my @files_found = grep { /^pf_|^S60_|^dfs_/i } readdir RELDIR;
       
   265 # salmarko ends
       
   266       close RELDIR;
       
   267 
       
   268       if( @files_found ) {
       
   269           foreach( reverse sort ( @files_found ) ) {
       
   270               # we only want to get the last dir name..
       
   271               s/.*\///i;
       
   272               my $productToDl = $pathToReleaseFolder.$defaultServiceName.$param_product;
       
   273               $productToDl .= FixPaths( $_ );
       
   274               print "Searching metadata.xml files from $productToDl\n" if $param_debug;
       
   275 
       
   276               $metaDataXml = SearchValidXml( $productToDl ) ;
       
   277               if( $metaDataXml ) {
       
   278                   $metaDataXml = $productToDl.$metaDataXml;
       
   279                   printLog( "selected xml: $metaDataXml" );
       
   280                   last;
       
   281               }
       
   282           }
       
   283       }
       
   284       else {
       
   285           HandleError( "cannot find releases from $pathToReleaseFolder$defaultServiceName$param_product", $cannotContinue );
       
   286       }
   170     }
   287     }
   171     else {
   288     else {
   172         printLog( "SOAP: we dont have SOAP access" );
   289         die "If you specify -latest parameter you have to define -product also!\n";
   173         $soapConnection = 0;
   290     }
   174     }
   291   }
   175 
   292   
   176     if( @param_exclude and @param_include ) {
   293   # use wizard to find out what to DL
   177         HandleError( "you cant specify include and exclude lists at the same time!", $cannotContinue );
   294   if( ! $metaDataXml ) {
   178     }
   295       printLog( "Not enought valid inputs provided - running wizard..." );
   179 
   296       RunWizard( );
   180     # checking wheter we are in root of the substituted drive (if -start param is not specified)
   297   }
   181     if( ! $param_start_directly and
   298   
   182             !   getcwd =~ /[a-zA-Z]:\// and
   299   # check wheter metadata and currentRelease adds up
   183                 $param_keepgoing ) {
   300   if( -e FixPaths( getcwd )."currentRelease.xml") {
   184         HandleError( "You should run getenv only in root of the substituted drive\nYou can use -k as keep going parameter if you think it is ok to proceed", $cannotContinue );
   301       printLog( "CurrenRelease.xml exists. Checking wheter update is possible" );
   185     }
   302       
   186 
   303       # compare service, product and release with xml files
   187     # ok we are in root. Is the drive empty?
   304       my $CurrentRelXmlParser = new XML::Simple( );
   188     my $xmlFile = 0;
   305       my $currentReleaseData = $CurrentRelXmlParser->XMLin( FixPaths( getcwd )."currentRelease.xml" );
   189     my $driveEmpty = 1;
   306       
   190     
   307       my $xmlParser = new XML::Simple( );
   191     opendir( ROOT, "/" ) or HandleError( "cant read root dir: $!", $warning );
   308       my $xmlData = $xmlParser->XMLin( $metaDataXml );
   192     my @filesFound = readdir( ROOT );
   309 
   193     closedir( ROOT );
       
   194     foreach my $file( @filesFound ) {
       
   195         next if $file =~ /^\.[\.]?$/;
       
   196         next if $file =~ /getenv/;
       
   197         $xmlFile = 1 if $file =~ /.*metadata.*\.xml/;
       
   198         $xmlFile = 1 if $file =~ /currentRelease\.xml/;
       
   199         $driveEmpty = 0;
       
   200     }
       
   201     
       
   202     printLog( "xml files: $xmlFile" );
       
   203     printLog( "drive empty: $driveEmpty" );
       
   204 
       
   205     # if drive is not empty and no xmls found ==> print warning (if -start param not specified)
       
   206     if( ! $param_start_directly and ! $xmlFile and ! $driveEmpty ) {
       
   207         HandleError( "The drive you are about to extract environment is not empty!\nHit CTRL-C to break now or <enter> to continue", $promptUser );
       
   208     }
       
   209 
       
   210     # if there is valid metadata.xml in root, params like path or latest doesn't make any sense
       
   211     if( $xmlFile ) {
       
   212         foreach my $file( @filesFound ) {
       
   213             if( $file =~ /.*metadata(_(\d*))?.xml$/i ) {
       
   214                 print "metadata file found!\n";
       
   215                 if( ValidateXmlFile( getcwd.$file ) ) {
       
   216                     $metaDataXml = getcwd.$file;
       
   217                     last;
       
   218                 }
       
   219             }
       
   220         }
       
   221     }
       
   222 
       
   223     if( $metaDataXml ) {
       
   224         if( $param_latest or $param_release_path ) {
       
   225             print "It doesnt make sense to use 'path' or 'latest' parameter while having metadata.xml in root!\n\n";
       
   226             print_help( );
       
   227             exit 0;
       
   228         }
       
   229 
       
   230         # we should ask correct grace share if xmlfile !server !start       
       
   231         if( !$param_server and ! $param_start_directly ) {
       
   232             print "For your convenience it is recommended to use GRACE samba share close to you.\n";
       
   233             # prompt user wheter he wants to use GRACE
       
   234             my $networkAccessVerified = 0;
       
   235             while( $networkAccessVerified eq 0 ) {
       
   236                 my $wantedServer = FixPaths( $graceList[ ReturnMenuIndex( "Please select share closest to you", @graceNameList ) ] );
       
   237         
       
   238                 if( $wantedServer eq FixPaths( $graceList[0] ) ) {
       
   239                     HandleError( "Please notice that access to $graceList[0] will be removed from wk50 onwards. Now would be perfect time to get yourself a GRACE access.", $promptUser );
       
   240                 }
       
   241             
       
   242                 printLog( "selected: $wantedServer - accessing.." );
       
   243                 if( opendir( GRACETEST, $wantedServer ) ) {
       
   244                     printLog( "connection tested OK" );
       
   245                     $networkAccessVerified = 1;
       
   246                     $pathToReleaseFolder = $wantedServer;
       
   247                 }
       
   248                 else {
       
   249                     print "Unable to access $wantedServer\nPlease select another network share.\n";
       
   250                 }
       
   251             }
       
   252         }
       
   253         
       
   254         # in case we have metadata in \ and -start defined, look grace automatically
       
   255         elsif( !$param_server and $param_start_directly ) {
       
   256             $pathToReleaseFolder = FindGraceServer( );
       
   257         }
       
   258     }
       
   259     
       
   260     # ToDo: if there is not metadata.xml in root check if we have already env. Possibly update?
       
   261     
       
   262     # is 'path' parameter is used, find out (wheter there exists) valid metadata.xml
       
   263     if( $param_release_path ) {
       
   264         if( $param_latest or $param_product ) {
       
   265             print "It doesnt make sense to use 'path' or 'latest' parameter while having metadata.xml in root!\n\n";
       
   266             print_help( );
       
   267             exit 0;
       
   268         }
       
   269         $metaDataXml = FixPaths( $param_release_path );
       
   270         $metaDataXml .= SearchValidXml( $metaDataXml );
       
   271         printLog( "setting metadata: $metaDataXml" );
       
   272     }
       
   273     
       
   274     # handle server parameter
       
   275     # simply just verify accessablility and fix path
       
   276     if( $param_server ) {
       
   277         $pathToReleaseFolder = FixPaths( $param_server );
       
   278         opendir( OPENTEST, $pathToReleaseFolder ) or HandleError( "Unable to access given server path: $pathToReleaseFolder\n$!", $cannotContinue );
       
   279         closedir( OPENTEST );
       
   280     }
       
   281     
       
   282     # param_latest is used to just get latest release - requires product
       
   283     if( $param_latest ) {
       
   284         if( $param_product ) {
       
   285             $param_product = FixPaths( $param_product );
       
   286             
       
   287             # once the network share is unavailable then tries to find grace share
       
   288             $pathToReleaseFolder = FindGraceServer( );
       
   289             
       
   290             opendir( RELDIR, $pathToReleaseFolder.$defaultServiceName.$param_product ) or die "unable to open $pathToReleaseFolder$defaultServiceName$param_product\n$!";
       
   291             # scan all xml files to @files_found
       
   292 # salmarko starts
   310 # salmarko starts
   293             my @files_found = grep { /^pf_|^S60_|^dfs_/i } readdir RELDIR;
   311       my $currentRelease = '';
   294 # salmarko ends
   312       my $newRelease = '';
   295             close RELDIR;
   313 
   296 
   314       if ( !defined $xmlData->{releaseDetails}->{dependsOf}->{service}->{name} ) { # no dependencies, lets compare current to new
   297             if( @files_found ) {
   315           # compare services
   298                 foreach( reverse sort ( @files_found ) ) {
   316           if( $currentReleaseData->{releaseDetails}->{releaseID}->{service}->{name} ne
   299                     # we only want to get the last dir name..
   317                   $xmlData->{releaseDetails}->{releaseID}->{service}->{name} ) {
   300                     s/.*\///i;
   318               HandleError( "Can not extract ".$xmlData->{releaseDetails}->{releaseID}->{service}->{name} .
   301                     my $productToDl = $pathToReleaseFolder.$defaultServiceName.$param_product;
   319               " release on top of ".$currentReleaseData->{releaseDetails}->{releaseID}->{service}->{name}, $cannotContinue );
   302                     $productToDl .= FixPaths( $_ );
   320           }
   303                     print "Searching metadata.xml files from $productToDl\n" if $param_debug;
   321           # compare products
   304 
   322           if( $currentReleaseData->{releaseDetails}->{releaseID}->{product}->{name} ne
   305                     $metaDataXml = SearchValidXml( $productToDl ) ;
   323                   $xmlData->{releaseDetails}->{releaseID}->{product}->{name} ) {
   306                     if( $metaDataXml ) {
   324               HandleError( "Can not extract ".$xmlData->{releaseDetails}->{releaseID}->{product}->{name} .
   307                         $metaDataXml = $productToDl.$metaDataXml;
   325               " release on top of ".$currentReleaseData->{releaseDetails}->{releaseID}->{product}->{name}, $cannotContinue );
   308                         printLog( "selected xml: $metaDataXml" );
   326           }
   309                         last;
   327           printLog( "service and product matches.. checking release" );
   310                     }
   328 
   311                 }
   329           $currentRelease = $currentReleaseData->{releaseDetails}->{releaseID}->{release}->{name};
   312             }
   330           $newRelease = $xmlData->{releaseDetails}->{releaseID}->{release}->{name};
   313             else {
   331       }
   314                 HandleError( "cannot find releases from $pathToReleaseFolder$defaultServiceName$param_product", $cannotContinue );
   332       else{
   315             }
   333           # compare services
   316         }
   334           if( $currentReleaseData->{releaseDetails}->{releaseID}->{service}->{name} ne
   317         else {
   335                   $xmlData->{releaseDetails}->{dependsOf}->{service}->{name} ) {
   318             die "If you specify -latest parameter you have to define -product also!\n";
   336               HandleError( "Can not extract ".$xmlData->{releaseDetails}->{dependsOf}->{service}->{name} .
   319         }
   337               " release on top of ".$currentReleaseData->{releaseDetails}->{releaseID}->{service}->{name}, $cannotContinue );
   320     }
   338           }
   321     
   339           # compare products
   322     # use wizard to find out what to DL
   340           if( $currentReleaseData->{releaseDetails}->{releaseID}->{product}->{name} ne
   323     if( ! $metaDataXml ) {
   341                   $xmlData->{releaseDetails}->{dependsOf}->{product}->{name} ) {
   324         printLog( "Not enought valid inputs provided - running wizard..." );
   342               HandleError( "Can not extract ".$xmlData->{releaseDetails}->{dependsOf}->{product}->{name} .
   325         RunWizard( );
   343               " release on top of ".$currentReleaseData->{releaseDetails}->{releaseID}->{product}->{name}, $cannotContinue );
   326     }
   344           }
   327     
   345           printLog( "service and product matches.. checking release" );
   328     # check wheter metadata and currentRelease adds up
   346           
   329     if( -e FixPaths( getcwd )."currentRelease.xml") {
   347           # compare releases
   330         printLog( "CurrenRelease.xml exists. Checking wheter update is possible" );
   348           $currentRelease = $currentReleaseData->{releaseDetails}->{releaseID}->{release}->{name};
   331         
   349           $newRelease = $xmlData->{releaseDetails}->{dependsOf}->{release}->{name};
   332         # compare service, product and release with xml files
   350 
   333         my $CurrentRelXmlParser = new XML::Simple( );
   351           if ( $currentRelease =~ m/^(S60_\d_\d+_\d{6})/i or $currentRelease =~ m/^(pf_\d{4}_\d{6})/ ) {
   334         my $currentReleaseData = $CurrentRelXmlParser->XMLin( FixPaths( getcwd )."currentRelease.xml" );
   352               $currentRelease = $1;
   335         
   353           }
   336         my $xmlParser = new XML::Simple( );
   354           else {
   337         my $xmlData = $xmlParser->XMLin( $metaDataXml );
   355               HandleError( "Current release info unknown or missing: $currentRelease", $cannotContinue );
   338 
   356           }
   339 # salmarko starts
   357 
   340         my $currentRelease = '';
   358           if ( $newRelease =~ m/^(S60_\d_\d+_\d{6})/i or $newRelease =~ m/^(pf_\d{4}_\d{6})/ ) {
   341         my $newRelease = '';
   359               $newRelease = $1;
   342 
   360           }
   343         if ( !defined $xmlData->{releaseDetails}->{dependsOf}->{service}->{name} ) { # no dependencies, lets compare current to new
   361           else {
   344             # compare services
   362               HandleError( "New release info unknown or missing: $newRelease", $cannotContinue );
   345             if( $currentReleaseData->{releaseDetails}->{releaseID}->{service}->{name} ne
   363           }
   346                     $xmlData->{releaseDetails}->{releaseID}->{service}->{name} ) {
   364       }
   347                 HandleError( "Can not extract ".$xmlData->{releaseDetails}->{releaseID}->{service}->{name} .
   365 
   348                 " release on top of ".$currentReleaseData->{releaseDetails}->{releaseID}->{service}->{name}, $cannotContinue );
   366       printLog( "current release: $currentRelease" );
   349             }
   367       printLog( "release to extract: $newRelease" );
   350             # compare products
   368 #salmarko ends
   351             if( $currentReleaseData->{releaseDetails}->{releaseID}->{product}->{name} ne
   369 
   352                     $xmlData->{releaseDetails}->{releaseID}->{product}->{name} ) {
   370       if( $currentRelease ne $newRelease ) {
   353                 HandleError( "Can not extract ".$xmlData->{releaseDetails}->{releaseID}->{product}->{name} .
   371           HandleError( "Can not extract $newRelease release on top of $currentRelease", $cannotContinue );
   354                 " release on top of ".$currentReleaseData->{releaseDetails}->{releaseID}->{product}->{name}, $cannotContinue );
   372       }
   355             }
   373       printLog( "release matches - update possible" );
   356             printLog( "service and product matches.. checking release" );
   374       
   357 
   375       $currentRelease = FixPaths( getcwd )."currentRelease.xml";
   358             $currentRelease = $currentReleaseData->{releaseDetails}->{releaseID}->{release}->{name};
   376   }
   359             $newRelease = $xmlData->{releaseDetails}->{releaseID}->{release}->{name};
   377   # check wheter we can use c-disc as temp
   360         }
   378   my $df = getFreeDisk(  $ENV{'TEMP'}  );
   361         else{
   379   
   362             # compare services
   380   if( $df > 2147483648 && $df < 2147483648000 ) {
   363             if( $currentReleaseData->{releaseDetails}->{releaseID}->{service}->{name} ne
   381     printLog( "amount of free space seems sane: $df" );
   364                     $xmlData->{releaseDetails}->{dependsOf}->{service}->{name} ) {
   382     $tmpDir = FixPaths( tempdir( CLEANUP => 0 ) );
   365                 HandleError( "Can not extract ".$xmlData->{releaseDetails}->{dependsOf}->{service}->{name} .
   383     printLog( "setting tmpDir: $tmpDir" );
   366                 " release on top of ".$currentReleaseData->{releaseDetails}->{releaseID}->{service}->{name}, $cannotContinue );
   384     $tmpDlDir = FixPaths( tempdir( CLEANUP => 0 ) );
   367             }
   385     printLog( "setting tmpDlDir: $tmpDlDir" );
   368             # compare products
   386   }
   369             if( $currentReleaseData->{releaseDetails}->{releaseID}->{product}->{name} ne
       
   370                     $xmlData->{releaseDetails}->{dependsOf}->{product}->{name} ) {
       
   371                 HandleError( "Can not extract ".$xmlData->{releaseDetails}->{dependsOf}->{product}->{name} .
       
   372                 " release on top of ".$currentReleaseData->{releaseDetails}->{releaseID}->{product}->{name}, $cannotContinue );
       
   373             }
       
   374             printLog( "service and product matches.. checking release" );
       
   375             
       
   376             # compare releases
       
   377             $currentRelease = $currentReleaseData->{releaseDetails}->{releaseID}->{release}->{name};
       
   378             $newRelease = $xmlData->{releaseDetails}->{dependsOf}->{release}->{name};
       
   379 
       
   380             if ( $currentRelease =~ m/^(S60_\d_\d+_\d{6})/i or $currentRelease =~ m/^(pf_\d{4}_\d{6})/ ) {
       
   381                 $currentRelease = $1;
       
   382             }
       
   383             else {
       
   384                 HandleError( "Current release info unknown or missing: $currentRelease", $cannotContinue );
       
   385             }
       
   386 
       
   387             if ( $newRelease =~ m/^(S60_\d_\d+_\d{6})/i or $newRelease =~ m/^(pf_\d{4}_\d{6})/ ) {
       
   388                 $newRelease = $1;
       
   389             }
       
   390             else {
       
   391                 HandleError( "New release info unknown or missing: $newRelease", $cannotContinue );
       
   392             }
       
   393         }
       
   394 
       
   395         printLog( "current release: $currentRelease" );
       
   396         printLog( "release to extract: $newRelease" );
       
   397 # salmarko ends
       
   398 
       
   399         if( $currentRelease ne $newRelease ) {
       
   400             HandleError( "Can not extract $newRelease release on top of $currentRelease", $cannotContinue );
       
   401         }
       
   402         printLog( "release matches - update possible" );
       
   403         
       
   404         $currentRelease = FixPaths( getcwd )."currentRelease.xml";
       
   405     }
       
   406 }
   387 }
   407 
   388 
   408 
   389 
   409 # Make sure paths are as perl likes 'em
   390 # Make sure paths are as perl likes 'em
   410 # change '\' ==> '/' and make sure last char is /
   391 # change '\' ==> '/' and make sure last char is /
   500   getenv.pl -k          keep going even when errors occurs
   481   getenv.pl -k          keep going even when errors occurs
   501   getenv.pl -p          do nothing, but print system calls
   482   getenv.pl -p          do nothing, but print system calls
   502   getenv.pl -emu        DEPRECATED - prefer filtering: get only emulator environment
   483   getenv.pl -emu        DEPRECATED - prefer filtering: get only emulator environment
   503   getenv.pl -start      starts extracting without user confirmation (nice for scripts)
   484   getenv.pl -start      starts extracting without user confirmation (nice for scripts)
   504   getenv.pl -nodeps     do not download dependencies for the release
   485   getenv.pl -nodeps     do not download dependencies for the release
   505   getenv.pl -nosoap     dont try to use SOAP connection for s60builds server
       
   506   getenv.pl -skipitd    DEPRECATED - prefer filtering: skips useless doc, internal, tsrc zips
   486   getenv.pl -skipitd    DEPRECATED - prefer filtering: skips useless doc, internal, tsrc zips
   507   getenv.pl -verbose    print debug traces
   487   getenv.pl -verbose    print debug traces
   508   getenv.pl -Include    include only some types of packages (emu, src, tsrc)
   488   getenv.pl -Include    include only some types of packages (emu, src, tsrc)
   509   getenv.pl -eXclude    exclude some types of packages (emu, src, tsrc)
   489   getenv.pl -eXclude    exclude some types of packages (emu, src, tsrc)
       
   490   getenv.pl -all        extract all zips
       
   491   getenv.pl -Force      forces to extract some filtered packages ( tsrc ) including default zips
   510 
   492 
   511 examples
   493 examples
   512 ========
   494 ========
   513   get latest PRODUCT release:
   495   get latest PRODUCT release:
   514       getenv.pl -latest -product PRODUCT
   496       getenv.pl -latest -product PRODUCT
   578 # salmarko ends
   560 # salmarko ends
   579         # prompt user wheter he wants to use GRACE
   561         # prompt user wheter he wants to use GRACE
   580         my $wantedServer;
   562         my $wantedServer;
   581         my $networkAccessVerified = 0;
   563         my $networkAccessVerified = 0;
   582         while( $networkAccessVerified eq 0 ) {
   564         while( $networkAccessVerified eq 0 ) {
   583             $wantedServer = FixPaths( $graceList[ ReturnMenuIndex( "Please select share closest to you", @graceNameList ) ] );
   565             $wantedServer = FixPaths( $hydraList[ ReturnMenuIndex( "Please select share closest to you", @hydraNameList ) ] );
   584             
   566             
   585             if( $wantedServer eq FixPaths( $graceList[0] ) ) {
   567             if( $wantedServer eq FixPaths( $hydraList[0] ) ) {
   586                 HandleError( "Please notice that access to $graceList[0] will be removed from wk50 onwards. Now would be perfect time to get yourself GRACE access.", $promptUser );
   568                 HandleError( "Please notice that access to $hydraList[0] will be removed from wk50 onwards. Now would be perfect time to get yourself GRACE access.", $promptUser );
   587             }
   569             }
   588         
   570         
   589             printLog( "selected: $wantedServer - accessing.." );
   571             printLog( "selected: $wantedServer - accessing.." );
   590             if( opendir( GRACETEST, $wantedServer ) ) {
   572             if( opendir( GRACETEST, $wantedServer ) ) {
   591                 printLog( "connection tested OK" );
   573                 printLog( "connection tested OK" );
   592                 $networkAccessVerified = 1;
   574                 $networkAccessVerified = 1;
   593                 $pathToReleaseFolder = $wantedServer;
   575                 $pathToReleaseFolder = $wantedServer;
   594             }
   576             }
   595             else {
   577             else {
   596                 print "Unable to access $wantedServer\nPlease select another network share.\n";
   578         die "Unable to access $wantedServer\nPlease select another network share.\n";
   597             }
   579             }
   598         }
   580         }
   599         my $wantedService = $serviceList[ ReturnMenuIndex( "Please select GRACE Service.", @serviceNameList)];
   581         my $wantedService = $serviceList[ ReturnMenuIndex( "Please select GRACE Service.", @serviceNameList)];
   600         printLog( "selected: $wantedServer.$wantedService - accessing.." );
   582         printLog( "selected: $wantedServer.$wantedService - accessing.." );
   601         local *GRACETEST2;
   583         local *GRACETEST2;
   602         if( opendir( GRACETEST2, $wantedServer.$wantedService ) ) {
   584         if( opendir( GRACETEST2, $wantedServer.$wantedService ) ) {
   603             printLog( "serviceconnection tested OK" );
   585             printLog( "serviceconnection tested OK" );
   604             $defaultServiceName = $wantedService
   586             $defaultServiceName = $wantedService
   605             }
   587             }
   606             else {
   588             else {
   607             print "Unable to access $wantedServer.$wantedService\nPlease select another network share or service.\n";
   589             die "Unable to access $wantedServer.$wantedService\nPlease select another network share or service.\n";
   608             }
   590             }
   609     }
   591     }
   610 
   592 
   611     # find & select correct product from the server
   593     # find & select correct product from the server
   612     my @productFiles = FindAvailableProducts( );
   594     my @productFiles = FindAvailableProducts( );
   634 
   616 
   635 # check what products is there under servers release path
   617 # check what products is there under servers release path
   636 sub FindAvailableProducts {
   618 sub FindAvailableProducts {
   637     opendir( DIR, $pathToReleaseFolder.$defaultServiceName )
   619     opendir( DIR, $pathToReleaseFolder.$defaultServiceName )
   638         or HandleError( "Can't open directory: $pathToReleaseFolder$defaultServiceName\n$!", $cannotContinue );
   620         or HandleError( "Can't open directory: $pathToReleaseFolder$defaultServiceName\n$!", $cannotContinue );
   639 #change to match only for directories
   621   my @productFiles = grep /^pf_|^S60|^DFS|^50_|^pf./i, readdir (DIR);
   640 #   my @productFiles = grep { /s(eries_)?60_\d_\d/i } readdir (DIR);
       
   641 # salmarko starts
       
   642     my @productFiles = grep /^pf_|^S60_|^DFS/i, readdir (DIR);
       
   643 # salmarko ends
       
   644     printLog( @productFiles );
   622     printLog( @productFiles );
   645     closedir( DIR );
   623     closedir( DIR );
   646     
   624     
   647     # return found releases sorted
   625     # return found releases sorted
   648     return sort( @productFiles );
   626     return sort( @productFiles );
   748     printLog( "searching available releases from $selectedProduct" );
   726     printLog( "searching available releases from $selectedProduct" );
   749 #   print $serverPath.$selectedProduct."\n";
   727 #   print $serverPath.$selectedProduct."\n";
   750     opendir( DIR, $pathToReleaseFolder.$defaultServiceName .$selectedProduct ) or die "Can't open dir: $!\n";
   728     opendir( DIR, $pathToReleaseFolder.$defaultServiceName .$selectedProduct ) or die "Can't open dir: $!\n";
   751 #   my @releaseFiles = grep { /S60_\d_\d.*/ } readdir (DIR);
   729 #   my @releaseFiles = grep { /S60_\d_\d.*/ } readdir (DIR);
   752 # salmarko starts
   730 # salmarko starts
   753     my @releaseFiles = grep /^pf_|^S60/i, readdir (DIR);
   731   #my @releaseFiles = grep /^pf_|^S60|^DFS|^50_|^pf./i, readdir (DIR);
       
   732   # s3laine: Better way to exclude "." and ".." entries. The previous will fail
       
   733   # if the release name includes dots. 
       
   734   my @releaseFiles = grep { $_ ne '.' and $_ ne '..' } readdir (DIR); 
   754 # salmarko ends
   735 # salmarko ends
   755 #   print Dumper( @releaseFiles );
   736 #   print Dumper( @releaseFiles );
   756     closedir (DIR);
   737     closedir (DIR);
   757 #TODO: maybe we should also check wheter xml files exists in release
   738 #TODO: maybe we should also check wheter xml files exists in release
   758     return sort {$b cmp $a} ( @releaseFiles );
   739     return sort {$b cmp $a} ( @releaseFiles );
   811         # reduct old DL'd files (currentrelease.xml and it's dependencies)
   792         # reduct old DL'd files (currentrelease.xml and it's dependencies)
   812         # passing param '1' as for printing
   793         # passing param '1' as for printing
   813         RemoveThisXmlFromFinalList( FixPaths( getcwd )."currentRelease.xml", 1 );
   794         RemoveThisXmlFromFinalList( FixPaths( getcwd )."currentRelease.xml", 1 );
   814     }
   795     }
   815     if( VerifyFinalZipList( ) or $param_keepgoing ) {
   796     if( VerifyFinalZipList( ) or $param_keepgoing ) {
   816         # start SOAP session
       
   817         if( $soapConnection ) {
       
   818             my $soapSessionInfo = StartSoapSession( );
       
   819             printLog( "SOAP: note ".$soapSessionInfo->{'HelloNote'} );
       
   820             printLog( "SOAP: sessionid ".$soapSessionInfo->{'SessionID'} );
       
   821             
       
   822             print "\n".$soapSessionInfo->{'HelloNote'}."\n\n" if( $soapSessionInfo->{'HelloNote'} );
       
   823             $soapSessionID = $soapSessionInfo->{'SessionID'};
       
   824             printLog( "SOAP: soapSessionID set: $soapSessionID" );
       
   825         }
       
   826         
       
   827         # extract the environment
   797         # extract the environment
   828         GetEnv( );
   798         GetEnv( );
   829     }
   799     }
   830 }
   800 }
   831 
   801 
   891         ${packageHash}{$key}{path} = FixPaths( $releaseInServer );
   861         ${packageHash}{$key}{path} = FixPaths( $releaseInServer );
   892         ${packageHash}{$key}{type} = $xmlDataHandle->{releaseFiles}->{package}->{$key}->{'type'};
   862         ${packageHash}{$key}{type} = $xmlDataHandle->{releaseFiles}->{package}->{$key}->{'type'};
   893         ${packageHash}{$key}{state} = $xmlDataHandle->{releaseFiles}->{package}->{$key}->{'state'};
   863         ${packageHash}{$key}{state} = $xmlDataHandle->{releaseFiles}->{package}->{$key}->{'state'};
   894         ${packageHash}{$key}{extract} = $xmlDataHandle->{releaseFiles}->{package}->{$key}->{'extract'};
   864         ${packageHash}{$key}{extract} = $xmlDataHandle->{releaseFiles}->{package}->{$key}->{'extract'};
   895         ${packageHash}{$key}{default} = $xmlDataHandle->{releaseFiles}->{package}->{$key}->{'default'};
   865         ${packageHash}{$key}{default} = $xmlDataHandle->{releaseFiles}->{package}->{$key}->{'default'};
   896         
   866     # added 5th of September 2008 by salmarko, include all zips
   897         # added 31.7.2007 : check filters -attribute
   867     if ( $param_all ) {
       
   868       ${packageHash}{$key}{default} = "true";
       
   869     }
   898         if ($xmlDataHandle->{releaseFiles}->{package}->{$key}->{'filters'}){
   870         if ($xmlDataHandle->{releaseFiles}->{package}->{$key}->{'filters'}){
   899             ${packageHash}{$key}{s60filter} = $xmlDataHandle->{releaseFiles}->{package}->{$key}->{'filters'};
   871             ${packageHash}{$key}{s60filter} = $xmlDataHandle->{releaseFiles}->{package}->{$key}->{'filters'};
   900         }
   872         }
   901         elsif ($xmlDataHandle->{releaseFiles}->{package}->{$key}->{'s60filter'}) {;
   873         elsif ($xmlDataHandle->{releaseFiles}->{package}->{$key}->{'s60filter'}) {;
   902             ${packageHash}{$key}{s60filter} = $xmlDataHandle->{releaseFiles}->{package}->{$key}->{'s60filter'};
   874             ${packageHash}{$key}{s60filter} = $xmlDataHandle->{releaseFiles}->{package}->{$key}->{'s60filter'};
   903         }   
   875         }   
   904 
   876 
       
   877     # added 5th of September 2008 by salmarko, include zips marked as false if -f parameter equals
       
   878     if ( ${packageHash}{$key}{default} eq "false" ) {
       
   879       if ( @force_include ) {
       
   880         foreach my $include( @force_include ) {
       
   881           if ( FindFromList( $include,${packageHash}{$key}{s60filter} ) ) {
       
   882             ${packageHash}{$key}{default} = "true";
       
   883           }
       
   884         }
       
   885       }
       
   886       if ( @param_include ){
       
   887         foreach my $include( @param_include ) {
       
   888           if ( FindFromList( $include,${packageHash}{$key}{s60filter} ) ) {
       
   889             ${packageHash}{$key}{default} = "true";
       
   890           }
       
   891         }
       
   892       }
       
   893     }
   905         # find out what is the latest state
   894         # find out what is the latest state
   906         if( $finalState < $xmlDataHandle->{releaseFiles}->{package}->{$key}->{'state'} ) {
   895         if( $finalState < $xmlDataHandle->{releaseFiles}->{package}->{$key}->{'state'} ) {
   907             $finalState = $xmlDataHandle->{releaseFiles}->{package}->{$key}->{'state'};
   896             $finalState = $xmlDataHandle->{releaseFiles}->{package}->{$key}->{'state'};
   908         }
   897         }
   909     }
   898     }
   930         my $specialInstructions = $xmlDataHandle->{servicePacks}->{servicePack}->{instructions};
   919         my $specialInstructions = $xmlDataHandle->{servicePacks}->{servicePack}->{instructions};
   931         if( $specialInstructions ) {
   920         if( $specialInstructions ) {
   932             printLog( "read special instructions" );
   921             printLog( "read special instructions" );
   933         }
   922         }
   934     }
   923     }
   935     # this is needed due to SymSEE's obsolete xml library
       
   936     # in case there is > 1 SP's in one XML file
   924     # in case there is > 1 SP's in one XML file
   937     else {
   925     else {
   938         foreach( keys(%{$xmlDataHandle->{servicePacks}->{servicePack} } ) ) {
   926         foreach( keys(%{$xmlDataHandle->{servicePacks}->{servicePack} } ) ) {
   939 #       foreach my $tmparray( $xmlDataHandle->{servicePacks}->{servicePack} ) {
   927 #       foreach my $tmparray( $xmlDataHandle->{servicePacks}->{servicePack} ) {
   940             printLog( "spname: $_" );
   928             printLog( "spname: $_" );
  1127             foreach my $finalZip( @finalZipList ) {
  1115             foreach my $finalZip( @finalZipList ) {
  1128 # path contains ../../../ so wont match ==>
  1116 # path contains ../../../ so wont match ==>
  1129 #               if( $finalZip->{filename} eq $zips and
  1117 #               if( $finalZip->{filename} eq $zips and
  1130 #                       $finalZip->{path} eq %packageHash->{$zips}->{'path'} ) {
  1118 #                       $finalZip->{path} eq %packageHash->{$zips}->{'path'} ) {
  1131                 if( $finalZip->{filename} eq $zips ) {
  1119                 if( $finalZip->{filename} eq $zips ) {
  1132                             printLog( "removing $finalZip->{path}/$finalZip->{filename} from dl list" );
  1120               printLog( "removing $finalZip->{path} $finalZip->{filename} from dl list" );
  1133                             $finalZip->{default} = "false";
  1121                             $finalZip->{default} = "false";
  1134                 }
  1122                 }
  1135             }
  1123             }
  1136         }
  1124         }
  1137     }
  1125     }
  1165     print "done\n";
  1153     print "done\n";
  1166 }
  1154 }
  1167 
  1155 
  1168 
  1156 
  1169 sub GetEnv {
  1157 sub GetEnv {
  1170     # first thing is to copy 7zip
  1158   my $fileCounter = 0;
  1171     if( ! $param_print_only ) {
  1159   # first thing is to copy 7zip
  1172         `7za --help`;
  1160   if( ! $param_print_only ) {
  1173         HandleError( "couldnt copy 7zip! make sure you have it in your system path!", $warning ) if ($? != 0);
  1161     `7za --help`;
  1174         mkdir $tmpDir;
  1162     HandleError( "couldnt copy 7zip! make sure you have it in your system path!", $warning ) if ($? != 0);
  1175         mkdir $tmpDlDir;
  1163     mkdir $tmpDir;
  1176     }
  1164     mkdir $tmpDlDir;
       
  1165   }
       
  1166   
       
  1167   my $nmbrOfFiles = returnNmbrOfFiles( );
  1177 
  1168 
  1178     printLog( "final zip list:" );
  1169     printLog( "final zip list:" );
  1179     printLog( Dumper( @finalZipList ) );
  1170     printLog( Dumper( @finalZipList ) );
  1180 
  1171 
  1181     # symsee 3.3.0 contains obsolete archive::zip, so we'll have to use system calls
  1172     # symsee 3.3.0 contains obsolete archive::zip, so we'll have to use system calls
  1182     foreach my $file( @finalZipList ) {
  1173     foreach my $file( @finalZipList ) {
       
  1174     $fileCounter ++;
  1183         $returnValue = 0;
  1175         $returnValue = 0;
  1184 
  1176 
  1185         # skip not mandatory files
  1177         # skip not mandatory files
  1186         next if( $file->{default} eq "false" );
  1178         next if( $file->{default} eq "false" );
  1187 
  1179 
  1216         
  1208         
  1217         my $skipByFilter = 0;
  1209         my $skipByFilter = 0;
  1218         # exclude files that has s60filter matching with exclude array
  1210         # exclude files that has s60filter matching with exclude array
  1219         if( @param_exclude ) {
  1211         if( @param_exclude ) {
  1220             foreach my $exclude( @param_exclude ) {
  1212             foreach my $exclude( @param_exclude ) {
  1221                 if( $exclude eq $file->{s60filter} ) {
  1213 #       if( $exclude eq $file->{s60filter} ) {
  1222                     $skipByFilter = 1;
  1214         if( FindFromList( $exclude, $file->{s60filter} ) ) {
  1223                     last;
  1215           printLog( "excluding $file->{filename} because $exclude matches $file->{s60filter}" );
  1224                 }
  1216           $skipByFilter = 1;
       
  1217           last;
       
  1218         }
  1225             }
  1219             }
  1226         }
  1220         }
  1227         # include only files that has s60filter matching with include array
  1221         # include only files that has s60filter matching with include array
  1228         elsif( @param_include ) {
  1222         elsif( @param_include ) {
  1229             $skipByFilter = 1;
  1223             $skipByFilter = 1;
  1230             foreach my $include( @param_include ) {
  1224             foreach my $include( @param_include ) {
  1231                 if( $include eq $file->{s60filter} ) {
  1225 #       if( $include eq $file->{s60filter} ) {
  1232                     $skipByFilter = 0;
  1226         if( FindFromList( $include, $file->{s60filter} ) ) {
       
  1227           printLog( "including $file->{filename} because $include matches $file->{s60filter}" );
       
  1228           $skipByFilter = 0;
  1233                     last;
  1229                     last;
  1234                 }
  1230                 }
  1235             }
  1231             }
  1236         }
  1232         }
  1237         next if $skipByFilter;
  1233         next if $skipByFilter;
  1243         my $pid = myFork();
  1239         my $pid = myFork();
  1244         if( $pid ) {
  1240         if( $pid ) {
  1245             # parent process copies/unzips packages to tmpDlDir
  1241             # parent process copies/unzips packages to tmpDlDir
  1246             printLog( "parent: extract packages to $tmpDlDir" );
  1242             printLog( "parent: extract packages to $tmpDlDir" );
  1247             printLog( "parent: Processing: $file->{filename}... " );
  1243             printLog( "parent: Processing: $file->{filename}... " );
  1248             print "Processing: $file->{filename}... ";
  1244       print "Downloading[$fileCounter\/$nmbrOfFiles] $file->{filename}... ";
  1249             
  1245             
  1250             if( $file->{extract} eq 'single' ) {
  1246             if( $file->{extract} eq 'single' ) {
  1251                 # copy single zipped packages to $tmpDlDir
  1247                 # copy single zipped packages to $tmpDlDir
  1252                 printLog( "parent: single zipped - copy to $tmpDlDir" );
  1248                 printLog( "parent: single zipped - copy to $tmpDlDir" );
  1253                 if( ! $param_print_only ) {
  1249         if( ! $param_print_only ) {
  1254                     copy( $file->{path} . $file->{filename}, $tmpDlDir ) or
  1250           # Let's try 3 times to copy the file in case the server is busy, note this is a hack,
  1255                         HandleError( "cant copy file $file->{path}$file->{filename} to $tmpDlDir", $cannotContinue);
  1251           # the correct way would be either to remove the file from release list so that the next run would get the file
  1256                 }
  1252           # or to check the for the error value before trying again. Although the error code seems to be '2' ie.
       
  1253           # 'File not found' so it is a little bit hard to distinguish between removed file and the server being busy.
       
  1254           # With more testing it some times returns also error code '9' ie. 'Bad file descriptor'.
       
  1255           copy( $file->{path} . $file->{filename}, $tmpDlDir ) or
       
  1256           copy( $file->{path} . $file->{filename}, $tmpDlDir ) or
       
  1257           copy( $file->{path} . $file->{filename}, $tmpDlDir ) or
       
  1258             HandleError( "cant copy file $file->{path}$file->{filename} to $tmpDlDir", $warning );
       
  1259         }
  1257             }
  1260             }
  1258             elsif( $file->{extract} eq 'double' ) {
  1261             elsif( $file->{extract} eq 'double' ) {
  1259                 # unzip double zipped zips to $tmpDlDir
  1262                 # unzip double zipped zips to $tmpDlDir
  1260                 # there shouldnt be much of these anymore
  1263                 # there shouldnt be much of these anymore
  1261                 printLog( "parent: double zipped - unzip to $tmpDlDir" );
  1264                 printLog( "parent: double zipped - unzip to $tmpDlDir" );
  1305             die "Cannot fork: $!\n";
  1308             die "Cannot fork: $!\n";
  1306         }
  1309         }
  1307         
  1310         
  1308         # this is after forking
  1311         # this is after forking
  1309         # move files from tmpDlDir => tmpDir
  1312         # move files from tmpDlDir => tmpDir
       
  1313     printLog( "check is there file to move in tmpdldir" );
  1310         my $somethingToCopy = 0;
  1314         my $somethingToCopy = 0;
  1311         opendir( DLTEMP, $tmpDlDir ) or HandleError( "cant read $tmpDlDir dir: $!", $warning );
  1315         opendir( DLTEMP, $tmpDlDir ) or HandleError( "cant read $tmpDlDir dir: $!", $warning );
  1312         my @filesFound = readdir( DLTEMP );
  1316         my @filesFound = readdir( DLTEMP );
  1313         closedir( DLTEMP );
  1317         closedir( DLTEMP );
  1314         foreach my $file( @filesFound ) {
  1318         foreach my $file( @filesFound ) {
  1315             next if $file =~ /^\.[\.]?$/;
  1319             next if $file =~ /^\.[\.]?$/;
       
  1320       printLog( "in tmpdldir: $file" );
  1316             $somethingToCopy = 1;
  1321             $somethingToCopy = 1;
  1317         }
  1322         }
  1318 
  1323 
  1319         if( $somethingToCopy ) {
  1324         if( $somethingToCopy ) {
  1320             printLog( "move everything from $tmpDlDir to $tmpDir" ); 
  1325             printLog( "move everything from $tmpDlDir to $tmpDir" ); 
  1434     }
  1439     }
  1435 }
  1440 }
  1436 
  1441 
  1437 # return path to accessible GRACE samba share
  1442 # return path to accessible GRACE samba share
  1438 sub FindGraceServer {
  1443 sub FindGraceServer {
  1439 # added 27.2.2007 : skip seeking if server has given from commandline
       
  1440 # salmarko starts
       
  1441     if (defined $param_server) {return FixPaths( $param_server );}
  1444     if (defined $param_server) {return FixPaths( $param_server );}
  1442 # salmarko ends
  1445 
  1443 
  1446     print "\nseeking possible hydra accesses. This might take a while.. ";
  1444     print "\nseeking possible grace accesses. This might take a while.. ";
       
  1445 
  1447 
  1446         my @graceAccessArray;
  1448         my @graceAccessArray;
  1447         foreach my $address( @graceList ) {
  1449         foreach my $address( @hydraList ) {
  1448             printLog( "accessing $address..." );
  1450             printLog( "accessing $address..." );
  1449             if( opendir( GRACETEST, $address ) ) {
  1451             if( opendir( GRACETEST, $address ) ) {
  1450                 push @graceAccessArray, $address;
  1452                 push @graceAccessArray, $address;
  1451                 printLog( " success\n" );
  1453                 printLog( " success\n" );
  1452                 close GRACETEST;
  1454                 close GRACETEST;
  1455                 printLog( " fail" );
  1457                 printLog( " fail" );
  1456             }
  1458             }
  1457         }
  1459         }
  1458 
  1460 
  1459     if( @graceAccessArray ) {
  1461     if( @graceAccessArray ) {
  1460         print "done\nSelected GRACE server: ", $graceAccessArray[0];
  1462         print "done\nSelected HYDRA server: ", $graceAccessArray[0];
  1461         if( scalar( @graceAccessArray ) > 1 ) {
  1463         if( scalar( @graceAccessArray ) > 1 ) {
  1462             
  1464             
  1463             # if start is defined && >1 grace shares available, we'll have to just guess correct share
  1465             # if start is defined && >1 grace shares available, we'll have to just guess correct share
  1464             if( $param_start_directly ) {
  1466             if( $param_start_directly ) {
  1465                 print( "More than one grace shares accessible\n" );
  1467                 print( "More than one HYDRA shares accessible\n" );
  1466                 print Dumper( @graceAccessArray );
  1468                 print Dumper( @graceAccessArray );
  1467                 print "\nBecause -start parameter is provided we cant prompt user to select correct, lets pick first one from the list\n";
  1469                 print "\nBecause -start parameter is provided we cant prompt user to select correct, lets pick first one from the list\n";
  1468                 print "You should use -server parameter to define the server\n";
  1470                 print "You should use -server parameter to define the server\n";
  1469                 printLog( "-start defined and >1 grace shares accessible" );
  1471                 printLog( "-start defined and >1 hydra shares accessible" );
  1470                 printLog( @graceAccessArray );
  1472                 printLog( @graceAccessArray );
  1471                 printLog( "selecting first one: $graceAccessArray[0]" );
  1473                 printLog( "selecting first one: $graceAccessArray[0]" );
  1472                 return FixPaths( $graceAccessArray[0] );
  1474                 return FixPaths( $graceAccessArray[0] );
  1473             }
  1475             }
  1474             else {
  1476             else {
  1475 # salmarko starts
  1477 # salmarko starts
  1476                 return FixPaths( PrintSelectMenu( "Select reasonable GRACE share", @graceAccessArray ) );
  1478                 return FixPaths( PrintSelectMenu( "Select reasonable HYDRA share", @graceAccessArray ) );
  1477 # salmarko ends
  1479 # salmarko ends
  1478             }
  1480             }
  1479         }
  1481         }
  1480         else {
  1482         else {
  1481 # salmarko starts
  1483 # salmarko starts
  1506     my $tempXmlHandle = $tempXmlParser->XMLin( $data );
  1508     my $tempXmlHandle = $tempXmlParser->XMLin( $data );
  1507     
  1509     
  1508     # parse dl directory into $releaseDirectory
  1510     # parse dl directory into $releaseDirectory
  1509     return $tempXmlHandle->{releaseDetails}->{releaseID}->{product}->{name};
  1511     return $tempXmlHandle->{releaseDetails}->{releaseID}->{product}->{name};
  1510 }
  1512 }
  1511 
       
  1512 sub GetSoapVersion {
       
  1513     printLog( "Trying to access SOAP server" );
       
  1514     
       
  1515     my $soapVersion = eval { SOAP::Lite
       
  1516                                                         ->uri('GetEnv')
       
  1517                                                         ->on_action(sub{ sprintf('%s/%s', @_ )})
       
  1518                                                         ->proxy($soapServiceURL)
       
  1519                                                         ->GetVersionInfo( )
       
  1520                                                         ->result } ;
       
  1521     
       
  1522     print Dumper( $soapVersion ) if( $param_debug );
       
  1523     
       
  1524     return $soapVersion;
       
  1525 }
       
  1526 
       
  1527 sub StartSoapSession {
       
  1528     printLog( "fetching session start info from SOAP" );
       
  1529     my $netPath = FixPaths( $pathToReleaseFolder );
       
  1530     $netPath .= FixPaths( $defaultServiceName );
       
  1531     $netPath .= FixPaths( ReturnProductName( $metaDataXml ) );
       
  1532     $netPath .= FixPaths( ReturnReleaseName( $metaDataXml ) );
       
  1533 #   $netPath .= $metaDataXml;
       
  1534     printLog( "about to fetch: $netPath" );
       
  1535     
       
  1536     return SOAP::Lite
       
  1537         ->uri('GetEnv')
       
  1538         ->on_action(sub{ sprintf('%s/%s', @_ )})
       
  1539         ->proxy($soapServiceURL)
       
  1540         ->StartGetEnv( SOAP::Data->name( BuildName=> ReturnReleaseName( $metaDataXml ) )
       
  1541                                             ->type('string')
       
  1542                                             ->uri('GetEnv'),
       
  1543                                         SOAP::Data->name( NetworkPath=> $netPath )
       
  1544                                             ->type('string')
       
  1545                                             ->uri('GetEnv'),
       
  1546                                         SOAP::Data->name( UserName=> $ENV{'USERNAME'} )
       
  1547                                             ->type('string')
       
  1548                                             ->uri('GetEnv'),
       
  1549                                         SOAP::Data->name( MachineName=> $ENV{'COMPUTERNAME'} )
       
  1550                                             ->type('string')
       
  1551                                             ->uri('GetEnv') )
       
  1552         ->result;
       
  1553 }
       
  1554 
       
  1555 sub EndSoapConnection {
       
  1556     printLog( "SOAP: Finishing SOAP session: $soapSessionID" );
       
  1557     printLog( "SOAP: release downloaded: $metaDataXml" );
       
  1558 
       
  1559     return SOAP::Lite
       
  1560         ->uri('GetEnv')
       
  1561         ->on_action(sub{ sprintf('%s/%s', @_ )})
       
  1562         ->proxy($soapServiceURL)
       
  1563         ->DoneGetEnv( SOAP::Data->name( ID=> $soapSessionID )
       
  1564                                         ->type('string')
       
  1565                                         ->uri('GetEnv'))
       
  1566         ->result;
       
  1567 
       
  1568 }
       
  1569 
       
  1570 
  1513 
  1571 sub FindTempDir {
  1514 sub FindTempDir {
  1572     # it'll speed up extraction if we put temp dir to separate disk
  1515     # it'll speed up extraction if we put temp dir to separate disk
  1573     
  1516     
  1574 }
  1517 }
  1592         {
  1535         {
  1593         die "fork error\n";
  1536         die "fork error\n";
  1594         }
  1537         }
  1595     return $pid;
  1538     return $pid;
  1596     }
  1539     }
  1597 
  1540 # try to grep amount of free disk space
       
  1541 sub getFreeDisk {
       
  1542   printLog( "getFreeDisk: $_[0]" );
       
  1543   my $bytesfree;
       
  1544   my $d = $_[0];
       
  1545   chomp($d);
       
  1546 
       
  1547   my $cmd = "call dir $d";
       
  1548   my @dir = `$cmd 2>&1`;
       
  1549   return -1 if ($? != 0);
       
  1550   my $dir = $dir[scalar(@dir) - 1]; # the last line
       
  1551   chop($dir);
       
  1552   
       
  1553   printLog( "dir: $dir" );
       
  1554 
       
  1555   # clean up whitespaces
       
  1556   $dir =~ s/^\s+//g;
       
  1557   $dir =~ s/\s+$//g;
       
  1558   $dir =~ s/\s{1,}/ /g;
       
  1559 
       
  1560   # get rid of `X Dir(s)'
       
  1561   @dir = split(/\s/, $dir);
       
  1562   $dir = join("", @dir[2 .. scalar(@dir)]);
       
  1563   # get digits only
       
  1564   $dir =~ s/[^0-9]//g;
       
  1565   
       
  1566   # free space in gigabytes
       
  1567 # $bytesfree = $dir/1073741824;
       
  1568   $bytesfree = $dir;
       
  1569   
       
  1570   printLog( "returning: $bytesfree" );
       
  1571   return $bytesfree;
       
  1572 }
       
  1573 
       
  1574 # returns amount of files set for extract from finalZipList
       
  1575 sub returnNmbrOfFiles {
       
  1576   my $count = 0;
       
  1577   
       
  1578   foreach( @finalZipList ) {
       
  1579     $count++ if $_->{default};
       
  1580   }
       
  1581   
       
  1582   return $count;
       
  1583 }
       
  1584