public static function evaluate_string_to_qualifier($supplied, $bind_version = true, $check_only_type = false)
 {
     $qualified = false;
     $c_repo = null;
     $repos = self::linked_repositories();
     if (($c = strpos($supplied, '/')) !== false) {
         // A repository was explicitly defined
         $c_repo = substr($supplied, 0, $c);
         $test = substr($supplied, $c + 1);
         // If it's in the linked repo list it should have refreshed when starting client
         if (!in_array($c_repo, $repos)) {
             // Pull in this repository's index
             pts_openbenchmarking::refresh_repository_lists($repos);
         }
         $repos = array($c_repo);
     } else {
         // If it's in the linked repo list it should have refreshed when starting client
         $test = $supplied;
     }
     if (($c = strrpos($test, '-')) !== false) {
         $version = substr($test, $c + 1);
         // TODO: functionalize this and read against types.xsd
         if (isset($version[2]) && !isset($version[8]) && pts_strings::string_only_contains($version, pts_strings::CHAR_NUMERIC | pts_strings::CHAR_DECIMAL)) {
             $test = substr($test, 0, $c);
         } else {
             $version = null;
         }
     } else {
         $version = null;
     }
     if ($test == null) {
         return false;
     }
     foreach ($repos as $repo) {
         if ($repo == 'local') {
             if (self::check_only_type_compare($check_only_type, 'test')) {
                 if (is_file(PTS_TEST_PROFILE_PATH . $repo . '/' . $test . '/test-definition.xml')) {
                     return $repo . '/' . $test;
                     // ($bind_version ? '-' . $version : null)
                 } else {
                     if (is_file(PTS_TEST_PROFILE_PATH . $repo . '/' . $test . '-' . $version . '/test-definition.xml')) {
                         return $repo . '/' . $test . '-' . $version;
                         // ($bind_version ? '-' . $version : null)
                     }
                 }
             }
             if (self::check_only_type_compare($check_only_type, 'suite')) {
                 if (is_file(PTS_TEST_SUITE_PATH . $repo . '/' . $test . '/suite-definition.xml')) {
                     return $repo . '/' . $test;
                     // ($bind_version ? '-' . $version : null)
                 } else {
                     if (is_file(PTS_TEST_SUITE_PATH . $repo . '/' . $test . '-' . $version . '/suite-definition.xml')) {
                         return $repo . '/' . $test . '-' . $version;
                         // ($bind_version ? '-' . $version : null)
                     }
                 }
             }
         }
         $repo_index = pts_openbenchmarking::read_repository_index($repo);
         if (is_array($repo_index) && isset($repo_index['tests'][$test]) && self::check_only_type_compare($check_only_type, 'test')) {
             // The test profile at least exists
             // Looking for a particular test profile version?
             if ($version != null) {
                 if (!in_array($version, $repo_index['tests'][$test]['versions'])) {
                     // Grep to see if the version passed was e.g. 1.3 instead of 1.3.3
                     $versions = $repo_index['tests'][$test]['versions'];
                     sort($versions);
                     foreach (array_reverse($versions) as $check_version) {
                         if (strstr($check_version, $version) != false) {
                             $version = $check_version;
                             break;
                         }
                     }
                 }
                 if (in_array($version, $repo_index['tests'][$test]['versions'])) {
                     pts_openbenchmarking::download_test_profile($repo . '/' . $test . '-' . $version);
                     return $repo . '/' . $test . ($bind_version ? '-' . $version : null);
                 }
             } else {
                 // Assume to use the latest version unless something else is installed
                 $available_versions = $repo_index['tests'][$test]['versions'];
                 $version = $available_versions[0];
                 // the latest version available
                 if (pts_c::$test_flags & pts_c::is_run_process) {
                     // Check to see if an older version of the test profile is currently installed
                     foreach ($available_versions as $i => $v) {
                         if (is_file(pts_client::test_install_root_path() . $repo . '/' . $test . '-' . $v . '/pts-install.xml')) {
                             $version = $v;
                             if ($i > 0 && pts_c::$test_flags ^ pts_c::batch_mode) {
                                 // It's not the latest test profile version available
                                 trigger_error($repo . '/' . $test . ': The latest test profile version available for upgrade is ' . $available_versions[0] . ' but version ' . $version . ' is the latest currently installed.', E_USER_WARNING);
                             }
                             break;
                         }
                     }
                 }
                 pts_openbenchmarking::download_test_profile($repo . '/' . $test . '-' . $version);
                 return $repo . '/' . $test . ($bind_version ? '-' . $version : null);
             }
         }
         if (is_array($repo_index) && isset($repo_index['suites'][$test]) && self::check_only_type_compare($check_only_type, 'suite')) {
             // The test profile at least exists
             // Looking for a particular test profile version?
             if ($version != null) {
                 if (!in_array($version, $repo_index['suites'][$test]['versions'])) {
                     // Grep to see if the version passed was e.g. 1.3 instead of 1.3.3
                     $versions = $repo_index['suites'][$test]['versions'];
                     sort($versions);
                     foreach (array_reverse($versions) as $check_version) {
                         if (strstr($check_version, $version) != false) {
                             $version = $check_version;
                             break;
                         }
                     }
                 }
                 if (in_array($version, $repo_index['suites'][$test]['versions'])) {
                     pts_openbenchmarking::download_test_suite($repo . '/' . $test . '-' . $version);
                     return $repo . '/' . $test . ($bind_version ? '-' . $version : null);
                 }
             } else {
                 // Assume to use the latest version
                 $version = array_shift($repo_index['suites'][$test]['versions']);
                 pts_openbenchmarking::download_test_suite($repo . '/' . $test . '-' . $version);
                 return $repo . '/' . $test . ($bind_version ? '-' . $version : null);
             }
         }
     }
     return false;
 }
 public static function run($r)
 {
     pts_client::$display->generic_heading('Available Tests');
     $available_tests = pts_openbenchmarking::available_tests(false);
     $available_suites = pts_openbenchmarking::available_suites(false);
     $test_count = count($available_tests);
     $suite_count = count($available_suites);
     $total_count = $test_count + $suite_count;
     $total_cache_count = 0;
     $total_cache_size = 0;
     if ($test_count == 0 || !pts_network::internet_support_available()) {
         echo PHP_EOL . 'No tests found. Please check that you have Internet connectivity to download test profile data from OpenBenchmarking.org. The Phoronix Test Suite has documentation on configuring the network setup, proxy settings, and PHP network options. Please contact Phoronix Media if you continuing to experience problems.' . PHP_EOL . PHP_EOL;
         return false;
     }
     $terminal_width = pts_client::terminal_width();
     // Cache test profiles
     foreach ($available_tests as $i => $identifier) {
         $repo = substr($identifier, 0, strpos($identifier, '/'));
         $test = substr($identifier, strlen($repo) + 1);
         $repo_index = pts_openbenchmarking::read_repository_index($repo);
         echo $i . '/' . $total_count . ': ' . ($repo_index['tests'][$test]['title'] != null ? $repo_index['tests'][$test]['title'] . ' [' . $repo_index['tests'][$test]['test_type'] . ']' : null) . PHP_EOL;
         foreach ($repo_index['tests'][$test]['versions'] as $version) {
             $qualified_identifier = $repo . '/' . $test . '-' . $version;
             echo $qualified_identifier;
             $success = pts_openbenchmarking::download_test_profile($repo . '/' . $test . '-' . $version);
             if ($success && is_file(PTS_OPENBENCHMARKING_SCRATCH_PATH . $qualified_identifier . '.zip')) {
                 $file_size = round(filesize(PTS_OPENBENCHMARKING_SCRATCH_PATH . $qualified_identifier . '.zip') / 1024, 2);
                 $info = $file_size . 'KB - ' . sha1_file(PTS_OPENBENCHMARKING_SCRATCH_PATH . $qualified_identifier . '.zip');
                 $r_size = $terminal_width - strlen($qualified_identifier) - 3 - strlen($info);
                 if ($r_size > 0) {
                     echo ' ' . str_repeat('.', $terminal_width - strlen($qualified_identifier) - 3 - strlen($info)) . ' ' . $info . PHP_EOL;
                 }
                 $total_cache_count++;
                 $total_cache_size += $file_size;
             }
         }
         echo PHP_EOL;
     }
     // Cache test suites
     foreach ($available_suites as $i => $identifier) {
         $repo = substr($identifier, 0, strpos($identifier, '/'));
         $test = substr($identifier, strlen($repo) + 1);
         $repo_index = pts_openbenchmarking::read_repository_index($repo);
         echo $i + $test_count . '/' . $total_count . ': ' . $repo_index['suites'][$test]['title'] . PHP_EOL;
         foreach ($repo_index['suites'][$test]['versions'] as $version) {
             $qualified_identifier = $repo . '/' . $test . '-' . $version;
             echo $qualified_identifier;
             $success = pts_openbenchmarking::download_test_suite($repo . '/' . $test . '-' . $version);
             if ($success && is_file(PTS_OPENBENCHMARKING_SCRATCH_PATH . $qualified_identifier . '.zip')) {
                 $file_size = round(filesize(PTS_OPENBENCHMARKING_SCRATCH_PATH . $qualified_identifier . '.zip') / 1024, 2);
                 $info = $file_size . 'KB - ' . sha1_file(PTS_OPENBENCHMARKING_SCRATCH_PATH . $qualified_identifier . '.zip');
                 $dot_size = $terminal_width - strlen($qualified_identifier) - 3 - strlen($info);
                 echo ' ' . str_repeat('.', $dot_size >= 0 ? $dot_size : 0) . ' ' . $info . PHP_EOL;
                 $total_cache_count++;
                 $total_cache_size += $file_size;
             }
         }
         echo PHP_EOL;
     }
     echo PHP_EOL . $total_cache_count . ' Files Cached' . PHP_EOL . $test_count . ' Test Profiles' . PHP_EOL . $suite_count . ' Test Suites' . PHP_EOL . $total_cache_size . 'KB Total Cache Size' . PHP_EOL . PHP_EOL;
 }