blob: 35859a52f7c4b64dcee615fd31f1a9293e7094bb [file] [log] [blame]
Norman Jamesf066e872015-10-07 15:29:51 -05001#!/usr/bin/env python
2
3import sys
4import gobject
5import dbus
6import dbus.service
7import dbus.mainloop.glib
8import tftpy
Norman James408920d2015-10-08 07:02:45 -05009import Openbmc
10if (len(sys.argv) < 2):
11 print "Usage: download_manager.py [system name]"
12 exit(1)
13System = __import__(sys.argv[1])
Norman Jamesf066e872015-10-07 15:29:51 -050014
15
16DBUS_NAME = 'org.openbmc.managers.Download'
17OBJ_NAME = '/org/openbmc/managers/Download'
18TFTP_PORT = 69
Norman Jamesf066e872015-10-07 15:29:51 -050019
20class DownloadManagerObject(dbus.service.Object):
21 def __init__(self,bus,name):
22 dbus.service.Object.__init__(self,bus,name)
Norman Jamesf066e872015-10-07 15:29:51 -050023 bus.add_signal_receiver(self.DownloadHandler,
Norman James166acf42015-10-22 07:11:51 -050024 dbus_interface = "org.openbmc.Flash", signal_name = "Download", path_keyword = "path")
Norman Jamesf066e872015-10-07 15:29:51 -050025
Norman James18998182015-10-11 21:54:53 -050026 @dbus.service.signal(DBUS_NAME,signature='ss')
27 def DownloadComplete(self,outfile,filename):
Norman Jamesf066e872015-10-07 15:29:51 -050028 print "Download Complete: "+outfile
29 return outfile
30
Norman James18998182015-10-11 21:54:53 -050031 @dbus.service.signal(DBUS_NAME,signature='s')
32 def DownloadError(self,filename):
Norman Jamesf066e872015-10-07 15:29:51 -050033 pass
34
Norman James166acf42015-10-22 07:11:51 -050035 def DownloadHandler(self,url,filename,path = None):
Norman Jamesf066e872015-10-07 15:29:51 -050036 try:
37 filename = str(filename)
38 client = tftpy.TftpClient(url, TFTP_PORT)
39 print "Downloading: "+filename+" from "+url
Norman James408920d2015-10-08 07:02:45 -050040 outfile = System.FLASH_DOWNLOAD_PATH+"/"+filename
Norman Jamesf066e872015-10-07 15:29:51 -050041 client.download(filename,outfile)
Norman James166acf42015-10-22 07:11:51 -050042 obj = bus.get_object("org.openbmc.control.Flash",path)
43 intf = dbus.Interface(obj,"org.openbmc.Flash")
44 intf.update(outfile)
Norman Jamesf066e872015-10-07 15:29:51 -050045
46 except Exception as e:
47 print "ERROR DownloadManager: "+str(e)
Norman James166acf42015-10-22 07:11:51 -050048 obj = bus.get_object("org.openbmc.control.Flash",path)
49 intf = dbus.Interface(obj,"org.openbmc.Flash")
50 intf.error("Download Error: "+filename)
Norman Jamesf066e872015-10-07 15:29:51 -050051
52
53if __name__ == '__main__':
54 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
Norman James5e792e32015-10-07 17:36:17 -050055 bus = Openbmc.getDBus()
Norman Jamesf066e872015-10-07 15:29:51 -050056 name = dbus.service.BusName(DBUS_NAME, bus)
57 obj = DownloadManagerObject(bus, OBJ_NAME)
58 mainloop = gobject.MainLoop()
59
60 print "Running Download Manager"
61 mainloop.run()
62