summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEudyptula <eitan@mosenkis.net>2009-06-23 19:20:43 -0400
committerEudyptula <eitan@mosenkis.net>2009-06-23 19:20:43 -0400
commit6d04b1a4f2a37852f5e546e96e252c54c3d770e6 (patch)
tree83de4eb8a5c8356d15d6cf25cec8c65b29d919ff /frontend
parentIntegrated basic ANSI handling into logviewer, needs to be merged with logvie... (diff)
downloadingenue-6d04b1a4f2a37852f5e546e96e252c54c3d770e6.tar.gz
ingenue-6d04b1a4f2a37852f5e546e96e252c54c3d770e6.tar.bz2
ingenue-6d04b1a4f2a37852f5e546e96e252c54c3d770e6.zip
Major improvements to logging in frontend and backend; moved log_command function to sql_task class; minor fixes here and there
Diffstat (limited to 'frontend')
-rw-r--r--frontend/css/build.css40
-rw-r--r--frontend/css/task.css29
-rw-r--r--frontend/functions/display_time.php35
-rw-r--r--frontend/functions/throw_exception.php5
-rw-r--r--frontend/include/footer.php2
-rw-r--r--frontend/pages/downloadimage.php32
-rw-r--r--frontend/pages/logview.php35
-rw-r--r--frontend/pages/passthrough.php8
-rw-r--r--frontend/pages/welcome.php11
-rw-r--r--frontend/routing.csv3
10 files changed, 166 insertions, 34 deletions
diff --git a/frontend/css/build.css b/frontend/css/build.css
new file mode 100644
index 0000000..7ae7345
--- /dev/null
+++ b/frontend/css/build.css
@@ -0,0 +1,40 @@
+div.build {
+ margin: 1em;
+ border: 1px dotted green;
+ padding: 1em;
+}
+div.build span.name {
+ font-size: 120%;
+}
+div.build span.status {
+ font-size: 95%;
+}
+div.build span.status.failed {
+ color: red;
+}
+div.build span.status.successful {
+ color: green;
+}
+div.build span.status.building {
+ background-color: black;
+ color: yellow;
+}
+div.build span.status.queued {
+ background-color: yellow;
+}
+div.build span.status.config {
+ color: teal;
+}
+div.build span.links {
+ font-size: 90%;
+}
+div.build span.links a:visited {
+ color: blue;
+}
+div.build div.time {
+ font-size: 90%;
+}
+div.build div.time span.time {
+ font-family: monospace;
+ font-weight: bold;
+}
diff --git a/frontend/css/task.css b/frontend/css/task.css
new file mode 100644
index 0000000..d3e9892
--- /dev/null
+++ b/frontend/css/task.css
@@ -0,0 +1,29 @@
+div.task {
+ font-family: monospace;
+}
+div.task span.command {
+ font-size: 110%;
+ font-weight: bold;
+}
+div.task span.status {
+ font-weight: bold;
+}
+div.task span.status.successful {
+ color: green;
+}
+div.task span.status.failed {
+ color: red;
+}
+div.task span.status.running {
+ color: yellow;
+ background-color: black;
+}
+div.task span.status.queued {
+ background-color: yellow
+}
+div.task span.time span.time {
+ font-weight: bold;
+}
+div.task a {
+ color: blue;
+}
diff --git a/frontend/functions/display_time.php b/frontend/functions/display_time.php
new file mode 100644
index 0000000..8c3cbce
--- /dev/null
+++ b/frontend/functions/display_time.php
@@ -0,0 +1,35 @@
+<?php
+// Returns a nice two-piece human-friendly length of time from the given number of seconds
+function display_time($n) {
+ $s=$n%60;
+ $n-=$s;
+ $n/=60;
+ $m=$n%60;
+ $n-=$m;
+ $n/=60;
+ $h=$n%24;
+ $n-=$h;
+ $n/=24;
+ $d=$n%365;
+ $n-=$d;
+ $n/=365;
+ $y=$n;
+ $array=array(
+ 'y' => $y,
+ 'd' => $d,
+ 'h' => $h,
+ 'm' => $m,
+ 's' => $s
+ );
+ $r=array();
+ foreach ($array as $label => $val) {
+ if ($val > 0) {
+ $r[]="$val $label";
+ if (count($r) == 2) {
+ break;
+ }
+ }
+ }
+ return $r?implode(' ', $r):'0 s';
+}
+?>
diff --git a/frontend/functions/throw_exception.php b/frontend/functions/throw_exception.php
deleted file mode 100644
index 6a9c288..0000000
--- a/frontend/functions/throw_exception.php
+++ /dev/null
@@ -1,5 +0,0 @@
-<?php
-function throw_exception($msg='') {
- throw new Exception($msg);
-}
-?>
diff --git a/frontend/include/footer.php b/frontend/include/footer.php
index 1f2f241..96ba9b9 100644
--- a/frontend/include/footer.php
+++ b/frontend/include/footer.php
@@ -5,7 +5,7 @@ if (isset($S['start'])) {
$diff=round(microtime(true)-$S['start'], 3);
echo 'Execution took '.$diff.' seconds.<br/>'."\n";
}
-echo '&#169; Eitan Mosenkis '.date('Y').'</div>';
+echo /*'&#169; Eitan Mosenkis '.date('Y').*/'</div>';
if ($conf['debug']) {
echo '<br/><div id="debug"><div class="heading" onclick="toggledebugbox()">Debug (<span id="debugcount">'.$S['debugrow'].'</span>) <span id="debugactions">[<a href="javascript:cleardebug()" id="debugclear">Clear</a>] [<a href="javascript:closedebug()" id="debugclose">X</a>]</span></div><div id="debugbox">'./*$state->debug.*/'</div></div>'."\n";
echo '<script type="text/javascript">
diff --git a/frontend/pages/downloadimage.php b/frontend/pages/downloadimage.php
new file mode 100644
index 0000000..b3632e3
--- /dev/null
+++ b/frontend/pages/downloadimage.php
@@ -0,0 +1,32 @@
+<?php
+function init_downloadimage() {
+ global $S, $request;
+ if (!isset($S['user'])) {
+ return 'login';
+ }
+ if (!isset($request['build']) || !preg_match('/^[a-zA-Z0-9]{6}$/', $request['build'])) {
+ debug('downlaodimage', 'No build or badly formatted build requested');
+ return '404';
+ }
+ $r=$S['pdo']->query('SELECT * FROM `builds` WHERE `owner`='.$S['user']->id.' AND `id`="'.$request['build'].'"');
+ if ($r->rowCount() == 0) {
+ debug('downloadimage', 'build not found or not owned by user');
+ return '404';
+ }
+ $build=new sql_build($r->fetch(PDO::FETCH_ASSOC));
+ $S['file']=WORK.'/build-'.$build->id.'/image.tar.gz';
+ if (!is_file($S['file'])) {
+ debug('downloadimage', 'image file '.$S['file'].' not found');
+ return '404';
+ }
+ contenttype('application/x-gzip');
+ header('Content-Length: '.filesize($S['file']));
+ header('Content-Description: File Transfer');
+ header('Content-Transfer-Encoding: binary');
+ header('Content-Disposition: attachment; filename="ingenue-'.$build->id.'.tar.gz"');
+}
+function body_downloadimage() {
+ global $S;
+ readfile($S['file']);
+}
+?>
diff --git a/frontend/pages/logview.php b/frontend/pages/logview.php
index 90a1fc9..2884c48 100644
--- a/frontend/pages/logview.php
+++ b/frontend/pages/logview.php
@@ -13,7 +13,9 @@ function body_logview() {
return;
}
$task=new sql_task($r->fetch(PDO::FETCH_ASSOC));
- echo '<h3>Task '.$task->id.': '.$task->command.' ';
+ echo '<div style="font-size: 130%">'.$task->display().'</div>';
+ echo '<a href="'.url('logs/build'.$task->build).'">Back</a><br/>';
+/* echo '<h3>Task '.$task->id.': '.$task->command.' ';
if (isset($task->exit)) {
if ($task->exit == 0) {
echo '<span style="color: green">[completed]</span>';
@@ -23,7 +25,7 @@ function body_logview() {
} else {
echo '<span style="color: yellow">[running]</span>';
}
- echo '</h3>';
+ echo '</h3>';*/
$page=isset($request['page']) && is_numeric($request['page'])?$request['page']:1;
$count=$S['pdo']->query('SELECT COUNT(*) FROM `buildlogs` WHERE `task`='.$task->id)->fetch(PDO::FETCH_COLUMN);
$pager='';
@@ -54,6 +56,7 @@ function body_logview() {
}
echo '</div>';
echo $pager;
+ echo '<a href="'.url('logs/build'.$task->build).'">Back</a><br/>';
} else {
if ($count) {
echo print_error("There aren't $page pages. Try an <a href=\"".url('logs/task'.$task->id)."\">earlier page</a>.");
@@ -62,7 +65,8 @@ function body_logview() {
}
}
} elseif (isset($request['build']) && preg_match('/[a-z0-9]{6}/', $request['build'])) {
- echo '<h3>Build '.$request['build'].'</h3>';
+ $build=new sql_build($request['build']);
+ echo $build->display();
$r=$S['pdo']->query('SELECT * FROM `tasks` WHERE `build`="'.$request['build'].'" ORDER BY `id` ASC');
if ($r->rowCount() == 0) {
echo '<b>No tasks found.</b>';
@@ -70,23 +74,27 @@ function body_logview() {
$i=0;
while ($task=$r->fetch(PDO::FETCH_ASSOC)) {
$task=new sql_task($task);
- echo '<a href="'.url('logs/task'.$task->id).'">Task #'.++$i.'</a>: '.htmlentities($task->command).'<br/>';
+ echo $task->display();
+// echo '<a href="'.url('logs/task'.$task->id).'">Task #'.++$i.'</a>: '.htmlentities($task->command).'<br/>';
}
} else {
- $r=$S['pdo']->query('SELECT * FROM `builds` ORDER BY `ctime` ASC');
+ $r=$S['pdo']->query('SELECT * FROM `builds` ORDER BY `ctime` IS NULL ASC, `ctime` ASC, `status` DESC');
if ($r->rowCount() == 0) {
echo print_warning('No builds found.');
}
while ($build=$r->fetch(PDO::FETCH_ASSOC)) {
$build=new sql_build($build);
- echo '<a href="'.url('logs/build'.$build->id).'">Build '.$build->id.'</a>: ';
- if (isset($build->name)) {
- echo htmlentities($build->name);
- }
- echo '<br/>';
+ echo $build->display();
}
}
}
+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');
@@ -117,11 +125,4 @@ function ansi_callback($match) {
}
return $r;
}
-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);
-}
?>
diff --git a/frontend/pages/passthrough.php b/frontend/pages/passthrough.php
index b8f0268..fd989f1 100644
--- a/frontend/pages/passthrough.php
+++ b/frontend/pages/passthrough.php
@@ -34,6 +34,14 @@ function init_passthrough() {
case 'php':
$S['notemplates']=true;
break;
+ case 'gz':
+ case 'gzip':
+ contenttype('application/x-gzip');
+ break;
+ case 'tbz2':
+ case 'bz2':
+ contenttype('application/bzip2');
+ break;
default:
debug('passthrough', 'Unknown extension '.$request['ext']);
return '404';
diff --git a/frontend/pages/welcome.php b/frontend/pages/welcome.php
index 3c7da87..d326f08 100644
--- a/frontend/pages/welcome.php
+++ b/frontend/pages/welcome.php
@@ -3,19 +3,8 @@ function init_welcome() {
global $S;
$S['title']='Welcome';
}
-function print_query($q) {
- echo '<pre>'.$q.'</pre>';
- global $S;
- $S['pdo']->query($q);
-}
function body_welcome() {
global $S;
echo '<h2>Welcome</h2>';
- $e=new sql_buildlog_entry();
-// print_query($e->drop_table());
-// print_query($e->create_table());
- $e=new sql_task();
-// print_query($e->drop_table());
-// print_query($e->create_table());
}
?>
diff --git a/frontend/routing.csv b/frontend/routing.csv
index 3d21751..841529d 100644
--- a/frontend/routing.csv
+++ b/frontend/routing.csv
@@ -14,12 +14,15 @@
# Logs
^logs$ logview
^logs/build([a-z0-9]{6})$ logview build
+^logs/build([a-z0-9]{6})/live$ livelog build
^logs/task([0-9]+)$ logview task
^logs/task([0-9]+)/([0-9]+)$ logview task page
# Build creation
^create$ wizard
^create/([a-zA-Z0-9]{6})$ wizard build
^create/([a-zA-Z0-9]{6})/([0-9]+)$ wizard build step
+# Download finished image
+^download/([a-zA-Z0-9]{6})$ downloadimage build
# Session
^login$ login
^logout$ logout