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
39 manumora
import threading
32 manumora
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
40 manumora
logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG)

41 manumora
def checkmd5File(pathFileName):
md5File = pathFileName+'.md5'
39 manumora
if not os.path.isfile(md5File):
41 manumora
md5Hash = MyUtils.getMD5Hash(pathFileName+'.iso')
f = open(md5File, 'wt')
39 manumora
f.write(md5Hash)
f.close()

# publish files (Avahi)
def publishFiles():
published = []

while True:
listFiles = os.listdir(downloadsPath)
for i in listFiles:
if os.path.isfile(downloadsPath + i) and i.endswith('.iso'):
fileName = MyUtils.getFileName(os.path.basename(i))
41 manumora
pathFileName = downloadsPath + fileName
39 manumora
41 manumora
checkmd5File(pathFileName)
39 manumora
service = ZeroconfService.ZeroconfService(name = str(portWebServer)+"@"+i, port=3000, stype = "_autoclone_"+classroomName+"._tcp") #, domain="replicant", host="localhost", text="Esto es una prueba")
service.publish()

published.append(service)

time.sleep(300) #refresh in seconds
for i in published:
i.unpublish()

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

40 manumora
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)

39 manumora
t = threading.Thread(target=publishFiles)
t.start()
32 manumora
39 manumora
t2 = threading.Thread(target=startWebServer)
t2.start()
32 manumora
39 manumora
32 manumora
#server.socket.close()
#service.unpublish()