blob: 2a4cab926cd1c647b2c0218b3246f5a588eed364 [file] [log] [blame]
Norman James42c1be82015-10-22 14:34:26 -05001#!/usr/bin/python -u
Norman Jamesf066e872015-10-07 15:29:51 -05002
3import sys
4import gobject
5import dbus
6import dbus.service
7import dbus.mainloop.glib
Norman James408920d2015-10-08 07:02:45 -05008import Openbmc
9if (len(sys.argv) < 2):
10 print "Usage: download_manager.py [system name]"
11 exit(1)
12System = __import__(sys.argv[1])
Norman Jamesf066e872015-10-07 15:29:51 -050013
14
15DBUS_NAME = 'org.openbmc.managers.Download'
16OBJ_NAME = '/org/openbmc/managers/Download'
17TFTP_PORT = 69
Norman Jamesf066e872015-10-07 15:29:51 -050018
19class DownloadManagerObject(dbus.service.Object):
20 def __init__(self,bus,name):
21 dbus.service.Object.__init__(self,bus,name)
Norman Jamesf066e872015-10-07 15:29:51 -050022 bus.add_signal_receiver(self.DownloadHandler,
Norman James166acf42015-10-22 07:11:51 -050023 dbus_interface = "org.openbmc.Flash", signal_name = "Download", path_keyword = "path")
Norman Jamesf066e872015-10-07 15:29:51 -050024
Norman James18998182015-10-11 21:54:53 -050025 @dbus.service.signal(DBUS_NAME,signature='ss')
26 def DownloadComplete(self,outfile,filename):
Norman Jamesf066e872015-10-07 15:29:51 -050027 print "Download Complete: "+outfile
28 return outfile
29
Norman James18998182015-10-11 21:54:53 -050030 @dbus.service.signal(DBUS_NAME,signature='s')
31 def DownloadError(self,filename):
Norman Jamesf066e872015-10-07 15:29:51 -050032 pass
33
Norman James166acf42015-10-22 07:11:51 -050034 def DownloadHandler(self,url,filename,path = None):
Norman Jamesf066e872015-10-07 15:29:51 -050035 try:
36 filename = str(filename)
Norman Jamesf066e872015-10-07 15:29:51 -050037 print "Downloading: "+filename+" from "+url
Norman James408920d2015-10-08 07:02:45 -050038 outfile = System.FLASH_DOWNLOAD_PATH+"/"+filename
Norman James8af7d4a2016-01-06 14:09:08 -060039 subprocess.call(["tftp", "-l",outfile,"-r",filename,"-g",url])
Norman James166acf42015-10-22 07:11:51 -050040 obj = bus.get_object("org.openbmc.control.Flash",path)
41 intf = dbus.Interface(obj,"org.openbmc.Flash")
42 intf.update(outfile)
Norman James8af7d4a2016-01-06 14:09:08 -060043
Norman Jamesf066e872015-10-07 15:29:51 -050044 except Exception as e:
45 print "ERROR DownloadManager: "+str(e)
Norman James166acf42015-10-22 07:11:51 -050046 obj = bus.get_object("org.openbmc.control.Flash",path)
47 intf = dbus.Interface(obj,"org.openbmc.Flash")
48 intf.error("Download Error: "+filename)
Norman Jamesf066e872015-10-07 15:29:51 -050049
50
51if __name__ == '__main__':
52 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
Norman James5e792e32015-10-07 17:36:17 -050053 bus = Openbmc.getDBus()
Norman Jamesf066e872015-10-07 15:29:51 -050054 name = dbus.service.BusName(DBUS_NAME, bus)
55 obj = DownloadManagerObject(bus, OBJ_NAME)
56 mainloop = gobject.MainLoop()
57
58 print "Running Download Manager"
59 mainloop.run()
60