summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEudyptula <eitan@mosenkis.net>2009-06-24 18:33:43 -0400
committerEudyptula <eitan@mosenkis.net>2009-06-24 18:33:43 -0400
commit914460bfd5cb42be7c7df043475e54e79029a727 (patch)
tree3f1a5549c183834ccd10bb8f77f1e552a419b36f /frontend
parentMerged minor updates from SQL into sql_row_obj-based classes (diff)
downloadingenue-914460bfd5cb42be7c7df043475e54e79029a727.tar.gz
ingenue-914460bfd5cb42be7c7df043475e54e79029a727.tar.bz2
ingenue-914460bfd5cb42be7c7df043475e54e79029a727.zip
Cleaned up various unused bits of code; moved finished images to their own directory; moved ANSI text processing from logviewer into its own class; added unique ID to profiles table
Diffstat (limited to 'frontend')
-rw-r--r--frontend/classes/ansi.php54
-rw-r--r--frontend/css/ansi.css63
-rw-r--r--frontend/pages/downloadimage.php2
-rw-r--r--frontend/pages/logview.php41
-rw-r--r--frontend/wizard/step1.php4
5 files changed, 123 insertions, 41 deletions
diff --git a/frontend/classes/ansi.php b/frontend/classes/ansi.php
new file mode 100644
index 0000000..45c0462
--- /dev/null
+++ b/frontend/classes/ansi.php
@@ -0,0 +1,54 @@
+<?php
+class ansi_to_html {
+ var $spans=0;
+ public function process($txt) {
+ // Clear to end of line
+ $txt=str_replace("\x1b[K", '', $txt);
+ // Backspace
+ while (($i=strpos($txt, chr(8))) !== false) {
+ if ($i == 0) {
+ $txt=substr($txt, 1);
+ } elseif ($i == 1) {
+ $txt=substr($txt, 2);
+ } elseif ($i == strlen($txt)-1) {
+ $txt=substr($txt, 0, strlen($txt)-1);
+ } else {
+ $txt=substr($txt, 0, $i-1).substr($txt, $i+1);
+ }
+ }
+ return preg_replace_callback('#\e\[(?:(?:([0-9]{1,2});)*([0-9]{1,2}))?m#', array($this, 'ansi_callback'), $txt);
+ }
+ private function ansi_callback($match) {
+ if (count($match) <= 1) {
+ return $this->reset();
+ }
+ // Extra spaces after dim and blink are intentional
+ $a=explode(' ', 'bright dim underscore blink reverse hidden');
+ $c=explode(' ', 'black red green yellow blue magenta cyan white');
+ $r='';
+ for ($i=1; $i<count($match); $i++) {
+ $n=(int)$match[$i];
+ if ($n == 0) {
+ $r.=str_repeat('</span>', $this->spans);
+ $this->spans=0;
+ } elseif ($n <= 8) {
+ if ($a[$n-1]) {
+ $r.='<span class="ansi-'.$a[$n-1].'">';
+ $this->spans++;
+ }
+ } elseif (30 <= $n && $n <= 37) {
+ $r.='<span class="ansi-'.$c[$n-30].'fg">';
+ $this->spans++;
+ } elseif (40 <= $n && $n <= 47) {
+ $r.='<span class="ansi-'.$c[$n-40].'bg">';
+ $this->spans++;
+ }
+ }
+ return $r;
+ }
+ public function reset() {
+ return str_repeat('</span>', $this->spans);
+ $this->spans=0;
+ }
+}
+?>
diff --git a/frontend/css/ansi.css b/frontend/css/ansi.css
new file mode 100644
index 0000000..24ce781
--- /dev/null
+++ b/frontend/css/ansi.css
@@ -0,0 +1,63 @@
+span.ansi-bright {
+}
+span.ansi-dim {
+}
+span.ansi-underscore {
+ text-decoration: underline;
+}
+span.ansi-blink {
+ text-decoration: blink;
+}
+span.ansi-reverse {
+}
+span.ansi-hidden {
+ display: none;
+}
+span.ansi-blackfg {
+ color: black;
+}
+span.ansi-redfg {
+ color: red;
+}
+span.ansi-greenfg {
+ color: green;
+}
+span.ansi-yellowfg {
+ color: yellow;
+}
+span.ansi-bluefg {
+ color: blue;
+}
+span.ansi-magentafg {
+ color: rgb(255, 0, 255);
+}
+span.ansi-cyanfg {
+ color: rgb(0, 255, 255);
+}
+span.ansi-whitefg {
+ color: white;
+}
+span.ansi-blackbg {
+ background-color: black;
+}
+span.ansi-redbg {
+ background-color: red;
+}
+span.ansi-greenbg {
+ background-color: green;
+}
+span.ansi-yellowbg {
+ background-color: yellow;
+}
+span.ansi-bluebg {
+ background-color: blue;
+}
+span.ansi-magentabg {
+ background-color: rgb(255, 0, 255);
+}
+span.ansi-cyanbg {
+ background-color: rgb(0, 255, 255);
+}
+span.ansi-whitebg {
+ background-color: white;
+}
diff --git a/frontend/pages/downloadimage.php b/frontend/pages/downloadimage.php
index b3632e3..aaa48b3 100644
--- a/frontend/pages/downloadimage.php
+++ b/frontend/pages/downloadimage.php
@@ -14,7 +14,7 @@ function init_downloadimage() {
return '404';
}
$build=new sql_build($r->fetch(PDO::FETCH_ASSOC));
- $S['file']=WORK.'/build-'.$build->id.'/image.tar.gz';
+ $S['file']=COMPLETED.'/build-'.$build->id.'.tar.gz';
if (!is_file($S['file'])) {
debug('downloadimage', 'image file '.$S['file'].' not found');
return '404';
diff --git a/frontend/pages/logview.php b/frontend/pages/logview.php
index 7672933..e8a9528 100644
--- a/frontend/pages/logview.php
+++ b/frontend/pages/logview.php
@@ -48,12 +48,14 @@ function body_logview() {
$r=$S['pdo']->query('SELECT * FROM `commandlogs` WHERE `task`='.$task->id.' ORDER BY `order` ASC LIMIT '.$conf['logview_max'].' OFFSET '.($page-1)*$conf['logview_max']);
if ($r->rowCount()) {
echo '<div style="font-family: monospace">';
+ $ansi=new ansi_to_html();
while ($entry=$r->fetch(PDO::FETCH_ASSOC)) {
$entry=new sql_commandlog_entry($entry);
// $text=str_replace(array("\n", "\t"), array("<br/>\n", str_repeat('&nbsp;', 4)), htmlentities($entry->text));
// echo '<a name="entry_'.$task->id.'_'.$entry->order.'"'.($entry->stream=='stderr'?' style="color: red" ':'').' title="'.strtoupper($entry->stream).', entry #'.$entry->order.' @ '.date('D j M Y @ H:i:s', $entry->timestamp).' UTC">'.$text.'</a>';
- echo process_ansi($entry->text);
+ echo $ansi->process(nl2br($entry->text));
}
+ echo $ansi->reset(); // Clear any leftover <span>s
echo '</div>';
echo $pager;
echo '<a href="'.url('logs/build'.$task->build).'">Back</a><br/>';
@@ -88,41 +90,4 @@ function body_logview() {
}
}
}
-function process_ansi($txt) {
- $txt=str_replace("\x1b[K", '', nl2br($txt));
- do {
- $txt=preg_replace('#.\ch#', '', $txt, -1, $count); // ^H = Backspace
- } while ($count);
- return preg_replace_callback('#\e\[(?:(?:([0-9]{1,2});)*([0-9]{1,2}))?m#', 'ansi_callback', $txt);
-}
-function ansi_callback($match) {
- $a=explode(' ', 'bright dim underscore blink reverse hidden');
- $c=explode(' ', 'black red green yellow blue magenta cyan white');
- static $spans=0;
- $r='';
- if (count($match) == 1) {
- $r.=str_repeat('</span>', $spans);
- $spans=0;
- } else {
- for ($i=1; $i<count($match); $i++) {
- $n=(int)$match[$i];
- if ($n == 0) {
- $r.=str_repeat('</span>', $spans);
- $spans=0;
- } elseif ($n <= 8) {
- if ($a[$n-1]) {
- $r.='<span style="'.$a[$n-1].'">';
- $spans++;
- }
- } elseif (30 <= $n && $n <= 37) {
- $r.='<span style="color: '.$c[$n-30].'">';
- $spans++;
- } elseif (40 <= $n && $n <= 47) {
- $r.='<span style="background-color: '.$c[$n-40].'">';
- $spans++;
- }
- }
- }
- return $r;
-}
?>
diff --git a/frontend/wizard/step1.php b/frontend/wizard/step1.php
index cb8d2bf..878fc40 100644
--- a/frontend/wizard/step1.php
+++ b/frontend/wizard/step1.php
@@ -11,14 +11,14 @@ function wizard_body_step1() {
while ($profile=$r->fetch(PDO::FETCH_ASSOC)) {
$profile=new sql_profile($profile);
$display=$profile->name?$profile->name:($profile->pkgdir?$profile->pkgdir:'/');
- echo '<option value="'.htmlentities($profile->pkgdir).'">'.htmlentities($display).'</option>';
+ echo '<option value="'.$profile->id.'">'.htmlentities($display).'</option>';
}
echo '</select><br/>';
}
function wizard_process_step1() {
global $S, $request;
$profile=new sql_profile($request['pkgdir']);
- $profileopt=new sql_buildopt($S['wizard.build']->id, 'profile', $profile->pkgdir);
+ $profileopt=new sql_buildopt($S['wizard.build']->id, 'profile', $profile->id);
$profileopt->write();
}
?>