blob: dbf7c8e245fba7c977a52577b101750e7525bd94 [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
9
10
11
12DBUS_NAME = 'org.openbmc.managers.Download'
13OBJ_NAME = '/org/openbmc/managers/Download'
14TFTP_PORT = 69
15DOWNLOAD_DIR = '/tmp'
16
17class DownloadManagerObject(dbus.service.Object):
18 def __init__(self,bus,name):
19 dbus.service.Object.__init__(self,bus,name)
Norman Jamesf066e872015-10-07 15:29:51 -050020 bus.add_signal_receiver(self.DownloadHandler,
21 dbus_interface = "org.openbmc.Flash", signal_name = "Download")
22
23 @dbus.service.signal(DBUS_NAME,signature='s')
24 def DownloadComplete(self,outfile):
25 print "Download Complete: "+outfile
26 return outfile
27
28 @dbus.service.signal(DBUS_NAME)
29 def DownloadError(self):
30 pass
31
32 def DownloadHandler(self,url,filename):
33 try:
34 filename = str(filename)
35 client = tftpy.TftpClient(url, TFTP_PORT)
36 print "Downloading: "+filename+" from "+url
37 outfile = DOWNLOAD_DIR+"/"+filename
38 client.download(filename,outfile)
39 self.DownloadComplete(outfile)
40
41 except Exception as e:
42 print "ERROR DownloadManager: "+str(e)
43 self.DownloadError()
44
45
46
47if __name__ == '__main__':
48 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
Norman James5e792e32015-10-07 17:36:17 -050049 bus = Openbmc.getDBus()
Norman Jamesf066e872015-10-07 15:29:51 -050050 name = dbus.service.BusName(DBUS_NAME, bus)
51 obj = DownloadManagerObject(bus, OBJ_NAME)
52 mainloop = gobject.MainLoop()
53
54 print "Running Download Manager"
55 mainloop.run()
56