Domotique/Updater.py

48 lines
1.3 KiB
Python
Raw Normal View History

2016-09-21 18:44:41 +02:00
#!/usr/bin/env python
2016-09-21 23:52:52 +02:00
# Gui to get parameters for espota.py
# espota.py is available https://raw.githubusercontent.com/esp8266/Arduino/master/tools/espota.py
# and should be in the same directory
2016-09-21 18:44:41 +02:00
from tkinter import *
from tkinter import filedialog
2016-09-21 23:31:14 +02:00
from tkinter.messagebox import *
2016-09-21 18:44:41 +02:00
import subprocess
2016-09-21 23:48:18 +02:00
class Updater(Frame):
file = None
2016-09-21 23:31:14 +02:00
2016-09-21 23:48:18 +02:00
def __init__(self, win, **kwargs):
Frame.__init__(self, win, **kwargs)
button_opt = {'fill': constants.BOTH, 'padx': 5, 'pady': 5}
Button(root, text='Select firmware',
command=self.askopenfile).pack(**button_opt)
2016-09-21 18:44:41 +02:00
2016-09-21 23:48:18 +02:00
self.ipEntry = Entry(root)
self.ipEntry.pack()
self.ipEntry.delete(0, END)
self.ipEntry.insert(0, "192.168.0.XX")
2016-09-21 18:44:41 +02:00
2016-09-21 23:48:18 +02:00
Button(root, text='Install', command=self.install).pack(pady=20)
2016-09-21 23:31:14 +02:00
2016-09-21 23:48:18 +02:00
def install(self):
ip = self.ipEntry.get()
print("Installing", self.file, "at ip", ip)
2016-09-21 18:44:41 +02:00
2016-09-21 23:48:18 +02:00
if self.file != None:
subprocess.call(["python", "espota.py", "-i", ip, "-f", self.file])
else:
showerror("Error", "Select a firmware first")
2016-09-21 18:44:41 +02:00
2016-09-21 23:48:18 +02:00
def askopenfile(self):
self.file = filedialog.askopenfilename(
title='Select Firmware', filetypes=[('binaries', '*.bin')])
2016-09-21 18:44:41 +02:00
2016-09-21 23:48:18 +02:00
root = Tk()
root.title("Firmware Updater")
2016-09-21 18:44:41 +02:00
2016-09-21 23:48:18 +02:00
updater = Updater(root)
updater.mainloop()
updater.destroy()