Proyecto

General

Perfil

32 manumora
import ZeroconfService
from BaseHTTPServer import HTTPServer
import os
33 manumora
import time
32 manumora
import WebServer
import MyUtils

33 manumora
rootPath = "/var/lib/autoclone"
downloadsPath = rootPath + "/www/"
32 manumora
portWebServer = 8000
classroom = "25"

if __name__ == '__main__':

33 manumora
if not os.path.exists(rootPath):
os.mkdir(rootPath)
32 manumora
33 manumora
if not os.path.exists(downloadsPath):
os.mkdir(downloadsPath)

32 manumora
while True:
33 manumora
listFiles = os.listdir(downloadsPath)
32 manumora
if len(listFiles) == 0:
time.sleep(300) #in seconds
else:
# publish files (Avahi)
for i in listFiles:
33 manumora
if os.path.isfile(downloadsPath + i) and i.endswith('.iso'):
32 manumora
fileName = MyUtils.getFileName(os.path.basename(i))
33 manumora
md5File = downloadsPath + fileName + '.md5'
32 manumora
if not os.path.isfile(md5File):
33 manumora
md5Hash = MyUtils.getMD5Hash(downloadsPath + i)
32 manumora
f = open(md5File,'wt')
f.write(md5Hash)
f.close()

33 manumora
service = ZeroconfService.ZeroconfService(name = str(portWebServer)+"@"+i, port=3000, stype = "_autoclone"+classroom+"._tcp") #, domain="replicant", host="localhost", text="Esto es una prueba")
32 manumora
service.publish()

# Start web server
server = HTTPServer(('', portWebServer), WebServer.MyHandler)
server.serve_forever()

#server.socket.close()
#service.unpublish()