From 5defd02afad5be407327e888bf3b60a9510a13f5 Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Sun, 2 Aug 2020 13:45:05 -0700 Subject: [PATCH 1/2] Clean up minor warnings from LGTM.com LGTM (Semmie) is a tool, bought by GitHub last year, that conducts basic linting tasks on code and HTML. Clean up the warnings identified in the latest report: https://lgtm.com/projects/g/esp8266/Arduino/?mode=list No functionality should change, however this may fix some issues with the perl utilities not exiting properly on a Ctrl-C from the command line. --- .../examples/FSBrowser/data/edit/index.htm | 26 ++++++------- .../examples/Graph/data/index.htm | 8 ++-- .../BearSSL_CertStore/certs-from-mozilla.py | 8 ++-- package/upload_release.py | 5 --- tools/boards.txt.py | 37 +++++++++---------- tools/elf2bin.py | 4 +- tools/espota.py | 14 +++---- tools/makecorever.py | 6 +-- tools/signing.py | 1 - tools/upload.py | 2 +- 10 files changed, 50 insertions(+), 61 deletions(-) mode change 100644 => 100755 package/upload_release.py diff --git a/libraries/ESP8266WebServer/examples/FSBrowser/data/edit/index.htm b/libraries/ESP8266WebServer/examples/FSBrowser/data/edit/index.htm index 31c9613a0f..e2a9d08776 100644 --- a/libraries/ESP8266WebServer/examples/FSBrowser/data/edit/index.htm +++ b/libraries/ESP8266WebServer/examples/FSBrowser/data/edit/index.htm @@ -292,7 +292,7 @@ if (fsInfo.isOk) { var percent = (1+Math.round(99*fsInfo.usedBytes/fsInfo.totalBytes)); // fake to see the "used" bar in any case var text = readableSize(fsInfo.totalBytes - fsInfo.usedBytes) + " free of " + readableSize(fsInfo.totalBytes); - status += "" + text + "" + status += "" + text + ""; if (fsInfo.unsupportedFiles) { status += " WARNING" + "Filesystem contains unsupported filenames:
" @@ -358,7 +358,6 @@ function createHeader(element, tree, editor){ var header = document.getElementById(element); - var xmlHttp; var fileSelector = document.createElement("input"); fileSelector.type = "file"; fileSelector.multiple = false; @@ -422,12 +421,12 @@ } if (!pathInput.value.startsWith("/")) pathInput.value = "/" + pathInput.value; pathInput.value = getParentFolder(pathInput.value) + "/" + filename; - } + }; upload.onclick = function(e) { if (fileSelector.files.length === 0) return; tree.httpUpload(fileSelector.files[0], pathInput.value); - } + }; function mustFormat83() { return false; // TODO: if needed, test fsInfo.type (and fatType ?) @@ -466,15 +465,15 @@ save.onclick = function(e){ editor.save(); - } + }; discard.onclick = function(e){ editor.discard(); - } + }; help.onclick = function(e){ editor.showShortcuts(); - } + }; } @@ -731,7 +730,7 @@ e.preventDefault(); e.stopPropagation(); showContextMenu(e, leaf.id, false); - } + }; return leaf; } @@ -892,7 +891,7 @@ function httpList(parentPath, remainingPaths){ setLoading(true, "Listing '" + parentPath + "'..."); // Fetch an updated list - xmlHttp = new XMLHttpRequest(); + var xmlHttp = new XMLHttpRequest(); xmlHttp.onload = onListReceived(xmlHttp, parentPath, remainingPaths); xmlHttp.open("GET", "/list?dir="+parentPath, true); xmlHttp.send(null); @@ -909,7 +908,7 @@ this.httpUpload = function(file, path) { setLoading(true, "Uploading '" + path + "'..."); if (!path.startsWith("/")) path = "/" + path; - xmlHttp = new XMLHttpRequest(); + var xmlHttp = new XMLHttpRequest(); xmlHttp.onload = onOperationComplete(xmlHttp, path); var formData = new FormData(); formData.append("data", file, path); @@ -920,7 +919,7 @@ this.httpCreate = function(path){ setLoading(true, "Creating '" + path + "'..."); if (!path.startsWith("/")) path = "/" + path; - xmlHttp = new XMLHttpRequest(); + var xmlHttp = new XMLHttpRequest(); xmlHttp.onload = onOperationComplete(xmlHttp, path); var formData = new FormData(); formData.append("path", path); @@ -931,7 +930,7 @@ function httpRename(srcPath, dstPath){ setLoading(true, "Renaming '" + srcPath + "' to '" + dstPath + "'..."); if (!dstPath.startsWith("/")) dstPath = "/" + dstPath; - xmlHttp = new XMLHttpRequest(); + var xmlHttp = new XMLHttpRequest(); xmlHttp.onload = onOperationComplete(xmlHttp, dstPath); var formData = new FormData(); formData.append("path", dstPath); @@ -942,7 +941,7 @@ function httpDelete(path) { setLoading(true, "Deleting '" + path + "'..."); - xmlHttp = new XMLHttpRequest(); + var xmlHttp = new XMLHttpRequest(); xmlHttp.onload = onOperationComplete(xmlHttp); var formData = new FormData(); formData.append("path", path); @@ -1097,7 +1096,6 @@ function onBodyLoad(){ var vars = {}; - var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) { vars[key] = value; }); if (typeof ace != "undefined") { var editor = createEditor("editor", vars.file, vars.lang, vars.theme); } diff --git a/libraries/ESP8266WebServer/examples/Graph/data/index.htm b/libraries/ESP8266WebServer/examples/Graph/data/index.htm index 7eb5c1b18f..5d2715a6ba 100644 --- a/libraries/ESP8266WebServer/examples/Graph/data/index.htm +++ b/libraries/ESP8266WebServer/examples/Graph/data/index.htm @@ -350,8 +350,6 @@ // Response is e.g.: {"time":963074, "heap":47160, "analog":60, "gpioMask":16447, "gpioData":16405} var espData = JSON.parse(xmlHttp.responseText); - var x = espData.time; - var maxSamples = parseInt(document.getElementById("maxSamplesField").value); // Add point to heap chart @@ -387,7 +385,7 @@ if (espData.gpioMask & gpioBitMask) { // This GPIO must be part of the chart - dataset = allDigitalDatasets[gpio]; + var dataset = allDigitalDatasets[gpio]; // give it the next available color dataset.borderColor = gpioColors[position % gpioColors.length]; // add it to the chart @@ -412,7 +410,7 @@ // chart must be updated, otherwise adding to previously hidden dataset fail digitalChart.update(); - currentGpioMask = espData.gpioMask + currentGpioMask = espData.gpioMask; } @@ -428,7 +426,7 @@ // Add received value to dataset // console.log(espData.gpioData + " & " + gpioBitMask + " => " + (espData.gpioData & gpioBitMask)); data = dataset.data; - var point = {x: espData.time, y: (espData.gpioData & gpioBitMask)?1:0} + var point = {x: espData.time, y: (espData.gpioData & gpioBitMask)?1:0}; data.push(point); // limit number of samples to maxSamples diff --git a/libraries/ESP8266WiFi/examples/BearSSL_CertStore/certs-from-mozilla.py b/libraries/ESP8266WiFi/examples/BearSSL_CertStore/certs-from-mozilla.py index 556acb70fa..68881c709c 100755 --- a/libraries/ESP8266WiFi/examples/BearSSL_CertStore/certs-from-mozilla.py +++ b/libraries/ESP8266WiFi/examples/BearSSL_CertStore/certs-from-mozilla.py @@ -1,4 +1,4 @@ -#!/usr/bin/python3 +#!/usr/bin/env python3 # This script pulls the list of Mozilla trusted certificate authorities # from the web at the "mozurl" below, parses the file to grab the PEM @@ -14,11 +14,11 @@ from subprocess import Popen, PIPE, call try: from urllib.request import urlopen -except: +except Exception: from urllib2 import urlopen try: from StringIO import StringIO -except: +except Exception: from io import StringIO # Mozilla's URL for the CSV file with included PEM certs @@ -42,7 +42,7 @@ # Try and make ./data, skip if present try: os.mkdir("data") -except: +except Exception: pass derFiles = [] diff --git a/package/upload_release.py b/package/upload_release.py old mode 100644 new mode 100755 index 20390c2b11..9f547f99db --- a/package/upload_release.py +++ b/package/upload_release.py @@ -2,11 +2,6 @@ from github import Github import argparse -import collections -import glob -import json -import mimetypes -import os parser = argparse.ArgumentParser(description='Upload a set of files to a new draft release') parser.add_argument('--user', help="Github username", type=str, required=True) diff --git a/tools/boards.txt.py b/tools/boards.txt.py index 789f75714c..7be8f695dc 100755 --- a/tools/boards.txt.py +++ b/tools/boards.txt.py @@ -907,23 +907,23 @@ '1M', ], 'desc': [ - 'ESP8266 based devices from ITEAD: Sonoff SV, Sonoff TH, Sonoff Basic, ' + 'ESP8266 based devices from ITEAD: Sonoff SV, Sonoff TH, Sonoff Basic, ' + 'and Sonoff S20', '', - 'These are not development boards. The development process is ' - 'inconvenient with these devices. When flashing firmware you will ' + 'These are not development boards. The development process is ' + + 'inconvenient with these devices. When flashing firmware you will ' + 'need a Serial Adapter to connect it to your computer.', '', - ' | Most of these devices, during normal operation, are connected to ' - '*wall power (AKA Mains Electricity)*. **NEVER** try to flash these ' - 'devices when connected to *wall power*. **ALWAYS** have them ' - 'disconnected from *wall power* when connecting them to your ' + ' | Most of these devices, during normal operation, are connected to ' + + '*wall power (AKA Mains Electricity)*. **NEVER** try to flash these ' + + 'devices when connected to *wall power*. **ALWAYS** have them ' + + 'disconnected from *wall power* when connecting them to your ' + 'computer. Your life may depend on it!', '', - 'When flashing you will need to hold down the push button connected ' - 'to the GPIO0 pin, while powering up with a safe 3.3 Volt source. Some USB ' - 'Serial Adapters may supply enough power to handle flashing; ' - 'however, it many may not supply enough power to handle the ' + 'When flashing you will need to hold down the push button connected ' + + 'to the GPIO0 pin, while powering up with a safe 3.3 Volt source. Some USB ' + + 'Serial Adapters may supply enough power to handle flashing; ' + + 'however, it many may not supply enough power to handle the ' + 'activities when the device reboots.', '', 'More product details at the bottom of https://www.itead.cc/wiki/Product/' @@ -943,15 +943,14 @@ '1M', ], 'desc': [ - 'DOIT ESP-Mx DevKit - This is a development board by DOIT, with a DOIT ESP-Mx module ' - '(`datasheet `__) ' - 'using a ESP8285 Chip. With the DOIT ESP-Mx module, GPIO pins 9 and 10 are not available. ' - 'The DOIT ESP-Mx DevKit board has a red power LED and a blue LED connected to GPIO16 ' - 'and is active low to turn on. It uses a CH340C, USB to Serial converter chip. ' - '', - 'ESP8285 (`datasheet `__) ' - 'is a multi-chip package which contains ESP8266 and 1MB flash. ', + 'DOIT ESP-Mx DevKit - This is a development board by DOIT, with a DOIT ESP-Mx module ' + + '(`datasheet `__) ' + + 'using a ESP8285 Chip. With the DOIT ESP-Mx module, GPIO pins 9 and 10 are not available. ' + + 'The DOIT ESP-Mx DevKit board has a red power LED and a blue LED connected to GPIO16 ' + + 'and is active low to turn on. It uses a CH340C, USB to Serial converter chip. ', '', + 'ESP8285 (`datasheet `__) ' + + 'is a multi-chip package which contains ESP8266 and 1MB flash. ' ], }) diff --git a/tools/elf2bin.py b/tools/elf2bin.py index 4fc407b908..ffc3a62088 100755 --- a/tools/elf2bin.py +++ b/tools/elf2bin.py @@ -57,7 +57,7 @@ def get_segment_size_addr(elf, segment, path): def read_segment(elf, segment, path): fd, tmpfile = tempfile.mkstemp() os.close(fd) - p = subprocess.check_call([path + "/xtensa-lx106-elf-objcopy", '-O', 'binary', '--only-section=' + segment, elf, tmpfile], stdout=subprocess.PIPE) + subprocess.check_call([path + "/xtensa-lx106-elf-objcopy", '-O', 'binary', '--only-section=' + segment, elf, tmpfile], stdout=subprocess.PIPE) with open(tmpfile, "rb") as f: raw = f.read() os.remove(tmpfile) @@ -85,7 +85,7 @@ def write_bin(out, args, elf, segments, to_addr): try: for data in raw: checksum = checksum ^ ord(data) - except: + except Exception: for data in raw: checksum = checksum ^ data total_size += 1 diff --git a/tools/espota.py b/tools/espota.py index d6b5a80860..fbba90d18d 100755 --- a/tools/espota.py +++ b/tools/espota.py @@ -77,7 +77,7 @@ def serve(remoteAddr, localAddr, remotePort, localPort, password, filename, comm try: sock.bind(server_address) sock.listen(1) - except: + except Exception: logging.error("Listen Failed") return 1 @@ -100,11 +100,11 @@ def serve(remoteAddr, localAddr, remotePort, localPort, password, filename, comm logging.info('Sending invitation to: %s', remoteAddr) sock2 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) remote_address = (remoteAddr, int(remotePort)) - sent = sock2.sendto(message.encode(), remote_address) + sock2.sendto(message.encode(), remote_address) sock2.settimeout(10) try: data = sock2.recv(128).decode() - except: + except Exception: logging.error('No Answer') sock2.close() return 1 @@ -123,7 +123,7 @@ def serve(remoteAddr, localAddr, remotePort, localPort, password, filename, comm sock2.settimeout(10) try: data = sock2.recv(32).decode() - except: + except Exception: sys.stderr.write('FAIL\n') logging.error('No Answer to our Authentication') sock2.close() @@ -147,7 +147,7 @@ def serve(remoteAddr, localAddr, remotePort, localPort, password, filename, comm connection, client_address = sock.accept() sock.settimeout(None) connection.settimeout(None) - except: + except Exception: logging.error('No response from device') sock.close() return 1 @@ -173,7 +173,7 @@ def serve(remoteAddr, localAddr, remotePort, localPort, password, filename, comm if connection.recv(32).decode().find('O') >= 0: # connection will receive only digits or 'OK' received_ok = True - except: + except Exception: sys.stderr.write('\n') logging.error('Error Uploading') connection.close() @@ -207,7 +207,7 @@ def serve(remoteAddr, localAddr, remotePort, localPort, password, filename, comm if received_ok: return 0 return 1 - except: + except Exception: logging.error('No Result!') connection.close() f.close() diff --git a/tools/makecorever.py b/tools/makecorever.py index 3f1422b5d4..e7bd348686 100755 --- a/tools/makecorever.py +++ b/tools/makecorever.py @@ -32,7 +32,7 @@ def git(*args): try: git_ver = git("rev-parse", "--short=8", "HEAD") git_desc = git("describe", "--tags") - except: + except Exception: pass text = "#define ARDUINO_ESP8266_GIT_VER 0x{}\n".format(git_ver) @@ -43,7 +43,7 @@ def git(*args): old_text = inp.read() if old_text == text: return - except: + except Exception: pass with open(path, "w") as out: @@ -73,7 +73,7 @@ def git(*args): include_dir = os.path.join(args.build_path, args.include_dir) try: os.makedirs(include_dir) - except: + except Exception: pass generate( diff --git a/tools/signing.py b/tools/signing.py index 8c58d8bbbc..8fef38a112 100755 --- a/tools/signing.py +++ b/tools/signing.py @@ -78,7 +78,6 @@ def main(): f.write(val) return 0 elif args.mode == "sign": - val = "" if not os.path.isfile(args.privatekey): return try: diff --git a/tools/upload.py b/tools/upload.py index 0d57a63c9c..48352de3a7 100755 --- a/tools/upload.py +++ b/tools/upload.py @@ -16,7 +16,7 @@ sys.path.insert(0, toolspath + "/pyserial") # Add pyserial dir to search path sys.path.insert(0, toolspath + "/esptool") # Add esptool dir to search path import esptool # If this fails, we can't continue and will bomb below -except: +except Exception: sys.stderr.write("pyserial or esptool directories not found next to this upload.py tool.\n") sys.exit(1) From 6429af8437da9a3042dfaf74294c649b6e59b7b3 Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Sun, 2 Aug 2020 15:09:27 -0700 Subject: [PATCH 2/2] Back out HTML changes and rerun boards.txt.py --- doc/boards.rst | 2 +- .../examples/FSBrowser/data/edit/index.htm | 26 ++++++++++--------- .../examples/Graph/data/index.htm | 8 +++--- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/doc/boards.rst b/doc/boards.rst index 9c94b63120..73cc64f158 100644 --- a/doc/boards.rst +++ b/doc/boards.rst @@ -476,6 +476,6 @@ DOIT ESP-Mx DevKit (ESP8285) ---------------------------- DOIT ESP-Mx DevKit - This is a development board by DOIT, with a DOIT ESP-Mx module (`datasheet `__) using a ESP8285 Chip. With the DOIT ESP-Mx module, GPIO pins 9 and 10 are not available. The DOIT ESP-Mx DevKit board has a red power LED and a blue LED connected to GPIO16 and is active low to turn on. It uses a CH340C, USB to Serial converter chip. -ESP8285 (`datasheet `__) is a multi-chip package which contains ESP8266 and 1MB flash. +ESP8285 (`datasheet `__) is a multi-chip package which contains ESP8266 and 1MB flash. diff --git a/libraries/ESP8266WebServer/examples/FSBrowser/data/edit/index.htm b/libraries/ESP8266WebServer/examples/FSBrowser/data/edit/index.htm index e2a9d08776..31c9613a0f 100644 --- a/libraries/ESP8266WebServer/examples/FSBrowser/data/edit/index.htm +++ b/libraries/ESP8266WebServer/examples/FSBrowser/data/edit/index.htm @@ -292,7 +292,7 @@ if (fsInfo.isOk) { var percent = (1+Math.round(99*fsInfo.usedBytes/fsInfo.totalBytes)); // fake to see the "used" bar in any case var text = readableSize(fsInfo.totalBytes - fsInfo.usedBytes) + " free of " + readableSize(fsInfo.totalBytes); - status += "" + text + ""; + status += "" + text + "" if (fsInfo.unsupportedFiles) { status += " WARNING" + "Filesystem contains unsupported filenames:
" @@ -358,6 +358,7 @@ function createHeader(element, tree, editor){ var header = document.getElementById(element); + var xmlHttp; var fileSelector = document.createElement("input"); fileSelector.type = "file"; fileSelector.multiple = false; @@ -421,12 +422,12 @@ } if (!pathInput.value.startsWith("/")) pathInput.value = "/" + pathInput.value; pathInput.value = getParentFolder(pathInput.value) + "/" + filename; - }; + } upload.onclick = function(e) { if (fileSelector.files.length === 0) return; tree.httpUpload(fileSelector.files[0], pathInput.value); - }; + } function mustFormat83() { return false; // TODO: if needed, test fsInfo.type (and fatType ?) @@ -465,15 +466,15 @@ save.onclick = function(e){ editor.save(); - }; + } discard.onclick = function(e){ editor.discard(); - }; + } help.onclick = function(e){ editor.showShortcuts(); - }; + } } @@ -730,7 +731,7 @@ e.preventDefault(); e.stopPropagation(); showContextMenu(e, leaf.id, false); - }; + } return leaf; } @@ -891,7 +892,7 @@ function httpList(parentPath, remainingPaths){ setLoading(true, "Listing '" + parentPath + "'..."); // Fetch an updated list - var xmlHttp = new XMLHttpRequest(); + xmlHttp = new XMLHttpRequest(); xmlHttp.onload = onListReceived(xmlHttp, parentPath, remainingPaths); xmlHttp.open("GET", "/list?dir="+parentPath, true); xmlHttp.send(null); @@ -908,7 +909,7 @@ this.httpUpload = function(file, path) { setLoading(true, "Uploading '" + path + "'..."); if (!path.startsWith("/")) path = "/" + path; - var xmlHttp = new XMLHttpRequest(); + xmlHttp = new XMLHttpRequest(); xmlHttp.onload = onOperationComplete(xmlHttp, path); var formData = new FormData(); formData.append("data", file, path); @@ -919,7 +920,7 @@ this.httpCreate = function(path){ setLoading(true, "Creating '" + path + "'..."); if (!path.startsWith("/")) path = "/" + path; - var xmlHttp = new XMLHttpRequest(); + xmlHttp = new XMLHttpRequest(); xmlHttp.onload = onOperationComplete(xmlHttp, path); var formData = new FormData(); formData.append("path", path); @@ -930,7 +931,7 @@ function httpRename(srcPath, dstPath){ setLoading(true, "Renaming '" + srcPath + "' to '" + dstPath + "'..."); if (!dstPath.startsWith("/")) dstPath = "/" + dstPath; - var xmlHttp = new XMLHttpRequest(); + xmlHttp = new XMLHttpRequest(); xmlHttp.onload = onOperationComplete(xmlHttp, dstPath); var formData = new FormData(); formData.append("path", dstPath); @@ -941,7 +942,7 @@ function httpDelete(path) { setLoading(true, "Deleting '" + path + "'..."); - var xmlHttp = new XMLHttpRequest(); + xmlHttp = new XMLHttpRequest(); xmlHttp.onload = onOperationComplete(xmlHttp); var formData = new FormData(); formData.append("path", path); @@ -1096,6 +1097,7 @@ function onBodyLoad(){ var vars = {}; + var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) { vars[key] = value; }); if (typeof ace != "undefined") { var editor = createEditor("editor", vars.file, vars.lang, vars.theme); } diff --git a/libraries/ESP8266WebServer/examples/Graph/data/index.htm b/libraries/ESP8266WebServer/examples/Graph/data/index.htm index 5d2715a6ba..7eb5c1b18f 100644 --- a/libraries/ESP8266WebServer/examples/Graph/data/index.htm +++ b/libraries/ESP8266WebServer/examples/Graph/data/index.htm @@ -350,6 +350,8 @@ // Response is e.g.: {"time":963074, "heap":47160, "analog":60, "gpioMask":16447, "gpioData":16405} var espData = JSON.parse(xmlHttp.responseText); + var x = espData.time; + var maxSamples = parseInt(document.getElementById("maxSamplesField").value); // Add point to heap chart @@ -385,7 +387,7 @@ if (espData.gpioMask & gpioBitMask) { // This GPIO must be part of the chart - var dataset = allDigitalDatasets[gpio]; + dataset = allDigitalDatasets[gpio]; // give it the next available color dataset.borderColor = gpioColors[position % gpioColors.length]; // add it to the chart @@ -410,7 +412,7 @@ // chart must be updated, otherwise adding to previously hidden dataset fail digitalChart.update(); - currentGpioMask = espData.gpioMask; + currentGpioMask = espData.gpioMask } @@ -426,7 +428,7 @@ // Add received value to dataset // console.log(espData.gpioData + " & " + gpioBitMask + " => " + (espData.gpioData & gpioBitMask)); data = dataset.data; - var point = {x: espData.time, y: (espData.gpioData & gpioBitMask)?1:0}; + var point = {x: espData.time, y: (espData.gpioData & gpioBitMask)?1:0} data.push(point); // limit number of samples to maxSamples