2019-05-15 21:04:09 +00:00
|
|
|
import socket
|
|
|
|
import os
|
|
|
|
from opendm import log
|
|
|
|
|
|
|
|
PROGRESS_BROADCAST_PORT = 6367 #ODMR
|
|
|
|
try:
|
|
|
|
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
|
|
|
except:
|
|
|
|
log.ODM_WARNING("Cannot create UDP socket, progress reporting will be disabled.")
|
|
|
|
sock = None
|
|
|
|
|
|
|
|
class Broadcaster:
|
|
|
|
def __init__(self, port):
|
|
|
|
self.port = port
|
|
|
|
self.project_name = "<unnamed>"
|
|
|
|
self.pid = os.getpid()
|
|
|
|
|
|
|
|
def set_project_name(self, project_name):
|
|
|
|
self.project_name = project_name
|
|
|
|
|
2019-05-20 20:29:51 +00:00
|
|
|
def send_update(self, global_progress):
|
2019-05-15 21:04:09 +00:00
|
|
|
"""
|
|
|
|
Update any listener on the pipeline progress (in percentage terms)
|
|
|
|
"""
|
|
|
|
if not sock:
|
|
|
|
return
|
|
|
|
|
|
|
|
UDP_IP = "127.0.0.1"
|
|
|
|
|
|
|
|
if global_progress > 100:
|
2019-05-21 16:38:30 +00:00
|
|
|
log.ODM_WARNING("Global progress is > 100 (%s), please contact the developers." % global_progress)
|
2019-05-15 21:04:09 +00:00
|
|
|
global_progress = 100
|
|
|
|
|
|
|
|
try:
|
2020-09-09 17:23:53 +00:00
|
|
|
sock.sendto("PGUP/{}/{}/{}".format(self.pid, self.project_name, float(global_progress)).encode('utf8'),
|
|
|
|
(UDP_IP, self.port))
|
|
|
|
except Exception as e:
|
|
|
|
log.ODM_WARNING("Failed to broadcast progress update on UDP port %s (%s)" % (str(self.port), str(e)))
|
2019-05-15 21:04:09 +00:00
|
|
|
|
|
|
|
progressbc = Broadcaster(PROGRESS_BROADCAST_PORT)
|