1. Dan Boitnott
  2. prise

Commits

Dan Boitnott  committed b07492c

Beginnings of output display

  • Participants
  • Parent commits 03a0400
  • Branches default

Comments (0)

Files changed (4)

File src/resources/static/global.css

View file
  • Ignore whitespace
 * {
     margin: 0;
     padding: 0;
+    font-family: sans-serif;
 }
 
 body * {
     padding: 10px;
 }
 
+pre {
+    font-family: monospace;
+}
+
 .TaskBox {
     border: 1px solid black;
     padding: 5px;
 }
 
 .CommandTask {
-    background-color: rgba(255, 255, 0, 0.52);
+
 }
+
+.notRun {
+    background-color: #d0d0ff;
+}
+
+.goodRun {
+    background-color: #d0ffd0;
+}
+
+.viewOutputForm {
+    font-size: small;
+    font-weight: bold;
+    border-top: 1px dashed #454545;
+    margin-top: 5px;
+    padding-top: 5px;
+}

File src/resources/templates/index.mustache

View file
  • Ignore whitespace
 <h1>PRISE:{{request.server_name}}:{{dirname}}</h1>
 
 {{#tasks}}
-    <div class="TaskBox {{class}}">
+    <div class="TaskBox {{class}} {{colorClass}}">
         <pre>{{lines}}</pre>
+        {{#isCommandTask}}
+            {{#hasOutput}}
+                <form class="viewOutputForm">
+                    Output:
+                    <select>
+                        {{#output}}<option value="{{hash}}.{{ts}}">{{ts}}</option>{{/output}}
+                    </select>
+                    <input type="submit" name="action" value="View"/>
+                </form>
+            {{/hasOutput}}
+        {{/isCommandTask}}
     </div>
 {{/tasks}}
 

File src/state.py

View file
  • Ignore whitespace
 import os
 import socket
 import threading
+import glob
 
 import util
 import output
             curCmdLog.close()
             curCmdLog = None
 
+def getCommandOutputPath(cmd, ts):
+    return os.path.join(runDir, "cmd.%s.%s.log" % (util.cmdHash(cmd.strip()), ts))
+
 def logCommand(cmd):
     with curCmdLogLock:
         global curCmdLog
             closeCmdLog()
 
         cmd = cmd.strip()
-        fname = "cmd.%s.%s.log" % (util.cmdHash(cmd), util.timestamp())
-        curCmdLog = open(os.path.join(runDir, fname), "w")
+        curCmdLog = open(getCommandOutputPath(cmd, util.timestamp()), "w")
         util.writeFileHeader(curCmdLog, { "Command" : cmd,
                                           "Started" : util.prettyTimestamp(),
                                           "Host" : socket.gethostname()})
     logCommand(cmd)
     sendToShell(cmd + "\n")
 
+def getCommandOutputTimes(cmd, desc = True):
+    """Returns the timestamps for each run of a given command."""
+
+    if type(cmd) is scripts.CommandTask:
+        # Extract the command from the task
+        cmd = cmd.content.strip()
+    elif type(cmd) is scripts.CommentTask:
+        # Deal gracefully with being asked for output times on comments
+        return []
+    else:
+        cmd = cmd.strip()
+
+    glb = getCommandOutputPath(cmd, '*')
+    return sorted([os.path.basename(p).split('.', 2)[2][:-4] for p in glob.glob(glb)], reverse=desc)
+
+def getCommandOutput(cmd, ts):
+    """Returns the output of a command run at the given timestamp. ts should exactly match the one returned from
+       getCommandOutputTimes()"""
+
+    fp = open(getCommandOutputPath(cmd, ts), 'r')
+    with fp:
+        return fp.read()
+
 def printToUser(msg, reprompt = True):
     # Print to STDERR so that it won't be sent to the shell
     print >>sys.stderr, "\r\n", msg.replace("\n", "\n\r"), "\r"

File src/web.py

View file
  • Ignore whitespace
 import pystache
 import state
 import scripts
+import util
 
 RESOURCES = "resources"
 STATIC = "static"
         self.log_message
         tasks = []
         for task in state.script:
+            times = state.getCommandOutputTimes(task)
+            output = [{"ts": ts} for ts in times]
+
+            # Determine box color
+            if type(task) is scripts.CommandTask:
+                if len(times) < 1:
+                    colorClass = 'notRun'
+                else:
+                    colorClass = 'goodRun'
+            else:
+                colorClass = '' # Comments are all colored the same
+
             tasks.append({
                 "class"         : task.__class__.__name__,
                 "isCommentTask" : type(task) is scripts.CommentTask,
                 "isCommandTask" : type(task) is scripts.CommandTask,
                 "content"       : task.content,
-                "lines"         : "\n".join(task.getLines())
+                "hash"          : util.cmdHash(task.content),
+                "lines"         : "\n".join(task.getLines()),
+                "colorClass"    : colorClass,
+                "output"        : output,
+                "hasOutput"     : len(output) > 0
             })
 
         self.sendTemplate("index", tasks=tasks, dirname=os.path.basename(os.getcwd()))