Proyecto

General

Perfil

import ZeroconfService
from BaseHTTPServer import HTTPServer
import logging
import os
import time
import WebServer
import MyUtils
import threading

LOG_FILENAME = "/var/log/autocloneserver.log"
rootPath = "/var/lib/autocloneserver"
downloadsPath = rootPath + "/www/"
portWebServer = 8000
classroomName = MyUtils.getClassroomName()

def checkmd5File(md5File):
if not os.path.isfile(md5File):
md5Hash = MyUtils.getMD5Hash(downloadsPath + i)
f = open(md5File,'wt')
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))
md5File = downloadsPath + fileName + '.md5'

checkmd5File(md5File)

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()

if __name__ == '__main__':

if not os.path.exists(rootPath):
os.mkdir(rootPath)

if not os.path.exists(downloadsPath):
os.mkdir(downloadsPath)

t = threading.Thread(target=publishFiles)
t.start()

t2 = threading.Thread(target=startWebServer)
t2.start()

#server.socket.close()
#service.unpublish()
(4-4/4)