From 0aabbda63044c324c91bcb2070203013949dff60 Mon Sep 17 00:00:00 2001 From: Peter Hinch Date: Thu, 16 May 2019 11:55:35 +0100 Subject: [PATCH] PicoWeb guide now has no changes to Paul Sokolovsky's picoweb code. --- PICOWEB.md | 12 ++-- PicoWeb/logging.py | 94 ------------------------------ PicoWeb/picoweb/__init__.py | 6 +- PicoWeb/picoweb/example_webapp.py | 2 +- PicoWeb/picoweb/example_webapp2.py | 2 +- 5 files changed, 10 insertions(+), 106 deletions(-) delete mode 100644 PicoWeb/logging.py diff --git a/PICOWEB.md b/PICOWEB.md index 03a83cf..b954977 100644 --- a/PICOWEB.md +++ b/PICOWEB.md @@ -5,8 +5,8 @@ This has regularly caused dificulty on the forum. The target hardware is assumed to be running official MicroPython firmware. This repo aims to clarify the installation process. Paul Sokolovsky's Picoweb -code is unchanged except for the name of the logging library. The demos are -trivially changed to use IP '0.0.0.0' and port 80. +code is unchanged. The demos are trivially changed to use IP '0.0.0.0' and port +80. To install on a hardware platform such as ESP32 or Pyboard D it is necessary to copy this directory and its contents (including subdirectories) to the target. @@ -16,7 +16,7 @@ issue ``` /my/tree/PicoWeb> rsync . /pyboard ``` -This may take some time. +This may take some time: 1 minute here on ESP32. At the REPL connect to the network and determine your IP address ``` @@ -88,7 +88,5 @@ path/to/repo> cp picoweb/templates/squares.tpl /pyboard/picoweb/templates/ See [the PicoWeb docs](https://github.com/pfalcon/picoweb) -Note that to run under official MicroPython, references to `ulogging` in these -demos must be changed to `logging`. You may also want to change IP and port as -above. - +Note that to run the demos on platforms other than the Unix build you may want +to change IP and port as above. diff --git a/PicoWeb/logging.py b/PicoWeb/logging.py deleted file mode 100644 index cea2de0..0000000 --- a/PicoWeb/logging.py +++ /dev/null @@ -1,94 +0,0 @@ -import sys - -CRITICAL = 50 -ERROR = 40 -WARNING = 30 -INFO = 20 -DEBUG = 10 -NOTSET = 0 - -_level_dict = { - CRITICAL: "CRIT", - ERROR: "ERROR", - WARNING: "WARN", - INFO: "INFO", - DEBUG: "DEBUG", -} - -_stream = sys.stderr - -class Logger: - - level = NOTSET - - def __init__(self, name): - self.name = name - - def _level_str(self, level): - l = _level_dict.get(level) - if l is not None: - return l - return "LVL%s" % level - - def setLevel(self, level): - self.level = level - - def isEnabledFor(self, level): - return level >= (self.level or _level) - - def log(self, level, msg, *args): - if level >= (self.level or _level): - _stream.write("%s:%s:" % (self._level_str(level), self.name)) - if not args: - print(msg, file=_stream) - else: - print(msg % args, file=_stream) - - def debug(self, msg, *args): - self.log(DEBUG, msg, *args) - - def info(self, msg, *args): - self.log(INFO, msg, *args) - - def warning(self, msg, *args): - self.log(WARNING, msg, *args) - - def error(self, msg, *args): - self.log(ERROR, msg, *args) - - def critical(self, msg, *args): - self.log(CRITICAL, msg, *args) - - def exc(self, e, msg, *args): - self.log(ERROR, msg, *args) - sys.print_exception(e, _stream) - - def exception(self, msg, *args): - self.exc(sys.exc_info()[1], msg, *args) - - -_level = INFO -_loggers = {} - -def getLogger(name): - if name in _loggers: - return _loggers[name] - l = Logger(name) - _loggers[name] = l - return l - -def info(msg, *args): - getLogger(None).info(msg, *args) - -def debug(msg, *args): - getLogger(None).debug(msg, *args) - -def basicConfig(level=INFO, filename=None, stream=None, format=None): - global _level, _stream - _level = level - if stream: - _stream = stream - if filename is not None: - print("logging.basicConfig: filename arg is not supported") - if format is not None: - print("logging.basicConfig: format arg is not supported") diff --git a/PicoWeb/picoweb/__init__.py b/PicoWeb/picoweb/__init__.py index 6708069..315de6e 100644 --- a/PicoWeb/picoweb/__init__.py +++ b/PicoWeb/picoweb/__init__.py @@ -281,10 +281,10 @@ class WebApp: def run(self, host="127.0.0.1", port=8081, debug=False, lazy_init=False, log=None): if log is None and debug >= 0: - import logging - log = logging.getLogger("picoweb") + import ulogging + log = ulogging.getLogger("picoweb") if debug > 0: - log.setLevel(logging.DEBUG) + log.setLevel(ulogging.DEBUG) self.log = log gc.collect() self.debug = int(debug) diff --git a/PicoWeb/picoweb/example_webapp.py b/PicoWeb/picoweb/example_webapp.py index ff99b5a..f614e92 100644 --- a/PicoWeb/picoweb/example_webapp.py +++ b/PicoWeb/picoweb/example_webapp.py @@ -41,7 +41,7 @@ ROUTES = [ ] -import logging +import ulogging as logging logging.basicConfig(level=logging.INFO) #logging.basicConfig(level=logging.DEBUG) diff --git a/PicoWeb/picoweb/example_webapp2.py b/PicoWeb/picoweb/example_webapp2.py index 9f58fac..757f174 100644 --- a/PicoWeb/picoweb/example_webapp2.py +++ b/PicoWeb/picoweb/example_webapp2.py @@ -18,7 +18,7 @@ def squares(req, resp): yield from app.render_template(resp, "squares.tpl", (req,)) -import logging +import ulogging as logging logging.basicConfig(level=logging.INFO) app.run(debug=True, host='0.0.0.0', port=80)