Revisión 39
Añadido por Manu Mora Gordillo hace más de 14 años
main.py | ||
---|---|---|
import time
|
||
import WebServer
|
||
import MyUtils
|
||
import threading
|
||
|
||
LOG_FILENAME = "/var/log/autocloneserver.log"
|
||
rootPath = "/var/lib/autocloneserver"
|
||
... | ... | |
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):
|
||
... | ... | |
if not os.path.exists(downloadsPath):
|
||
os.mkdir(downloadsPath)
|
||
|
||
while True:
|
||
listFiles = os.listdir(downloadsPath)
|
||
t = threading.Thread(target=publishFiles)
|
||
t.start()
|
||
|
||
if len(listFiles) == 0:
|
||
time.sleep(300) #in seconds
|
||
else:
|
||
# publish files (Avahi)
|
||
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'
|
||
t2 = threading.Thread(target=startWebServer)
|
||
t2.start()
|
||
|
||
if not os.path.isfile(md5File):
|
||
md5Hash = MyUtils.getMD5Hash(downloadsPath + i)
|
||
f = open(md5File,'wt')
|
||
f.write(md5Hash)
|
||
f.close()
|
||
|
||
service = ZeroconfService.ZeroconfService(name = str(portWebServer)+"@"+i, port=3000, stype = "_autoclone_"+classroomName+"._tcp") #, domain="replicant", host="localhost", text="Esto es una prueba")
|
||
service.publish()
|
||
|
||
# Start web server
|
||
server = HTTPServer(('', portWebServer), WebServer.MyHandler)
|
||
server.serve_forever()
|
||
|
||
|
||
#server.socket.close()
|
||
#service.unpublish()
|
Exportar a: Unified diff
Añado threads, ya detecta nuevas isos