From d33af3bb8d6a09592d58114b6aee2d735bee8020 Mon Sep 17 00:00:00 2001 From: Ben Lebherz Date: Tue, 16 Oct 2018 14:38:09 +0200 Subject: [PATCH 1/2] introduce some common python coding styles, remove mixed tabs/spaces and unused imports --- tools/fw_server/fw-server.py | 73 +++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 31 deletions(-) diff --git a/tools/fw_server/fw-server.py b/tools/fw_server/fw-server.py index 867d89709..8d20b9793 100644 --- a/tools/fw_server/fw-server.py +++ b/tools/fw_server/fw-server.py @@ -1,22 +1,24 @@ #!/usr/bin/env python3 +# coding=utf-8 """ - fw-server.py - firmware server for Sonoff-Tasmota OTA upgrade +fw-server.py - firmware server for Sonoff-Tasmota OTA upgrade - Copyright (C) 2018 Gennaro Tortone +Copyright (C) 2018 Gennaro Tortone - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . - You should have received a copy of the GNU General Public License - along with this program. If not, see . Requirements: - Python3 @@ -31,26 +33,28 @@ Instructions: Firmware Upgrade -> Upgrade by web server http://:5000/sonoff-minimal.bin + Usage: - ./fw-server.py -d (default: eth0) - or - ./fw-server.py -i + ./fw-server.py -d (default: eth0) + or + ./fw-server.py -i Example: - ./fw-server.py -d wlan0 - or - ./fw-server.py -i 192.168.1.10 + ./fw-server.py -d wlan0 + or + ./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,23 +62,30 @@ 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'] - except Exception as e: - print("E: network interface error - {}".format(e)) - exit(1) + try: + netip = ni.ifaddresses(options.netdev)[ni.AF_INET][0]['addr'] + except Exception as e: + print("E: network interface error - {}".format(e)) + exit(1) else: - netip = options.ip + netip = options.ip + app = Flask(__name__) + @app.route('/') 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: From c8a04e88b0949fde40a1d8cd4e0fc9231c202c36 Mon Sep 17 00:00:00 2001 From: Ben Lebherz Date: Tue, 16 Oct 2018 15:03:18 +0200 Subject: [PATCH 2/2] remove empty line to trigger travis (staled) once again --- tools/fw_server/fw-server.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/fw_server/fw-server.py b/tools/fw_server/fw-server.py index 8d20b9793..536c76785 100644 --- a/tools/fw_server/fw-server.py +++ b/tools/fw_server/fw-server.py @@ -1,6 +1,5 @@ #!/usr/bin/env python3 # coding=utf-8 - """ fw-server.py - firmware server for Sonoff-Tasmota OTA upgrade