summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Larabel <michael@phx-laptop.(none)>2008-06-23 14:29:34 -0400
committerMichael Larabel <michael@phx-laptop.(none)>2008-08-03 11:49:17 -0400
commit26aed79338d4258f4b08fcc97dc815e94ec49765 (patch)
tree0e4a636715d6de411b9f5aecbb9e9125e408eade
parent23061abebd8aec79a50de06c557a5e60b110bb0d (diff)
downloadphoronix-test-suite-upstream-26aed79338d4258f4b08fcc97dc815e94ec49765.tar.gz
phoronix-test-suite-upstream-26aed79338d4258f4b08fcc97dc815e94ec49765.tar.xz
phoronix-test-suite-upstream-26aed79338d4258f4b08fcc97dc815e94ec49765.zip
Add pts_module object for providing some common functions to use by PTS
modules, switch system_monitor to using these functions.
-rw-r--r--PTS-12-CHANGE-LOG1
-rw-r--r--pts-core/functions/pts-functions.php14
-rw-r--r--pts-core/functions/pts-functions_modules.php4
-rw-r--r--pts-core/modules/system_monitor.php16
-rw-r--r--pts-core/objects/pts_module.php95
5 files changed, 105 insertions, 25 deletions
diff --git a/PTS-12-CHANGE-LOG b/PTS-12-CHANGE-LOG
index 67d9ea3..753de58 100644
--- a/PTS-12-CHANGE-LOG
+++ b/PTS-12-CHANGE-LOG
@@ -3,3 +3,4 @@
- Add list-modules option for listing all available/installed modules
- Add module-info option for viewing information on a module
- Drop pts-functions_monitor.php now that it's all modulized.
+- Drop PTS_MONITOR_DIR environmental variable and pts_save_user_file() function from pts-core
diff --git a/pts-core/functions/pts-functions.php b/pts-core/functions/pts-functions.php
index ba4d942..95e89f6 100644
--- a/pts-core/functions/pts-functions.php
+++ b/pts-core/functions/pts-functions.php
@@ -77,7 +77,6 @@ define("ETC_DIR", PTS_DIR . "pts/etc/");
define("MODULE_DIR", PTS_DIR . "pts-core/modules/");
define("RESULTS_VIEWER_DIR", PTS_DIR . "pts-core/pts-results-viewer/");
define("PTS_USER_DIR", getenv("PTS_USER_DIR"));
-define("PTS_MONITOR_DIR", PTS_USER_DIR . "system-monitor" . '/');
define("FONT_DIR", RESULTS_VIEWER_DIR . "fonts/");
pts_config_init();
@@ -102,7 +101,6 @@ $PTS_GLOBAL_ID = 1;
$PTS_MODULES = array();
$PTS_MODULE_CURRENT = FALSE;
-pts_auto_modules_ready($PTS_MODULES);
pts_load_modules($PTS_MODULES);
pts_module_process("__startup");
register_shutdown_function("pts_module_process", "__shutdown");
@@ -187,18 +185,6 @@ function pts_copy($from, $to)
if(!is_file($to) || md5_file($from) != md5_file($to))
copy($from, $to);
}
-function pts_save_user_file($save_name = null, $contents = null, $directory = '/')
-{
- if(!is_dir(PTS_MONITOR_DIR))
- mkdir(PTS_MONITOR_DIR);
-
- if($directory != '/')
- if(!is_dir(PTS_MONITOR_DIR . $directory))
- mkdir(PTS_MONITOR_DIR . $directory);
-
- if(!empty($save_name) && !empty($contents))
- file_put_contents(PTS_USER_DIR . $extension . $directory . $save_name, $contents);
-}
function pts_gd_available()
{
if(!extension_loaded("gd"))
diff --git a/pts-core/functions/pts-functions_modules.php b/pts-core/functions/pts-functions_modules.php
index 5f09fd6..652cea0 100644
--- a/pts-core/functions/pts-functions_modules.php
+++ b/pts-core/functions/pts-functions_modules.php
@@ -37,8 +37,8 @@ function pts_auto_modules_ready(&$modules_list)
}
function pts_load_modules(&$modules_list)
{
- // TODO: Detect other modules to load
- // pts_auto_modules_ready($modules_list);
+ pts_auto_modules_ready($modules_list);
+ $GLOBALS["PTS_MODULE_CURRENT"] = FALSE;
// Clean-up modules list
array_unique($modules_list);
diff --git a/pts-core/modules/system_monitor.php b/pts-core/modules/system_monitor.php
index 11124f5..70ffcbf 100644
--- a/pts-core/modules/system_monitor.php
+++ b/pts-core/modules/system_monitor.php
@@ -299,11 +299,9 @@ class system_monitor extends pts_module_interface
if(pts_gd_available())
{
$image_list = array();
- pts_save_user_file();
- pts_save_user_file(null, null, "/pts-monitor-viewer/");
- pts_copy(RESULTS_VIEWER_DIR . "pts-monitor-viewer.html", PTS_MONITOR_DIR . "pts-monitor-viewer.html");
- pts_copy(RESULTS_VIEWER_DIR . "pts.js", PTS_MONITOR_DIR . "pts-monitor-viewer/pts.js");
- pts_copy(RESULTS_VIEWER_DIR . "pts-viewer.css", PTS_MONITOR_DIR . "pts-monitor-viewer/pts-viewer.css");
+ pts_module::copy_file(RESULTS_VIEWER_DIR . "pts-monitor-viewer.html", "pts-monitor-viewer.html");
+ pts_module::copy_file(RESULTS_VIEWER_DIR . "pts.js", "pts-monitor-viewer/pts.js");
+ pts_module::copy_file(RESULTS_VIEWER_DIR . "pts-viewer.css", "pts-monitor-viewer/pts-viewer.css");
$image_count = 0;
foreach($type_index as $key => $sub_array)
@@ -334,9 +332,8 @@ class system_monitor extends pts_module_interface
$first_run = false;
}
}
-
$t->loadGraphVersion(PTS_VERSION);
- $t->save_graph(PTS_MONITOR_DIR . THIS_RUN_TIME . '-' . $image_count . ".png");
+ $t->save_graph(pts_module::save_dir() . THIS_RUN_TIME . '-' . $image_count . ".png");
$t->renderGraph();
array_push($image_list, THIS_RUN_TIME . '-' . $image_count . ".png");
@@ -360,9 +357,10 @@ class system_monitor extends pts_module_interface
if(count($m_array[0]) > 1 && !empty($url))
{
- file_put_contents(PTS_MONITOR_DIR . "link-latest.html", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"><html><head><title>Phoronix Test Suite</title><meta http-equiv=\"REFRESH\" content=\"0;url=pts-monitor-viewer.html#$url\"></HEAD><BODY></BODY></HTML>
+ $file = pts_module::save_file("link-latest.html", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"><html><head><title>Phoronix Test Suite</title><meta http-equiv=\"REFRESH\" content=\"0;url=pts-monitor-viewer.html#$url\"></HEAD><BODY></BODY></HTML>
");
- display_web_browser(PTS_MONITOR_DIR . "link-latest.html");
+ if($file != FALSE)
+ display_web_browser($file);
}
}
diff --git a/pts-core/objects/pts_module.php b/pts-core/objects/pts_module.php
new file mode 100644
index 0000000..a7fee6b
--- /dev/null
+++ b/pts-core/objects/pts_module.php
@@ -0,0 +1,95 @@
+<?php
+
+/*
+ Phoronix Test Suite "Trondheim"
+ URLs: http://www.phoronix.com, http://www.phoronix-test-suite.com/
+ Copyright (C) 2008, Phoronix Media
+ Copyright (C) 2004-2008, Michael Larabel
+ pts_module_interface.php: The generic Phoronix Test Suite module object that is extended by the specific modules/plug-ins
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+class pts_module
+{
+ public static function save_dir()
+ {
+ $prefix_dir = PTS_USER_DIR . "local/";
+
+ if(!is_dir($prefix_dir))
+ mkdir($prefix_dir);
+
+ return $prefix_dir . self::module_name() . "/";
+ }
+ public static function save_file($file, $contents = NULL)
+ {
+ // Saves a file for a module
+
+ $save_base_dir = self::save_dir();
+
+ if(!is_dir($save_base_dir))
+ mkdir($save_base_dir);
+
+ if(($extra_dir = dirname($file)) != "." && !is_dir($save_base_dir . $extra_dir))
+ mkdir($save_base_dir . $extra_dir);
+
+ if(!empty($contents))
+ {
+ if(file_put_contents($save_base_dir . $file, $contents) != FALSE)
+ return $save_base_dir . $file;
+ }
+
+ return FALSE;
+ }
+ public static function copy_file($from_file, $to_file)
+ {
+ // Copy a file for a module
+
+ $save_base_dir = self::save_dir();
+
+ if(!is_dir($save_base_dir))
+ mkdir($save_base_dir);
+
+ if(($extra_dir = dirname($to_file)) != "." && !is_dir($save_base_dir . $extra_dir))
+ mkdir($save_base_dir . $extra_dir);
+
+
+ if(is_file($from_file) && (!is_file($save_base_dir . $to_file) || md5_file($from_file) != md5_file($save_base_dir . $to_file)))
+ if(copy($from_file, $save_base_dir . $to_file))
+ return $save_base_dir . $to_file;
+
+ return FALSE;
+ }
+ private static function module_name()
+ {
+ $module_name = "unknown";
+
+ if($GLOBALS["PTS_MODULE_CURRENT"] != FALSE)
+ {
+ $module_name = $GLOBALS["PTS_MODULE_CURRENT"];
+ }
+ else
+ {
+ $bt = debug_backtrace();
+
+ for($i = 0; $i < count($bt) && $module_name == "unknown"; $i++)
+ if($bt[$i]["class"] != "pts_module")
+ $module_name = $bt[$i]["class"];
+ }
+
+ return $module_name;
+ }
+}
+
+?>