From d08c07b68d0e88d863f597fe5e9ed72d84229ab7 Mon Sep 17 00:00:00 2001 From: Romain d'Alverny Date: Wed, 4 May 2011 13:26:54 +0000 Subject: initial import --- Report/Box.php | 235 ++++++++++++++++++++++++++++++ Report/Box/02_SourcePackage.php | 69 +++++++++ Report/Box/03_BuildSystem.php | 115 +++++++++++++++ Report/Box/04_CauldronPackages.php | 146 +++++++++++++++++++ Report/Box/ignore_01_UpstreamProjects.php | 49 +++++++ Report/Box/ignore_05_CauldronISOBuild.php | 177 ++++++++++++++++++++++ Report/HTML.php | 132 +++++++++++++++++ 7 files changed, 923 insertions(+) create mode 100644 Report/Box.php create mode 100644 Report/Box/02_SourcePackage.php create mode 100644 Report/Box/03_BuildSystem.php create mode 100644 Report/Box/04_CauldronPackages.php create mode 100644 Report/Box/ignore_01_UpstreamProjects.php create mode 100644 Report/Box/ignore_05_CauldronISOBuild.php create mode 100644 Report/HTML.php (limited to 'Report') diff --git a/Report/Box.php b/Report/Box.php new file mode 100644 index 0000000..79408a0 --- /dev/null +++ b/Report/Box.php @@ -0,0 +1,235 @@ + + * @license MIT License, see LICENSE.txt + * @link http://svnweb.mageia.org/svn/soft/dashboard/ +*/ + +/** +*/ +abstract class Report_Box +{ + /** + */ + var $title = null; + + /** + */ + var $_new_values = null; + + /** + */ + var $working = false; + + /** + */ + function __construct() + { + $this->_labels = array_merge(array('?' => '%s %s'), + $this->_get_var_definitions()); + } + + /** + */ + final public function run_report() + { + $path = realpath(dirname(__FILE__)); + $files = glob(sprintf('%s/Box/*.php', $path)); + + foreach ($files as $f) { + if (substr(basename($f), 0, 7) != 'ignore_') + include $f; + } + + $reports = array(); + foreach (get_declared_classes() as $class) { + if (is_subclass_of($class, 'Report_Box')) { + echo $class, "\n"; + $c = new $class; + $reports[] = $c->render(); + } + } + + file_put_contents('report.html', Report_HTML::render($reports)); + } + + /** + * lowercase keys! + */ + final public function update() + { + $this->_get_new_values(); + $this->_db_save($this->_new_values); + } + + /** + */ + function render () + { + $this->load(); + + // associate key/values with string labels + // compute global statuts + // push + $status = count($this->_new_values); + $status_max = count($this->_new_values); + $links = $this->_get_links(); + $values = array(); + + $this->_tmp_labels = $this->_labels; + if (is_null($this->_new_values)) + $this->_new_values = array(); + + foreach ($this->_tmp_labels as $k => $v) { + //foreach ($this->_new_values as $k => $v) { + if ($k == '?') + continue; + + $v = $this->_render_value_gen($k); + + $status -= $v['s']; + $values[] = $v; + } + + if (count($this->_tmp_labels) > 0) { + foreach ($this->_tmp_labels as $k => $v) { + if ($k == '?') + continue; + + $values[] = $this->_render_value_gen($k); + } + } + + echo $status / $status_max; + + return array( + 'title' => $this->title, + 'status' => $status_max > 0 ? round($status / $status_max, 2) : 0, + 'values' => $values, + 'links' => $links + ); + } + + /** + */ + final private function _render_value_gen($k = null) + { + if (array_key_exists($k, $this->_tmp_labels)) { + + if ($this->_tmp_labels[$k] == ':render') { + $this->_cur_val = isset($this->_new_values[$k]) ? $this->_new_values[$k] : null; + $v = call_user_func(array($this, '_render_value_' . $k)); + unset($this->_cur_val); + } else { + $v = $this->_render_value_default($k, $this->_tmp_labels[$k]); + } + } else { + $v = $this->_render_value_default($k); + } + unset($this->_tmp_labels[$k]); + + return $v; + } + + /** + */ + final private function _render_value_default($k = null, $format = null) + { + $score = 0; + $class = 'unk'; + $weight = 1; + $test_case = null; + + if (is_null($format)) { + $format = '%s %s'; + } elseif (!is_string($format)) { + $test_case = $format['t']; + $format = $format['l']; + $weight = isset($format['w']) ? $format['w'] : $weight; + } + + $v = isset($this->_new_values[$k]) ? $this->_new_values[$k] : null; + if (!is_null($v)) { + if (!is_null($test_case)) { + $test_case = sprintf('$evalres = ($v %s);', $test_case); + eval($test_case); + + $class = $evalres === true ? 'ok' : 'failed'; + } else { + $class = 'ok'; + } + } else { + $class = 'unk'; + } + + if ($class == 'failed') + $score = -1; + elseif ($class == 'ok') + $score = 1; + + $score *= $weight; + + return array( + 't' => sprintf($format, $v, $k), + 'c' => $class, + 's' => $score + ); + } + + /** + */ + final public function load() + { + // go in table TABLE, load all most recent key/values + // + // TODO(rda) + $this->_get_new_values(); + $this->_values = array(); + } + + /** + */ + final private function _db_save($vals) + { + echo "Saving:\n"; + echo get_class($this),"\n"; + print_r($vals); + } + + /** + */ + final private function _get_new_values() + { + $values = null; + $methods = array(); + foreach (get_class_methods($this) as $m) { + if (substr($m, 0, 7) == '_fetch_') { + $methods[] = $m; + } + } + if (count($methods) == 0) { + echo '> Nothing to fetch.', "\n"; + } else { + $values = array(); + foreach ($methods as $m) { + echo sprintf("> Calling [%s]", $m), "\n"; + $values = array_merge($values, $this->$m()); + } + } + + $this->_new_values = $values; + } + + /** + */ + function _get_links() + { + return null; + } +} \ No newline at end of file diff --git a/Report/Box/02_SourcePackage.php b/Report/Box/02_SourcePackage.php new file mode 100644 index 0000000..9ba0039 --- /dev/null +++ b/Report/Box/02_SourcePackage.php @@ -0,0 +1,69 @@ + + * @license MIT License, see LICENSE.txt + * @link http://svnweb.mageia.org/svn/soft/dashboard/ +*/ + +/** +*/ +class Report_Box_SourcePackage extends Report_Box +{ + /** + */ + var $title = "Source packages"; + + /** + */ + function _get_var_definitions() { + return array( + 'size' => '%5.1fGB', + 'count-srpms' => '%d packages', + 'upstream-updates' => array('l' => '%d have an update', 't' => '==0'), + 'orphans' => array('l' => '%d orphans', 't' => '>0'), + 'patches' => '%d patches', + 'bugs' => array('l' => '%d open bugs', 't' => '>0'), + 'rpmlint' => array('l' => '%d rpmlint errors', 't' => '>0'), + ); + } + + /** + */ + function _get_links() + { + return 'View svn, youri-check report'; + } + + /** + * Uses youri-check updates report (check.mageia.org) + */ + function _fetch_upstream_updates() + { + $txt = file('http://check.mageia.org/updates.txt'); + return array( + 'upstream-updates'=> count($txt) - 5 + ); + } + + /** + * Uses sophie.zarb.org + */ + function _fetch_source_packages() + { + $count = substr_count( + file_get_contents('http://sophie.zarb.org/distrib/Mageia/cauldron/i586/srpms?json=1'), + 'pkgid' + ); + + return array( + 'count-srpms' => $count, + ); + } + +} diff --git a/Report/Box/03_BuildSystem.php b/Report/Box/03_BuildSystem.php new file mode 100644 index 0000000..b2d020d --- /dev/null +++ b/Report/Box/03_BuildSystem.php @@ -0,0 +1,115 @@ + + * @license MIT License, see LICENSE.txt + * @link http://svnweb.mageia.org/svn/soft/dashboard/ +*/ +/** +*/ +class Report_Box_PackageBuildSystem extends Report_Box +{ + /** + */ + var $title = "Packages Build (past 48 hours)"; + + /** + */ + function _get_var_definitions() { + return array( + 'x_bs_queue_uploaded' => ':render', //'%d packages uploaded', + 'x_bs_queue_failure' => array('l' => '%d failed to build', 't' => '==0', 'w' => 0), + 'x_bs_queue_rejected' => array('l' => '%d rejected', 't' => '==0', 'w' => 0), + 'x_bs_buildtime' => ':render', + 'x_bs_buildtime_average' => ':render', + 'nodes' => ':render', + 'queue_size_avg' => 'queue size: 4/0/20', + 'wait_time' => 'wait time: 5/2/45' + ); + } + /* + missing dependencies % + other + */ + + function _render_value_x_bs_buildtime() + { + return array( + 't' => sprintf('%5.2f hours of total buildtime
(%d%% of the time)', + $this->_cur_val / 60, + $this->_cur_val / 60 / 48 * 100 + ), + 'c' => 'ok', + 's' => 0 + ); + } + + function _render_value_x_bs_buildtime_average() + { + return array( + 't' => sprintf('%5.2f min of average buildtime', $this->_cur_val), + 'c' => 'ok', + 's' => 0 + ); + } + + function _render_value_nodes() + { + return array( + 't' => '? nodes working fine out of ?', + 'c' => 'unk', + 's' => 0 + ); + } + + function _render_value_x_bs_queue_uploaded() + { + return array( + 't' => sprintf('%d packages uploaded', $this->_cur_val), + 'c' => 'ok', + 's' => 0 + ); + } + + /** + */ + function _get_links() + { + return 'View pkgsubmit'; + } + + /** + * Fetch live report values from pkgsubmit HTTP headers, + * prefixed with X-BS- + * + * @return array + */ + function _fetch_buildsystem() + { + $ret = array(); + $h = get_headers('http://pkgsubmit.mageia.org/'); + foreach ($h as $v) + { + $v = explode(':', trim($v)); + if (substr($v[0], 0, 5) == 'X-BS-') + { + $k = str_replace('-', '_', strtolower($v[0])); + if (in_array($k, array( + 'x_bs_queue_todo', + 'x_bs_queue_building', + 'x_bs_queue_partial', + 'x_bs_queue_built', + 'x_bs_throttle' + ))) + continue; + $ret[$k] = trim($v[1]); + } + } + return $ret; + } +} diff --git a/Report/Box/04_CauldronPackages.php b/Report/Box/04_CauldronPackages.php new file mode 100644 index 0000000..c275f94 --- /dev/null +++ b/Report/Box/04_CauldronPackages.php @@ -0,0 +1,146 @@ + + * @license MIT License, see LICENSE.txt + * @link http://svnweb.mageia.org/svn/soft/dashboard/ +*/ + +/** +*/ +class Report_Box_CauldronPackages extends Report_Box +{ + /** + */ + var $title = "Cauldron Compiled Packages"; + + /** + */ + function _get_var_definitions() { + return array( + 'size' => '%5.1fGB', + 'count-i586-rpms' => '%d packages (i586)', + 'count-x86_64-rpms' => '%d packages (x86_64)', + 'broken-pkgs' => array('l' => '%d have broken dependencies', 't' => '<=0'), + 'obs-bin' => array('l' => '%d obsolete binaries', 't' => '<=0'), + 'obs-source' => array('l' => '%d obsolete sources', 't' => '<=0'), + 'mis-source' => array('l' => '%d missing sources', 't' => '<=0'), + 'missing-deps' => array('l' => '%d missing dependencies', 't' => '<=0') + ); + /* + ?GB + ? packages + Broken hdlist (i586/nonfree) + Signatures: 23 missing (i586/nonfree, i586/tainted) + Dependencies: 32 missing, 2 circular + 15 packages are not in sync with their source + 432 missing/broken signatures + 213 bugs + @todo: per package test suite? rpmlint, other + @todo: src => 32/64/arm + Basesystem size: 437MB, w/o suggests: 163MB + view repository, detailed report + + */ + } + + /** + */ + function _get_links() + { + return 'View youri-check report'; + } + + + /** + * Uses youri-check report. + */ + function _fetch_03_missing_dependencies() + { + $txt = file('http://check.mageia.org/missing.txt'); + array_shift($txt); + array_shift($txt); + array_shift($txt); + + $ret = array( + 'obs-source' => 0, + 'obs-bin' => 0, + 'mis-source' => 0 + ); + foreach ($txt as $l) + { + $l = explode("\t", $l); + if (!isset($l[3]) || !isset($l[5])) + continue; + + $arch = trim($l[3]); + $reason = substr(trim($l[5]), 0, 14); + if ($arch == 'src') { //&& $l[5], 'Obsolete source')) { + $ret['obs-source'] += 1; + } elseif ($reason == 'Missing source') { + $ret['mis-source'] += 1; + } elseif ($reason == 'Obsolete binar') { + $ret['obs-bin'] += 1; + } + } + return $ret; + } + + /** + * Uses youri-check report. + */ + function _fetch_02_broken_dependencies() + { + $txt = file('http://check.mageia.org/dependencies.txt'); + array_shift($txt); + array_shift($txt); + array_shift($txt); + + $package = null; + + $reports = array(); + foreach ($txt as $l) + { + $l = explode("\t", $l); + if (isset($l[0]) && isset($l[4])) { + $packages[] = trim($l[0]); + $missing[] = trim($l[4]); + } + } + + $packages = array_unique($packages); + sort($packages); + $missing = array_unique($missing); + sort($missing); + + return array( + 'broken-pkgs' => count($packages) - 1, + 'missing-deps' => count($missing) - 1 + ); + } + + /** + * Uses sophie.zarb.org + */ + function _fetch_01_packages() + { + $count_i586 = substr_count( + file_get_contents('http://sophie.zarb.org/distrib/Mageia/cauldron/i586/rpms?json=1'), + 'pkgid' + ); + $count_x86_64 = substr_count( + file_get_contents('http://sophie.zarb.org/distrib/Mageia/cauldron/x86_64/rpms?json=1'), + 'pkgid' + ); + + return array( + 'count-i586-rpms' => $count_i586, + 'count-x86_64-rpms' => $count_x86_64 + ); + } +} diff --git a/Report/Box/ignore_01_UpstreamProjects.php b/Report/Box/ignore_01_UpstreamProjects.php new file mode 100644 index 0000000..77f83cf --- /dev/null +++ b/Report/Box/ignore_01_UpstreamProjects.php @@ -0,0 +1,49 @@ + + * @license MIT License, see LICENSE.txt + * @link http://svnweb.mageia.org/svn/soft/dashboard/ +*/ + +/** +*/ +class Report_Box_UpstreamProjects extends Report_Box +{ + /** + */ + var $title = "Upstream Projects"; + + /** + */ + function _get_var_definitions() { + return array( + 'source-packages' => '%d source packages' + ); + } + + /** + */ + function _get_links() + { + return 'View detailed report (youri-check)'; + } + + /** + * Uses youri-check updates report. + */ + function _fetch_upstream_updates() + { + $txt = file('http://check.mageia.org/updates.txt'); + return array( + 'upstream-updates'=> count($txt) - 5 + ); + } +} diff --git a/Report/Box/ignore_05_CauldronISOBuild.php b/Report/Box/ignore_05_CauldronISOBuild.php new file mode 100644 index 0000000..254dcfb --- /dev/null +++ b/Report/Box/ignore_05_CauldronISOBuild.php @@ -0,0 +1,177 @@ + + * @license MIT License, see LICENSE.txt + * @link http://svnweb.mageia.org/svn/soft/dashboard/ +*/ + +/** +*/ +class Report_Box_CauldronISOBuild extends Report_Box +{ + /** + */ + var $title = "Cauldron ISO Build/QA/Pub"; + + /** + */ + function _get_var_definitions() { + return array( + ); + } + + /** + */ + function _get_links() + { + return 'View bcd site'; + } + + function render() + { + $obj = array( + array( + 'ts' => gmdate('c'), + 'type' => 'info', + 'value' => 'Built packages tree is not ready – no build planned.' + ), + array( + 'ts' => gmdate('c') - 5, + 'type' => 'info', + 'value' => 'Next build 1a1 should start in about 12 hours (at 2011-03-15 20:23:33), with a new context.' + ), + array( + 'ts' => gmdate('c') - 10, + 'type' => 'report', + 'build' => '1a0', + 'contextDiffLink' => '', + 'started_at' => '2011-03-14 23:03:15', + 'products' => array( + array( + 'name' => 'DVD i586', + 'build' => array(true, 'url'), + 'tests' => array(false, 'url'), + 'iso' => 'cauldron-2-dvd-i586-1a0-qafail.iso' + ), + array( + 'name' => 'DVD x86_64', + 'build' => array(true, 'url'), + 'tests' => array(true, 'url'), + 'iso' => 'cauldron-2-dvd-i586-1a0-qapass.iso' + ), + array( + 'name' => 'CD dual', + 'build' => array(false, 'url'), + 'tests' => null, + 'iso' => null + ), + array( + 'name' => 'netinstall', + 'build' => 'pending' + ) + ) + ) + ); + $values = array(); + foreach ($obj as $item) + { + if ($item['type'] == 'info') { + $values[] = array( + 't' => sprintf('

%s

', $item['value']), + 'c' => null + ); + } + elseif ($item['type'] == 'report') { + $lis = ''; + foreach ($item['products'] as $p) { + $st = $item['build'][0] ? 'ok' : 'failed'; + $lis .= <<{$p['name']}, + build {$st} (log), + tests {$st} (log), + {$p['iso']} +T; + } + $text = <<Build {$item['build']} + (context diff w/ build {$item['prev_build']}) + – {$item['ts']} +
    {$lis}
+T; + $values[] = array( + 't' => $text, + 'c' => null + ); + } + } + + return array( + 'title' => $this->title, + 'status' => 0, + 'values' => $values, + 'links' => $links + ); + } +/* +
  • DVD i586, + build ok (log), + tests failed (log), + cauldron-2-dvd-i586-1a0-qafail.iso
  • +
  • DVD x86_64, + build ok (log), + tests ok (log), + cauldron-2-dvd-i586-1a0-ok.iso
  • +
  • CD dual, + build failed (log)
  • +
  • building netinstall image...
  • + +
  • Build 199 + (context diff w/ build 198) + – 2011-03-12 23:03:15

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    ItemBuildTestsDownload
    DVD i586OK (log)OK (log)cauldron-2-1a0-dvd-i586-ok.iso
    DVD x86_64OK (log)FAILED (log)cauldron-2-1a0-dvd-x86_64-qafail.iso
    CD dualFAILED (log)
    netinstallOK (log)OK (log)cauldron-2-1a0-netinstall-ok.iso
    + +
  • + +*/ +} diff --git a/Report/HTML.php b/Report/HTML.php new file mode 100644 index 0000000..6e27f14 --- /dev/null +++ b/Report/HTML.php @@ -0,0 +1,132 @@ + + * @license MIT License, see LICENSE.txt + * @link http://svnweb.mageia.org/svn/soft/dashboard/ +*/ + +/** +*/ +class Report_HTML +{ + + /** + * + */ + function render($r) + { + $ret = ''; + foreach ($r as $r1) { + $lis = ''; + foreach ($r1['values'] as $v) + $lis .= sprintf('
  • %s
  • ', $v['c'], $v['t']); + + if ($r1['status'] >= 1) + $status = 'OK'; + elseif ($r1['status'] > 0.7) + $status = 'GOOD'; + elseif ($r1['status'] < 0.5) + $status = 'NOT READY'; + + $links = $r1['links']; + $ret .= <<

    {$r1['title']}

    +

    Status: {$status}

    +
      {$lis}
    +

    {$links}

    + +S; + } + $s = << + + + + + Mageia buildsystem status overview + + + +

    Mageia build chain dashboard

    +
      {$ret}
    + +
    +
    +
      +
    • Light gray values are unknown for now.
    • +
    • ISO Build block is still a mockup, doesn't work for now!
    • +
    • code is in svnweb.mageia.org/soft/dashboard; + to get a copy of the code:
      $ svn checkout svn://svn.mageia.org/svn/soft/dashboard
      + patches welcome!
    • +
    +
    + + +S; + return $s; + } +} \ No newline at end of file -- cgit v1.2.1