Proyecto

General

Perfil

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

38 manumora
LOG_FILENAME = "/var/log/autocloneserver.log"
rootPath = "/var/lib/autocloneserver"
33 manumora
downloadsPath = rootPath + "/www/"
32 manumora
portWebServer = 8000
38 manumora
classroomName = MyUtils.getClassroomName()
32 manumora
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()

38 manumora
service = ZeroconfService.ZeroconfService(name = str(portWebServer)+"@"+i, port=3000, stype = "_autoclone_"+classroomName+"._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()