本文整理汇总了PHP中pts_strings::add_trailing_slash方法的典型用法代码示例。如果您正苦于以下问题:PHP pts_strings::add_trailing_slash方法的具体用法?PHP pts_strings::add_trailing_slash怎么用?PHP pts_strings::add_trailing_slash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pts_strings
的用法示例。
在下文中一共展示了pts_strings::add_trailing_slash方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: delete
public static function delete($object, $ignore_files = null, $remove_root_directory = false)
{
// Delete files and/or directories
if ($object == false) {
return false;
}
if (is_dir($object)) {
$object = pts_strings::add_trailing_slash($object);
}
foreach (pts_file_io::glob($object . '*') as $to_remove) {
if (is_file($to_remove) || is_link($to_remove)) {
if (is_array($ignore_files) && in_array(basename($to_remove), $ignore_files)) {
continue;
// Don't remove the file
} else {
unlink($to_remove);
}
} else {
if (is_dir($to_remove)) {
self::delete($to_remove, $ignore_files, true);
}
}
}
if ($remove_root_directory && is_dir($object) && count(pts_file_io::glob($object . '/*')) == 0) {
rmdir($object);
}
}
示例2: user_home_directory
public static function user_home_directory()
{
// Gets the system user's home directory
static $userhome = null;
if ($userhome == null) {
if (function_exists('posix_getpwuid') && function_exists('posix_getuid')) {
$userinfo = posix_getpwuid(posix_getuid());
$userhome = $userinfo['dir'];
} else {
if ($home = pts_client::read_env('HOME')) {
$userhome = $home;
} else {
if ($home = pts_client::read_env('HOMEPATH')) {
$userhome = pts_client::read_env('HOMEDRIVE') . $home;
} else {
if (PTS_IS_DAEMONIZED_SERVER_PROCESS) {
$userhome = PTS_USER_PATH;
} else {
if (!is_writable('/')) {
echo PHP_EOL . 'ERROR: Cannot find home directory.' . PHP_EOL;
}
$userhome = null;
}
}
}
}
$userhome = pts_strings::add_trailing_slash($userhome);
}
return $userhome;
}
示例3: find_download_cache
public static function find_download_cache()
{
if (is_file(PTS_DOWNLOAD_CACHE_PATH . 'pts-download-cache.json')) {
$dc_file = PTS_DOWNLOAD_CACHE_PATH . 'pts-download-cache.json';
} else {
if (is_file('/var/cache/phoronix-test-suite/download-cache/pts-download-cache.json')) {
$dc_file = '/var/cache/phoronix-test-suite/download-cache/pts-download-cache.json';
} else {
if (is_file(PTS_SHARE_PATH . 'download-cache/pts-download-cache.json')) {
$dc_file = PTS_SHARE_PATH . 'download-cache/pts-download-cache.json';
} else {
$dc = pts_strings::add_trailing_slash(pts_strings::parse_for_home_directory(pts_config::read_user_config('PhoronixTestSuite/Options/Installation/CacheDirectory', PTS_DOWNLOAD_CACHE_PATH)));
if (is_file($dc . 'pts-download-cache.json')) {
$dc_file = $dc . 'pts-download-cache.json';
}
}
}
}
return $dc_file;
}
示例4: render_page_process
public static function render_page_process($PATH)
{
echo phoromatic_webui_header_logged_in();
$main = '<h1>Cache Settings</h1>
<h2>Test Profile Download Cache</h2>
<p>Below are a list of files for verification/debugging purposes that are currently cached by the Phoromatic Server and available for Phoronix Test Suite client systems to download. These are files that are needed by various test profiles in the Phoronix Test Suite. To add more data to this Phoromatic Server cache, from the server run <strong>phoronix-test-suite make-download-cache</strong> while passing the names of any tests/suites you wish to have download and generate a cache for so they can be made available to the Phoronix Test Suite clients on your network.</p>';
$dc = pts_strings::add_trailing_slash(pts_strings::parse_for_home_directory(pts_config::read_user_config('PhoronixTestSuite/Options/Installation/CacheDirectory', PTS_DOWNLOAD_CACHE_PATH)));
$dc_exists = is_file($dc . 'pts-download-cache.json');
if ($dc_exists) {
$cache_json = file_get_contents($dc . 'pts-download-cache.json');
$cache_json = json_decode($cache_json, true);
}
if (is_file($dc . 'pts-download-cache.json')) {
if ($cache_json && isset($cache_json['phoronix-test-suite']['download-cache'])) {
$total_file_size = 0;
$main .= '<table style="margin: 0 auto;"><tr><th>File</th><th>Size</th></tr>';
foreach ($cache_json['phoronix-test-suite']['download-cache'] as $file_name => $inf) {
$total_file_size += $cache_json['phoronix-test-suite']['download-cache'][$file_name]['file_size'];
$main .= '<tr><td>' . $file_name . '</td><td>' . round(max(0.1, $cache_json['phoronix-test-suite']['download-cache'][$file_name]['file_size'] / 1000000), 1) . 'MB</td></tr>';
}
$main .= '</table>';
$main .= '<p><strong>' . count($cache_json['phoronix-test-suite']['download-cache']) . ' Files / ' . round($total_file_size / 1000000) . ' MB Cache Size</strong></p>';
}
} else {
$main .= '<h3>No download cache file could be found; on the Phoromatic Server you should run <strong>phoronix-test-suite make-download-cache</strong>.</h3>';
// TODO XXX implement from the GUI
}
$main .= '<hr /><h2>OpenBenchmarking.org Cache Data</h2>';
$main .= '<p>Below is information pertaining to the OpenBenchmarking.org cache present on the Phoromatic Server. To update this cache, run <strong>phoronix-test-suite make-openbenchmarking-cache</strong> from the server.</p>';
$index_files = pts_file_io::glob(PTS_OPENBENCHMARKING_SCRATCH_PATH . '*.index');
$main .= '<table style="margin: 0 auto;"><tr><th>Repository</th><th>Last Updated</th></tr>';
foreach ($index_files as $index_file) {
$index_data = json_decode(file_get_contents($index_file), true);
$main .= '<tr><td>' . basename($index_file, '.index') . '</td><td>' . date('d F Y H:i', $index_data['main']['generated']) . '</td></tr>';
}
$main .= '</table>';
echo phoromatic_webui_main($main, phoromatic_webui_right_panel_logged_in());
echo phoromatic_webui_footer();
}
示例5: render_page_process
public static function render_page_process($PATH)
{
if ($_SESSION['AdminLevel'] != -40) {
header('Location: /?main');
}
$main = null;
if (isset($_POST['new_phoromatic_path']) && !empty($_POST['new_phoromatic_path'])) {
$new_dir = dirname($_POST['new_phoromatic_path']);
if (!is_dir($new_dir)) {
$main .= '<h2 style="color: red;"><em>' . $new_dir . '</em> must be a valid directory.</h2>';
} else {
if (!is_writable($new_dir)) {
$main .= '<h2 style="color: red;"><em>' . $new_dir . '</em> is not a writable location.</h2>';
} else {
if (!is_dir($_POST['new_phoromatic_path'])) {
if (mkdir($_POST['new_phoromatic_path']) == false) {
$main .= '<h2 style="color: red;">Failed to make directory <em>' . $_POST['new_phoromatic_path'] . '</em>.</h2>';
}
}
if (is_dir($_POST['new_phoromatic_path'])) {
$new_phoromatic_dir = pts_strings::add_trailing_slash($_POST['new_phoromatic_path']);
$d = glob($new_phoromatic_dir . '*');
if (!empty($d)) {
$new_phoromatic_dir .= 'phoromatic/';
pts_file_io::mkdir($new_phoromatic_dir);
}
$d = glob($new_phoromatic_dir . '*');
if (!empty($d)) {
$main .= '<h2 style="color: red;"><em>' . $new_phoromatic_dir . '</em> must be an empty directory.</h2>';
} else {
if (pts_file_io::copy(phoromatic_server::phoromatic_path(), $new_phoromatic_dir)) {
pts_config::user_config_generate(array('PhoromaticStorage' => $new_phoromatic_dir));
header('Location: /?admin');
} else {
$main .= '<h2 style="color: red;"><em>Failed to copy old Phoromatic data to new location.</h2>';
}
}
}
}
}
}
if (isset($_POST['new_dc_path']) && !empty($_POST['new_dc_path'])) {
$new_dir = dirname($_POST['new_dc_path']);
if (!is_dir($new_dir)) {
$main .= '<h2 style="color: red;"><em>' . $new_dir . '</em> must be a valid directory.</h2>';
} else {
if (!is_writable($new_dir)) {
$main .= '<h2 style="color: red;"><em>' . $new_dir . '</em> is not a writable location.</h2>';
} else {
if (!is_dir($_POST['new_dc_path'])) {
if (mkdir($_POST['new_dc_path']) == false) {
$main .= '<h2 style="color: red;">Failed to make directory <em>' . $_POST['new_dc_path'] . '</em>.</h2>';
}
}
if (is_dir($_POST['new_dc_path'])) {
$new_dc_dir = pts_strings::add_trailing_slash($_POST['new_dc_path']);
if (pts_file_io::copy(pts_strings::add_trailing_slash(pts_client::parse_home_directory(pts_config::read_user_config('PhoronixTestSuite/Options/Installation/CacheDirectory', PTS_DOWNLOAD_CACHE_PATH))), $new_dc_dir)) {
pts_config::user_config_generate(array('CacheDirectory' => $new_dc_dir));
header('Location: /?admin');
} else {
$main .= '<h2 style="color: red;"><em>Failed to copy old Phoromatic data to new location.</h2>';
}
}
}
}
}
if (isset($_POST['new_proxy_address']) && isset($_POST['new_proxy_port'])) {
if (pts_network::http_get_contents('http://www.phoronix-test-suite.com/PTS', $_POST['new_proxy_address'], $_POST['new_proxy_port']) == 'PTS') {
pts_config::user_config_generate(array('PhoronixTestSuite/Options/Networking/ProxyAddress' => $_POST['new_proxy_address'], 'PhoronixTestSuite/Options/Networking/ProxyPort' => $_POST['new_proxy_port']));
} else {
$main .= '<h2 style="color: red;">Failed to connect via proxy server.</h2>';
}
}
if (isset($_POST['new_http_port']) && isset($_POST['new_ws_port'])) {
if (empty($_POST['new_http_port']) || !is_numeric($_POST['new_http_port']) && $_POST['new_http_port'] != 'RANDOM') {
$main .= '<h2 style="color: red;">The HTTP port must be a valid port number or <em>RANDOM</em>.</h2>';
}
if (empty($_POST['new_ws_port']) || !is_numeric($_POST['new_ws_port']) && $_POST['new_ws_port'] != 'RANDOM') {
$main .= '<h2 style="color: red;">The WebSocket port must be a valid port number or <em>RANDOM</em>.</h2>';
}
pts_config::user_config_generate(array('PhoronixTestSuite/Options/Server/RemoteAccessPort' => $_POST['new_http_port'], 'PhoronixTestSuite/Options/Server/WebSocketPort' => $_POST['new_ws_port']));
}
if (isset($_POST['add_new_users_to_account'])) {
if (empty($_POST['add_new_users_to_account'])) {
phoromatic_server::save_setting('add_new_users_to_account', null);
} else {
$stmt = phoromatic_server::$db->prepare('SELECT COUNT(AccountID) AS AccountHitCount FROM phoromatic_accounts WHERE AccountID = :account_id');
$stmt->bindValue(':account_id', $_POST['add_new_users_to_account']);
$result = $stmt->execute();
$row = $result->fetchArray();
if (empty($row['AccountHitCount'])) {
$main .= '<h2 style="color: red;"><em>' . $_POST['add_new_users_to_account'] . '</em> is not a valid account ID.</h2>';
} else {
phoromatic_server::save_setting('add_new_users_to_account', $_POST['add_new_users_to_account']);
}
}
}
if (isset($_POST['account_creation_alt'])) {
phoromatic_server::save_setting('account_creation_alt', $_POST['account_creation_alt']);
}
//.........这里部分代码省略.........
示例6: render_page_process
public static function render_page_process($PATH)
{
$main = null;
$identifier_item = isset($PATH[1]) ? $PATH[0] . '/' . $PATH[1] : false;
if ($identifier_item && pts_test_profile::is_test_profile($identifier_item)) {
$tp = new pts_test_profile($identifier_item);
$tp_identifier = $tp->get_identifier(false);
$main .= '<h1>' . $tp->get_title() . '</h1><p>' . $tp->get_description() . '</p>';
$main .= '<p><strong>' . $tp->get_test_hardware_type() . ' - ' . phoromatic_server::test_result_count_for_test_profile($_SESSION['AccountID'], $tp_identifier) . ' Results On This Account - ' . $tp->get_test_software_type() . ' - Maintained By: ' . $tp->get_maintainer() . ' - Supported Platforms: ' . implode(', ', $tp->get_supported_platforms()) . '</strong></p>';
$main .= '<p><a href="http://openbenchmarking.org/test/' . $tp_identifier . '">Find out more about this test profile on OpenBenchmarking.org</a>.</p>';
$main .= '<h2>Recent Results With This Test</h2>';
$stmt = phoromatic_server::$db->prepare('SELECT Title, PPRID FROM phoromatic_results WHERE AccountID = :account_id AND UploadID IN (SELECT DISTINCT UploadID FROM phoromatic_results_results WHERE AccountID = :account_id AND TestProfile LIKE :tp) ORDER BY UploadTime DESC LIMIT 30');
$stmt->bindValue(':account_id', $_SESSION['AccountID']);
$stmt->bindValue(':tp', $tp_identifier . '%');
$result = $stmt->execute();
$recent_result_count = 0;
while ($result && ($row = $result->fetchArray())) {
$recent_result_count++;
$main .= '<h2><a href="/?result/' . $row['PPRID'] . '">' . $row['Title'] . '</a></h2>';
}
if ($recent_result_count == 0) {
$main .= '<p>No results found on this Phoromatic Server for the ' . $tp->get_title() . ' test profile.</p>';
} else {
if ($recent_result_count > 5) {
$stmt = phoromatic_server::$db->prepare('SELECT UploadID, SystemID, UploadTime FROM phoromatic_results WHERE AccountID = :account_id AND UploadID IN (SELECT DISTINCT UploadID FROM phoromatic_results_results WHERE AccountID = :account_id AND TestProfile LIKE :tp) ORDER BY UploadTime DESC LIMIT 1000');
$stmt->bindValue(':account_id', $_SESSION['AccountID']);
$stmt->bindValue(':tp', $tp_identifier . '%');
$result = $stmt->execute();
$recent_result_count = 0;
$result_file = new pts_result_file(null, true);
while ($result && ($row = $result->fetchArray())) {
$composite_xml = phoromatic_server::phoromatic_account_result_path($_SESSION['AccountID'], $row['UploadID']) . 'composite.xml';
if (!is_file($composite_xml)) {
continue;
}
// Add to result file
$system_name = strtotime($row['UploadTime']) . ': ' . phoromatic_server::system_id_to_name($row['SystemID']);
$sub_result_file = new pts_result_file($composite_xml, true);
foreach ($sub_result_file->get_result_objects() as $obj) {
if ($obj->test_profile->get_identifier(false) == $tp_identifier) {
$obj->test_result_buffer->rename(null, $system_name);
$result_file->add_result($obj);
}
}
}
$table = null;
$extra_attributes = array('multi_way_comparison_invert_default' => false);
$f = false;
foreach ($result_file->get_result_objects() as $obj) {
$obj->test_profile->set_display_format('SCATTER_PLOT');
foreach ($obj->test_result_buffer->buffer_items as $i => &$item) {
if (!is_numeric(substr($item->get_result_identifier(), 0, strpos($item->get_result_identifier(), ':')))) {
unset($obj->test_result_buffer->buffer_items[$i]);
}
}
$result_file = null;
$main .= '<p align="center">' . pts_render::render_graph_inline_embed($obj, $result_file, $extra_attributes) . '</p>';
}
}
}
} else {
$dc = pts_strings::add_trailing_slash(pts_strings::parse_for_home_directory(pts_config::read_user_config('PhoronixTestSuite/Options/Installation/CacheDirectory', PTS_DOWNLOAD_CACHE_PATH)));
$dc_exists = is_file($dc . 'pts-download-cache.json');
if ($dc_exists) {
$cache_json = file_get_contents($dc . 'pts-download-cache.json');
$cache_json = json_decode($cache_json, true);
}
$test_counts_for_account = phoromatic_server::test_result_count_for_test_profiles($_SESSION['AccountID']);
foreach (pts_openbenchmarking::available_tests() as $test) {
$cache_checked = false;
if ($dc_exists) {
if ($cache_json && isset($cache_json['phoronix-test-suite']['cached-tests'])) {
$cache_checked = true;
if (!in_array($test, $cache_json['phoronix-test-suite']['cached-tests'])) {
//continue;
}
}
}
if (!$cache_checked && phoromatic_server::read_setting('show_local_tests_only') && pts_test_install_request::test_files_in_cache($test, true, true) == false) {
continue;
}
$tp = new pts_test_profile($test);
if ($tp->get_title() == null) {
continue;
}
$test_count = 0;
$tpid = $tp->get_identifier(false);
foreach ($test_counts_for_account as $test => $count) {
if (strpos($test, $tpid) !== false) {
$test_count += $count;
unset($test_counts_for_account[$test]);
}
}
$main .= '<h1 style="margin-bottom: 0;"><a href="/?tests/' . $tp->get_identifier(false) . '">' . $tp->get_title() . '</a></h1>';
$main .= '<p style="font-size: 90%;"><strong>' . $tp->get_test_hardware_type() . '</strong> <em>-</em> ' . $test_count . ' Results On This Account' . ' </p>';
}
}
echo phoromatic_webui_header_logged_in();
echo '<div id="pts_phoromatic_main_area">' . $main . '</div>';
echo phoromatic_webui_footer();
//.........这里部分代码省略.........
示例7: executable_in_path
public static function executable_in_path($executable, $ignore_paths_with = false)
{
static $cache = null;
if (!isset($cache[$executable]) || $ignore_paths_with) {
$paths = pts_strings::trim_explode(phodevi::is_windows() ? ';' : ':', ($path = pts_client::read_env('PATH')) == false ? '/usr/local/bin:/usr/bin:/usr/sbin:/bin' : $path);
$executable_path = false;
foreach ($paths as $path) {
$path = pts_strings::add_trailing_slash($path);
if (is_executable($path . $executable)) {
if ($ignore_paths_with && stripos($path, $ignore_paths_with) !== false) {
continue;
}
$executable_path = $path . $executable;
break;
}
}
if ($ignore_paths_with) {
// Don't cache calls using the $ignore_paths_with parameter
return $executable_path;
}
$cache[$executable] = $executable_path;
}
return $cache[$executable];
}
示例8: render_page_process
public static function render_page_process($PATH)
{
if (isset($_POST['suite_title'])) {
// echo '<pre>';
// var_dump($_POST);
// echo '</pre>';
if (strlen($_POST['suite_title']) < 3) {
echo '<h2>Suite title must be at least three characters.</h2>';
}
//echo 'TEST SUITE: ' . $_POST['suite_title'] . '<br />';
//echo 'TEST SUITE: ' . $_POST['suite_description'] . '<br />';
$tests = array();
foreach ($_POST['test_add'] as $i => $test_identifier) {
$test_prefix = $_POST['test_prefix'][$i];
$args = array();
$args_name = array();
foreach ($_POST as $i => $v) {
if (strpos($i, $test_prefix) !== false && substr($i, -9) != '_selected') {
if (strpos($v, '||') !== false) {
$opts = explode('||', $v);
$a = array();
$d = array();
foreach ($opts as $opt) {
$t = explode('::', $opt);
array_push($a, $t[1]);
array_push($d, $t[0]);
}
array_push($args, $a);
array_push($args_name, $d);
} else {
array_push($args, array($v));
array_push($args_name, array($_POST[$i . '_selected']));
}
}
}
$test_args = array();
$test_args_description = array();
pts_test_run_options::compute_all_combinations($test_args, null, $args, 0);
pts_test_run_options::compute_all_combinations($test_args_description, null, $args_name, 0, ' - ');
foreach (array_keys($test_args) as $i) {
array_push($tests, array('test' => $test_identifier, 'description' => $test_args_description[$i], 'args' => $test_args[$i]));
}
}
if (count($tests) < 1) {
echo '<h2>You must add at least one test to the suite.</h2>';
}
$suite_writer = new pts_test_suite_writer();
$version_bump = 0;
do {
$suite_version = '1.' . $version_bump . '.0';
$suite_id = $suite_writer->clean_save_name_string($_POST['suite_title']) . '-' . $suite_version;
$suite_dir = phoromatic_server::phoromatic_account_suite_path($_SESSION['AccountID'], $suite_id);
$version_bump++;
} while (is_dir($suite_dir));
pts_file_io::mkdir($suite_dir);
$save_to = $suite_dir . '/suite-definition.xml';
$suite_writer->add_suite_information($_POST['suite_title'], $suite_version, $_SESSION['UserName'], 'System', $_POST['suite_description']);
foreach ($tests as $m) {
$suite_writer->add_to_suite($m['test'], $m['args'], $m['description']);
}
$suite_writer->save_xml($save_to);
echo '<h2>Saved As ' . $suite_id . '</h2>';
}
echo phoromatic_webui_header_logged_in();
$main = '<h1>Local Suites</h1><p>Find already created local test suites by your account/group via the <a href="/?local_suites">local suites</a> page.</p>';
if (!PHOROMATIC_USER_IS_VIEWER) {
$main .= '<h1>Build Suite</h1><p>A test suite in the realm of the Phoronix Test Suite, OpenBenchmarking.org, and Phoromatic is <strong>a collection of test profiles with predefined settings</strong>. Establishing a test suite makes it easy to run repetitive testing on the same set of test profiles by simply referencing the test suite name.</p>';
$main .= '<form action="' . $_SERVER['REQUEST_URI'] . '" name="build_suite" id="build_suite" method="post" onsubmit="return validate_suite();">
<h3>Title:</h3>
<p><input type="text" name="suite_title" /></p>
<h3>Description:</h3>
<p><textarea name="suite_description" id="suite_description" cols="60" rows="2"></textarea></p>
<h3>Tests In Schedule:</h3>
<p><div id="test_details"></div></p>
<h3>Add Another Test</h3>';
$main .= '<select name="add_to_suite_select_test" id="add_to_suite_select_test" onchange="phoromatic_build_suite_test_details();">';
$dc = pts_strings::add_trailing_slash(pts_client::parse_home_directory(pts_config::read_user_config('PhoronixTestSuite/Options/Installation/CacheDirectory', PTS_DOWNLOAD_CACHE_PATH)));
$dc_exists = is_file($dc . 'pts-download-cache.json');
foreach (pts_openbenchmarking::available_tests(false, true) as $test) {
$cache_checked = false;
if ($dc_exists) {
$cache_json = file_get_contents($dc . 'pts-download-cache.json');
$cache_json = json_decode($cache_json, true);
if ($cache_json && isset($cache_json['phoronix-test-suite']['cached-tests'])) {
$cache_checked = true;
if (!in_array($test, $cache_json['phoronix-test-suite']['cached-tests'])) {
continue;
}
}
}
if (!$cache_checked && phoromatic_server::read_setting('show_local_tests_only') && pts_test_install_request::test_files_in_cache($test, true, true) == false) {
continue;
}
$main .= '<option value="' . $test . '">' . $test . '</option>';
}
$main .= '</select>';
$main .= '<p align="right"><input name="submit" value="Create Suite" type="submit" onclick="return pts_rmm_validate_suite();" /></p>';
}
echo '<div id="pts_phoromatic_main_area">' . $main . '</div>';
echo phoromatic_webui_footer();
//.........这里部分代码省略.........
示例9: define
define('REMOTE_ACCESS', true);
// XXX TODO: Is this still used with new Phoromatic?
ini_set('memory_limit', '4G');
define('PTS_MODE', 'WEB_CLIENT');
define('PTS_AUTO_LOAD_OBJECTS', true);
//error_reporting(E_ALL);
include '../../pts-core.php';
pts_core::init();
if (isset($_GET['repo'])) {
readfile(phoromatic_server::find_download_cache());
pts_logger::add_to_log($_SERVER['REMOTE_ADDR'] . ' requested a copy of the download cache JSON');
} else {
if (isset($_GET['download'])) {
$requested_file = str_replace(array('..', '/'), null, $_GET['download']);
pts_logger::add_to_log($_SERVER['REMOTE_ADDR'] . ' is attempting to download ' . $requested_file . ' from the download cache');
if (($dc = pts_strings::add_trailing_slash(pts_strings::parse_for_home_directory(pts_config::read_user_config('PhoronixTestSuite/Options/Installation/CacheDirectory', PTS_DOWNLOAD_CACHE_PATH)))) && is_file($dc . $requested_file)) {
$file_path = $dc . $requested_file;
} else {
if (is_file(PTS_DOWNLOAD_CACHE_PATH . $requested_file)) {
$file_path = PTS_DOWNLOAD_CACHE_PATH . $requested_file;
} else {
if (is_file(PTS_SHARE_PATH . 'download-cache/' . $requested_file)) {
$file_path = PTS_SHARE_PATH . 'download-cache/' . $requested_file;
} else {
if (is_file('/var/cache/phoronix-test-suite/download-cache/' . $requested_file)) {
$file_path = '/var/cache/phoronix-test-suite/download-cache/' . $requested_file;
} else {
pts_logger::add_to_log($requested_file . ' could not be found in the download cache');
exit;
}
}
示例10: download_cache_locations
public static function download_cache_locations()
{
static $cache_directories = null;
if ($cache_directories == null) {
$cache_directories = array();
// Phoronix Test Suite System Cache Directories
$additional_dir_checks = array('/var/cache/phoronix-test-suite/download-cache/', '/var/cache/phoronix-test-suite/');
foreach ($additional_dir_checks as $dir_check) {
if (is_dir($dir_check)) {
$cache_directories[] = $dir_check;
break;
}
}
// User Defined Directory Checking
$dir_string = ($dir = pts_client::read_env('PTS_DOWNLOAD_CACHE')) != false ? $dir : null;
foreach (array_merge(self::$extra_caches, pts_strings::colon_explode($dir_string)) as $dir_check) {
if ($dir_check == null) {
continue;
}
$dir_check = pts_strings::parse_for_home_directory($dir_check);
if (pts_strings::is_url($dir_check) == false && !is_dir($dir_check)) {
continue;
}
$cache_directories[] = pts_strings::add_trailing_slash($dir_check);
}
if (pts_config::read_bool_config('PhoronixTestSuite/Options/Installation/SearchMediaForCache', 'TRUE')) {
$download_cache_dirs = array_merge(pts_file_io::glob('/media/*/download-cache/'), pts_file_io::glob('/media/*/*/download-cache/'), pts_file_io::glob('/run/media/*/*/download-cache/'), pts_file_io::glob('/Volumes/*/download-cache/'));
foreach ($download_cache_dirs as $dir) {
$cache_directories[] = $dir;
}
}
}
return $cache_directories;
}
示例11: scan_download_caches
public function scan_download_caches($local_download_caches, $remote_download_caches, $remote_files, $phoromatic_server_caches, $skip_hash_checks = false)
{
$download_location = $this->test_profile->get_install_dir();
$main_download_cache = pts_strings::add_trailing_slash(pts_strings::parse_for_home_directory(pts_config::read_user_config('PhoronixTestSuite/Options/Installation/CacheDirectory', PTS_DOWNLOAD_CACHE_PATH)));
foreach ($this->test_files as &$download_package) {
$package_filename = $download_package->get_filename();
if (is_file($download_location . $package_filename)) {
// File is already there in the test/destination directory, must have been previously downloaded
// Could add an MD5 check here to ensure validity, but if it made it here it was already valid unless user modified it
if ($download_package->get_filesize() == 0) {
$download_package->set_filesize(filesize($download_location . $package_filename));
}
$download_package->set_download_location('IN_DESTINATION_DIR');
} else {
if (is_file($main_download_cache . $package_filename)) {
// In main download cache
if ($download_package->get_filesize() == 0) {
$download_package->set_filesize(filesize($main_download_cache . $package_filename));
}
$download_package->set_download_location('MAIN_DOWNLOAD_CACHE', array($main_download_cache . $package_filename));
} else {
if (is_file(PTS_SHARE_PATH . 'download-cache/' . $package_filename)) {
// In system's /usr/share download cache
if ($download_package->get_filesize() == 0) {
$download_package->set_filesize(filesize(PTS_SHARE_PATH . 'download-cache/' . $package_filename));
}
$download_package->set_download_location('MAIN_DOWNLOAD_CACHE', array(PTS_SHARE_PATH . 'download-cache/' . $package_filename));
} else {
// Scan the local download caches
foreach ($local_download_caches as &$cache_directory) {
if (is_file($cache_directory . $package_filename) && ($skip_hash_checks || $download_package->check_file_hash($cache_directory . $package_filename))) {
if ($download_package->get_filesize() == 0) {
$download_package->set_filesize(filesize($cache_directory . $package_filename));
}
$download_package->set_download_location('LOCAL_DOWNLOAD_CACHE', array($cache_directory . $package_filename));
break;
}
}
// Look-aside download cache copy
// Check to see if the same package name with the same package check-sum is already present in another test installation
$lookaside_copy = pts_test_install_manager::file_lookaside_test_installations($download_package);
if ($lookaside_copy) {
if ($download_package->get_filesize() == 0) {
$download_package->set_filesize(filesize($lookaside_copy));
}
$download_package->set_download_location('LOOKASIDE_DOWNLOAD_CACHE', array($lookaside_copy));
}
// Check Phoromatic server caches
if ($download_package->get_download_location_type() == null && $phoromatic_server_caches) {
foreach ($phoromatic_server_caches as $server_url => $repo) {
if (isset($repo[$package_filename]) && ($skip_hash_checks || $repo[$package_filename]['md5'] == $download_package->get_md5() || $repo[$package_filename]['sha256'] == $download_package->get_sha256() || $download_package->get_sha256() == null && $download_package->get_md5() == null)) {
$download_package->set_download_location('REMOTE_DOWNLOAD_CACHE', array($server_url . '/download-cache.php?download=' . $package_filename));
break;
}
}
}
// If still not found, check remote download caches
if ($download_package->get_download_location_type() == null) {
if (isset($remote_files[$package_filename])) {
$download_package->set_download_location('REMOTE_DOWNLOAD_CACHE', $remote_files[$package_filename]);
} else {
if (!empty($remote_download_caches)) {
// Check for files manually
foreach ($remote_download_caches as $remote_dir) {
$remote_file = $remote_dir . $package_filename;
$stream_context = pts_network::stream_context_create();
$file_pointer = fopen($remote_file, 'r', false, $stream_context);
if ($file_pointer !== false) {
$download_package->set_download_location('REMOTE_DOWNLOAD_CACHE', $remote_file);
break;
}
}
}
}
}
}
}
}
}
}
示例12: render_page_process
//.........这里部分代码省略.........
$stmt->bindValue(':schedule_id', $PATH[0]);
$result = $stmt->execute();
$test_count = 0;
$main .= '<p>';
while ($row = $result->fetchArray()) {
$test_count++;
$main .= $row['TestProfile'] . ($row['TestDescription'] != null ? ' - <em>' . $row['TestDescription'] . '</em>' : '') . (!PHOROMATIC_USER_IS_VIEWER ? ' <a href="?schedules/' . $PATH[0] . '/remove/' . base64_encode(implode(PHP_EOL, array($row['TestProfile'], $row['TestArguments']))) . '">Remove Test</a>' : null) . '<br />';
/*
if(!PHOROMATIC_USER_IS_VIEWER && isset($_REQUEST['make_version_lock_tests']))
{
if(strpos($row['TestProfile'], '.') == false)
{
$test_profile = new pts_test_profile($row['TestProfile']);
$full_identifier = $test_profile->get_identifier(true);
$stmt = phoromatic_server::$db->prepare('UPDATE phoromatic_schedules_tests SET TestProfile = :version_locked_tp WHERE AccountID = :account_id AND ScheduleID = :schedule_id AND TestProfile = :test');
$stmt->bindValue(':account_id', $_SESSION['AccountID']);
$stmt->bindValue(':schedule_id', $PATH[0]);
$stmt->bindValue(':test', $row['TestProfile']);
$stmt->bindValue(':version_locked_tp', $full_identifier);
$result2 = $stmt->execute();
}
}
*/
}
$main .= '</p>';
if ($test_count == 0) {
$main .= '<h3 style="text-transform: uppercase;">No tests have been added yet for this test schedule.</h3>';
}
if (!PHOROMATIC_USER_IS_VIEWER) {
$main .= '<hr /><h2>Add A Test</h2>';
$main .= '<form action="?schedules/' . $PATH[0] . '" name="add_test" id="add_test" method="post">';
$main .= '<select name="add_to_schedule_select_test" id="add_to_schedule_select_test" onchange="phoromatic_schedule_test_details(\'\');">';
$dc = pts_strings::add_trailing_slash(pts_client::parse_home_directory(pts_config::read_user_config('PhoronixTestSuite/Options/Installation/CacheDirectory', PTS_DOWNLOAD_CACHE_PATH)));
$dc_exists = is_file($dc . 'pts-download-cache.json');
foreach (pts_openbenchmarking::available_tests(false, true) as $test) {
$cache_checked = false;
if ($dc_exists) {
$cache_json = file_get_contents($dc . 'pts-download-cache.json');
$cache_json = json_decode($cache_json, true);
if ($cache_json && isset($cache_json['phoronix-test-suite']['cached-tests'])) {
$cache_checked = true;
if (!in_array($test, $cache_json['phoronix-test-suite']['cached-tests'])) {
continue;
}
}
}
if (!$cache_checked && phoromatic_server::read_setting('show_local_tests_only') && pts_test_install_request::test_files_in_cache($test, true, true) == false) {
continue;
}
$main .= '<option value="' . $test . '">' . $test . '</option>';
}
$main .= '</select>';
$main .= '<p><div id="test_details"></div></p>';
$main .= '</form>';
}
$systems_in_schedule = phoromatic_server::systems_associated_with_schedule($_SESSION['AccountID'], $PATH[0]);
if (!empty($systems_in_schedule)) {
$main .= '<hr /><h2>Systems In Schedule</h2>';
if (!PHOROMATIC_USER_IS_VIEWER) {
$main .= '<p>To run this schedule on more systems, <a href="?sched/' . $PATH[0] . '">edit the schedule</a>.</p>';
}
$main .= '<div class="pts_phoromatic_info_box_area" style="margin: 0 10%;"><ul><li><h1>Systems</h1></li>';
foreach ($systems_in_schedule as $system_id) {
$row = phoromatic_server::get_system_details($_SESSION['AccountID'], $system_id);
$main .= '<a href="?systems/' . $row['SystemID'] . '"><li>' . $row['Title'] . '<br /><table><tr><td>' . $row['LocalIP'] . '</td><td><strong>' . $row['CurrentTask'] . '</strong></td><td><strong>Last Communication:</strong> ' . date('j F Y H:i', strtotime($row['LastCommunication'])) . '</td></tr></table></li></a>';
示例13: run
public static function run($r)
{
// Force refresh of OB repository to ensure the latest profiles
pts_openbenchmarking::refresh_repository_lists(null, true);
// Determine cache location
$dc_write_directory = pts_strings::add_trailing_slash(pts_strings::parse_for_home_directory(pts_config::read_user_config('PhoronixTestSuite/Options/Installation/CacheDirectory', PTS_DOWNLOAD_CACHE_PATH)));
echo PHP_EOL . 'Download Cache Directory: ' . $dc_write_directory . PHP_EOL;
if ($dc_write_directory == null || !is_writable($dc_write_directory)) {
echo 'No writable download cache directory was found. A download cache cannot be created.' . PHP_EOL . PHP_EOL;
return false;
}
if (!empty($r)) {
$test_profiles = pts_types::identifiers_to_test_profile_objects($r, true, true);
if (count($test_profiles) > 0) {
echo PHP_EOL . 'Downloading Test Files For: ' . implode(' ', $test_profiles);
pts_test_installer::only_download_test_files($test_profiles, $dc_write_directory);
}
}
$json_download_cache = array('phoronix-test-suite' => array('main' => array('generated' => time()), 'download-cache' => array()));
foreach (pts_tests::partially_installed_tests() as $test) {
$test_profile = new pts_test_profile($test);
echo PHP_EOL . 'Checking Downloads For: ' . $test . PHP_EOL;
foreach (pts_test_install_request::read_download_object_list($test_profile, false) as $file) {
$cached_valid = false;
if (is_file($dc_write_directory . $file->get_filename()) && $file->check_file_hash($dc_write_directory . $file->get_filename())) {
echo ' Previously Cached: ' . $file->get_filename() . PHP_EOL;
$cached_valid = true;
} else {
if (is_dir($test_profile->get_install_dir())) {
if (is_file($test_profile->get_install_dir() . $file->get_filename()) && $file->check_file_hash($test_profile->get_install_dir() . $file->get_filename())) {
echo ' Caching: ' . $file->get_filename() . PHP_EOL;
if (copy($test_profile->get_install_dir() . $file->get_filename(), $dc_write_directory . $file->get_filename())) {
$cached_valid = true;
}
}
}
}
if ($cached_valid) {
if (!isset($json_download_cache['phoronix-test-suite']['download-cache'][$file->get_filename()])) {
$json_download_cache['phoronix-test-suite']['download-cache'][$file->get_filename()] = array('file_name' => $file->get_filename(), 'file_size' => $file->get_filesize(), 'associated_tests' => array($test_profile->get_identifier()), 'md5' => $file->get_md5(), 'sha256' => $file->get_sha256());
} else {
if ($file->get_md5() == $json_download_cache['phoronix-test-suite']['download-cache'][$file->get_filename()]['md5'] && $file->get_sha256() == $json_download_cache['phoronix-test-suite']['download-cache'][$file->get_filename()]['sha256']) {
array_push($json_download_cache['phoronix-test-suite']['download-cache'][$file->get_filename()]['associated_tests'], $test_profile->get_identifier());
}
}
}
}
}
// Find files in download-cache/ that weren't part of an installed test (but could have just been tossed in there) to cache
foreach (glob($dc_write_directory . '/*') as $cached_file) {
$file_name = basename($cached_file);
if (!isset($json_download_cache['phoronix-test-suite']['download-cache'][$file_name]) && $file_name != 'pts-download-cache.json') {
$json_download_cache['phoronix-test-suite']['download-cache'][$file_name] = array('file_name' => $file_name, 'file_size' => filesize($cached_file), 'associated_tests' => array(), 'md5' => md5_file($cached_file), 'sha256' => hash_file('sha256', $cached_file));
}
}
$cached_tests = array();
foreach (pts_openbenchmarking::available_tests(true, true) as $test) {
if (pts_test_install_request::test_files_in_cache($test, true, true) == false) {
continue;
}
array_push($cached_tests, $test);
}
$json_download_cache['phoronix-test-suite']['cached-tests'] = $cached_tests;
file_put_contents($dc_write_directory . 'pts-download-cache.json', json_encode($json_download_cache, defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0));
echo PHP_EOL;
}
示例14: parse_for_home_directory
public static function parse_for_home_directory($path)
{
// Find home directory if needed
if (strpos($path, '~/') !== false) {
$path = str_replace('~/', pts_core::user_home_directory(), $path);
}
return pts_strings::add_trailing_slash($path);
}
示例15: execute_script
//.........这里部分代码省略.........
if (is_readable($this->get_real_path($line_r[1], $pass_arguments))) {
$this->var_current_directory = $this->get_real_path($line_r[1], $pass_arguments);
}
}
}
}
}
break;
case 'touch':
if (!is_file($this->var_current_directory . $line_r[1]) && is_writable($this->var_current_directory)) {
touch($this->var_current_directory . $line_r[1]);
}
break;
case 'mkdir':
pts_file_io::mkdir($this->var_current_directory . $line_r[1]);
break;
case 'rm':
for ($i = 1; $i < count($line_r); $i++) {
if (is_file($this->var_current_directory . $line_r[$i])) {
unlink($this->var_current_directory . $line_r[$i]);
} else {
if (is_dir($this->var_current_directory . $line_r[$i])) {
pts_file_io::delete($this->var_current_directory . $line_r[$i], null, true);
}
}
}
break;
case 'chmod':
$chmod_file = self::find_file_in_array($line_r);
if ($chmod_file) {
chmod($chmod_file, 0755);
}
break;
case 'unzip':
$zip_file = self::find_file_in_array($line_r);
pts_compression::zip_archive_extract($zip_file, $this->var_current_directory);
break;
case 'tar':
// TODO: implement
break;
case 'echo':
if ($line == "echo \$? > ~/install-exit-status") {
file_put_contents($this->var_current_directory . "install-exit-status", $exit_status);
break;
} else {
if ($line == "echo \$? > ~/test-exit-status") {
file_put_contents($this->var_current_directory . "test-exit-status", $exit_status);
break;
}
}
$start_echo = strpos($script_contents, "\"") + 1;
$end_echo = $start_echo - 1;
do {
$end_echo = strpos($script_contents, "\"", $end_echo + 1);
} while ($script_contents[$end_echo - 1] == "\\");
$script_pointer = strpos($script_contents, "\n", $end_echo);
$line_remainder = substr($script_contents, $end_echo + 1, $script_pointer - $end_echo - 1);
$echo_contents = substr($script_contents, $start_echo, $end_echo - $start_echo);
$this->parse_variables_in_string($echo_contents, $pass_arguments);
$echo_contents = str_replace("\\\$", "\$", $echo_contents);
$echo_contents = str_replace("\\\"", "\"", $echo_contents);
if (($to_file = strpos($line_remainder, ' > ')) !== false) {
$to_file = trim(substr($line_remainder, $to_file + 3));
if (($end_file = strpos($to_file, ' ')) !== false) {
$to_file = substr($to_file, 0, $end_file);
}
// TODO: right now it's expecting the file location pipe to be relative location
$echo_dir = pts_strings::add_trailing_slash(str_replace('"', null, $this->var_current_directory));
// needed for phodevi::is_windows() specviewperf10
file_put_contents($echo_dir . $to_file, $echo_contents . "\n");
} else {
echo $echo_contents;
}
break;
case '#!/bin/sh':
case '#':
case null:
// IGNORE
break;
case 'case':
//echo "\nUNHANDLED EVENT\n";
return false;
// TODO: decide how to handle
break;
default:
$exec_output = array();
if (phodevi::is_windows() && substr($line, 0, 2) == "./") {
$line = substr($line, 2);
}
$this->parse_variables_in_string($line, $pass_arguments);
$cd_dir = $this->var_current_directory;
if (phodevi::is_windows() && strpos($cd_dir, ':\\') === 1) {
$cd_dir = str_replace('/', '\\', $cd_dir);
$cd_dir = str_replace('\\\\', '\\', $cd_dir);
}
exec("cd " . $cd_dir . " && " . $line . " 2>&1", $exec_output, $prev_exit_status);
break;
}
} while ($script_contents != false);
}