blob: 9dd6c2d5cd4ea3ed925224db28bbbd691c1b5db5 [file] [log] [blame]
#!/usr/bin/python -u
import sys
import gobject
import dbus
import dbus.service
import dbus.mainloop.glib
import subprocess
from obmc.dbuslib.bindings import get_dbus
import obmc_system_config as System
DBUS_NAME = 'org.openbmc.managers.Download'
OBJ_NAME = '/org/openbmc/managers/Download'
TFTP_PORT = 69
class DownloadManagerObject(dbus.service.Object):
def __init__(self,bus,name):
dbus.service.Object.__init__(self,bus,name)
bus.add_signal_receiver(self.DownloadHandler,
dbus_interface = "org.openbmc.Flash",
signal_name = "Download", path_keyword = "path")
bus.add_signal_receiver(self.TftpDownloadHandler,
signal_name = "TftpDownload", path_keyword = "path")
@dbus.service.signal(DBUS_NAME,signature='ss')
def DownloadComplete(self,outfile,filename):
print "Download Complete: "+outfile
return outfile
@dbus.service.signal(DBUS_NAME,signature='s')
def DownloadError(self,filename):
pass
def TftpDownloadHandler(self,ip,filename,path = None):
try:
filename = str(filename)
print "Downloading: "+filename+" from "+ip
outfile = System.FLASH_DOWNLOAD_PATH+"/"+filename
rc = subprocess.call(["tftp", "-l",outfile,"-r",filename,"-g",ip])
if (rc == 0):
self.DownloadComplete(outfile,filename)
else:
self.DownloadError(filename)
except Exception as e:
print "ERROR DownloadManager: "+str(e)
self.DownloadError(filename)
## TODO: this needs to be deprecated. Shouldn't call flash interface from here
def DownloadHandler(self,url,filename,path = None):
try:
filename = str(filename)
print "Downloading: "+filename+" from "+url
outfile = System.FLASH_DOWNLOAD_PATH+"/"+filename
subprocess.call(["tftp", "-l",outfile,"-r",filename,"-g",url])
obj = bus.get_object("org.openbmc.control.Flash",path)
intf = dbus.Interface(obj,"org.openbmc.Flash")
intf.update(outfile)
except Exception as e:
print "ERROR DownloadManager: "+str(e)
obj = bus.get_object("org.openbmc.control.Flash",path)
intf = dbus.Interface(obj,"org.openbmc.Flash")
intf.error("Download Error: "+filename)
if __name__ == '__main__':
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = get_dbus()
name = dbus.service.BusName(DBUS_NAME, bus)
obj = DownloadManagerObject(bus, OBJ_NAME)
mainloop = gobject.MainLoop()
print "Running Download Manager"
mainloop.run()