| 1 |
nino.borges |
668 |
"""
|
| 2 |
|
|
|
| 3 |
|
|
HomeAutomationStatusReport
|
| 4 |
|
|
|
| 5 |
|
|
Created by
|
| 6 |
|
|
Emanuel Borges
|
| 7 |
|
|
08.29.2013
|
| 8 |
|
|
|
| 9 |
|
|
This program will create an HTML report on the system and send to my website. Will take system
|
| 10 |
|
|
name as argument.
|
| 11 |
|
|
|
| 12 |
|
|
"""
|
| 13 |
|
|
|
| 14 |
|
|
import sys,os,subprocess, time
|
| 15 |
|
|
|
| 16 |
|
|
def GatherSizeStats():
|
| 17 |
|
|
proc = subprocess.Popen(["df -kh","/"], stdout=subprocess.PIPE, shell=True)
|
| 18 |
|
|
(out, err) = proc.communicate()
|
| 19 |
|
|
#print "program output:", out
|
| 20 |
|
|
#s = os.statvfs('/')
|
| 21 |
|
|
#(s.f_bavail * s.f_frsize) / 1024
|
| 22 |
|
|
## os.system('df -k /')
|
| 23 |
|
|
#return os.system('df -h /')
|
| 24 |
|
|
return out
|
| 25 |
|
|
|
| 26 |
|
|
def GatherMovieTvInfo():
|
| 27 |
|
|
pass
|
| 28 |
|
|
|
| 29 |
|
|
def CreateHTMLReport(rawSizeTable, workstationName):
|
| 30 |
|
|
#rawSizeTable = rawSizeTable.replace("\n","</tr>")
|
| 31 |
|
|
lnBuffer = "<tr><th>"
|
| 32 |
|
|
rawSizeTable2 = []
|
| 33 |
|
|
for i in rawSizeTable:
|
| 34 |
|
|
if i == "\n":
|
| 35 |
|
|
i.replace("\n","</tr>")
|
| 36 |
|
|
rawSizeTable2.append(lnBuffer)
|
| 37 |
|
|
lnBuffer = ""
|
| 38 |
|
|
else:
|
| 39 |
|
|
lnBuffer = lnBuffer + i
|
| 40 |
|
|
|
| 41 |
|
|
#rawSizeTable = list(rawSizeTable,"\n")
|
| 42 |
|
|
headder = rawSizeTable2[0]
|
| 43 |
|
|
#headder = headder.replace("|","")
|
| 44 |
|
|
headder = ' '.join(headder.split())
|
| 45 |
|
|
headder = headder.replace(" ","</th><th>")+"</th></tr>"
|
| 46 |
|
|
headder = headder.replace("<th>Mounted</th><th>on</th>", '<th>Mounted on</th>')
|
| 47 |
|
|
|
| 48 |
|
|
body = ""
|
| 49 |
|
|
#for x in rawSizeTable2[1:]:
|
| 50 |
|
|
# body = body + x + "\n"
|
| 51 |
|
|
for x in rawSizeTable2[1:]:
|
| 52 |
|
|
if x[0] == "/":
|
| 53 |
|
|
x = ' '.join(x.split())
|
| 54 |
|
|
x = x.replace(" ","</td><td>")+"</td></tr>\n\n"
|
| 55 |
|
|
body = body + "<tr><td>" + x
|
| 56 |
|
|
htmlTable = '<body>\n\n <h1>%s</h1>\n\n <h3>Collected on %s</h3>\n\n <table border="1" cellpadding=10>\n'%(workstationName,time.strftime('%Y%m%d')) + headder + "\n"+ body +"</table>\n\n</Body>"
|
| 57 |
|
|
return htmlTable
|
| 58 |
|
|
|
| 59 |
|
|
def UploadReport():
|
| 60 |
|
|
pw = '9utj11!!'
|
| 61 |
|
|
|
| 62 |
|
|
|
| 63 |
|
|
|
| 64 |
|
|
|
| 65 |
|
|
|
| 66 |
|
|
if __name__ == '__main__':
|
| 67 |
|
|
try:
|
| 68 |
|
|
systemName = sys.argv[1]
|
| 69 |
|
|
except:
|
| 70 |
|
|
print "Please pass a system name as the first argument."
|
| 71 |
|
|
if systemName:
|
| 72 |
|
|
print "Now gathering size for %s..."% systemName
|
| 73 |
|
|
rawSizeTable = GatherSizeStats()
|
| 74 |
|
|
htmlTable = CreateHTMLReport(rawSizeTable,systemName)
|
| 75 |
|
|
outputFile = open('/Users/ninoborges/Documents/temp/homeauto.html','w')
|
| 76 |
|
|
outputFile.write(htmlTable)
|
| 77 |
|
|
outputFile.close()
|
| 78 |
|
|
|
| 79 |
|
|
|