mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-23 18:56:38 +00:00
Merge pull request #4084 from benleb/pythonic-fw-server
introduce common python coding styles & other codestyle fixes
This commit is contained in:
commit
d9b9eeef1f
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# coding=utf-8
|
||||
"""
|
||||
fw-server.py - firmware server for Sonoff-Tasmota OTA upgrade
|
||||
|
||||
@ -18,6 +18,7 @@
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
Requirements:
|
||||
- Python3
|
||||
- pip install netifaces flask
|
||||
@ -31,6 +32,7 @@ Instructions:
|
||||
Firmware Upgrade -> Upgrade by web server
|
||||
http://<ip_address>:5000/sonoff-minimal.bin
|
||||
|
||||
|
||||
Usage:
|
||||
./fw-server.py -d <net_iface> (default: eth0)
|
||||
or
|
||||
@ -42,15 +44,16 @@ Example:
|
||||
./fw-server.py -i 192.168.1.10
|
||||
"""
|
||||
|
||||
import io
|
||||
import os.path
|
||||
from sys import exit
|
||||
from flask import Flask, send_file
|
||||
from optparse import OptionParser
|
||||
from sys import exit
|
||||
|
||||
from flask import Flask, send_file
|
||||
import netifaces as ni
|
||||
|
||||
|
||||
usage = "usage: fw-server {-d | -i} arg"
|
||||
|
||||
parser = OptionParser(usage)
|
||||
parser.add_option("-d", "--dev", action="store", type="string",
|
||||
dest="netdev", default="eth0", help="network interface (default: eth0)")
|
||||
@ -58,6 +61,8 @@ parser.add_option("-i", "--ip", action="store", type="string",
|
||||
dest="ip", help="IP address to bind")
|
||||
(options, args) = parser.parse_args()
|
||||
|
||||
netip = None
|
||||
|
||||
if options.ip is None:
|
||||
try:
|
||||
netip = ni.ifaddresses(options.netdev)[ni.AF_INET][0]['addr']
|
||||
@ -67,14 +72,19 @@ if options.ip is None:
|
||||
else:
|
||||
netip = options.ip
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
|
||||
@app.route('/<filename>')
|
||||
def fw(filename):
|
||||
if(os.path.exists("fw/" + str(filename))):
|
||||
return send_file("fw/" + str(filename), attachment_filename=filename, mimetype='application/octet-stream')
|
||||
else:
|
||||
return("ERROR: file not found")
|
||||
if os.path.exists("fw/" + str(filename)):
|
||||
return send_file("fw/" + str(filename),
|
||||
attachment_filename=filename,
|
||||
mimetype='application/octet-stream')
|
||||
|
||||
return "ERROR: file not found"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
|
Loading…
x
Reference in New Issue
Block a user