#!/usr/bin/python
# Import the CGI module
import cgi
from os import system
# Required header that tells the browser how to render the HTML.
print "Content-Type: text/html\n\n"
def listImages():
#get image list
images = []
imCnt = 0
cmd = 'ls /var/www/images/tn > temp'
system(cmd)
fin = open('temp', 'r')
line = fin.read()
fin.close()
files = line.split('\n')
files.reverse()
for fil in files:
if fil[-4:] == '.jpg' and imCnt < 10:
images.append(fil)
imCnt += 1
#display images
print 'Take Snapshot
'
print ''
def showImage(imName):
thisIm = imName[3:]
try:
imPath = '/var/www/images/' + thisIm
fin = open(imPath, 'r')
fin.close()
print '
'
except:
print 'Image not present, downloading from FlexStack...'
requestImage(imName)
def requestThumbnail():
print 'requesting new snapshot
'
system('python /tmp/pyHostController.py')
def requestImage(thumbName):
system('python /tmp/pyHostController.py -c ' + '"LG' + thumbName + '"' )
def printHead():
print "\n"
print "\n"
print "\tInfo Form\n"
print "\n"
print "\n"
def printFoot():
print "\n"
print "\n"
# Define main function.
def main():
printHead()
print '| '
print 'Boston Engineering FlexStack'
print ' |
'
print '| '
form = cgi.FieldStorage()
if form.has_key('image'):
listImages()
print ' | '
showImage(form['image'].value)
print ' |
'
elif form.has_key('capture'):
requestThumbnail()
listImages()
print ''
print ' | '
else:
listImages()
print ''
print ' | '
printFoot()
# Call main function.
main()