Skip to content
Snippets Groups Projects
Verified Commit 59369755 authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Move impotrs into methods for even more namespace tidyness

parent 6e9a2360
No related branches found
No related tags found
No related merge requests found
...@@ -14,12 +14,6 @@ ...@@ -14,12 +14,6 @@
"""µnit - Configurable initialisation system for MicroPython/ESP""" """µnit - Configurable initialisation system for MicroPython/ESP"""
import gc
import json
import network
import os
import webrepl
# Set of configuration schemas provided by µnit itself # Set of configuration schemas provided by µnit itself
# First level: category -> (human-readable name, dict of settings) # First level: category -> (human-readable name, dict of settings)
# Second level: setting key -> (human-readable name, type, choices, default) # Second level: setting key -> (human-readable name, type, choices, default)
...@@ -60,6 +54,8 @@ class _MynitConfig: ...@@ -60,6 +54,8 @@ class _MynitConfig:
self._load() self._load()
def _make_dir(self): def _make_dir(self):
import os
try: try:
os.stat(self._dir) os.stat(self._dir)
except OSError: except OSError:
...@@ -68,6 +64,8 @@ class _MynitConfig: ...@@ -68,6 +64,8 @@ class _MynitConfig:
def _load(self): def _load(self):
"""Load cached data from data directory.""" """Load cached data from data directory."""
import json
# Create data directory if it doesn't exist yet # Create data directory if it doesn't exist yet
self._make_dir() self._make_dir()
...@@ -90,6 +88,8 @@ class _MynitConfig: ...@@ -90,6 +88,8 @@ class _MynitConfig:
self._config = {} self._config = {}
def _save(self): def _save(self):
import json
"""Save cached data to data directory.""" """Save cached data to data directory."""
# Create data directory if it doesn't exist yet # Create data directory if it doesn't exist yet
self._make_dir() self._make_dir()
...@@ -161,6 +161,8 @@ class _MynitBoot: ...@@ -161,6 +161,8 @@ class _MynitBoot:
print("Boot finished") print("Boot finished")
def setup_wifi(self): def setup_wifi(self):
import network
# Setup wifi # Setup wifi
if self._config["wifi"]["essid"]: if self._config["wifi"]["essid"]:
if self._config["wifi"]["mode"] == "sta": if self._config["wifi"]["mode"] == "sta":
...@@ -198,6 +200,8 @@ class _MynitBoot: ...@@ -198,6 +200,8 @@ class _MynitBoot:
print("Wifi configured as %s" % (nic.ifconfig(),)) print("Wifi configured as %s" % (nic.ifconfig(),))
def setup_webrepl(self): def setup_webrepl(self):
import webrepl
# Start webrepl if enabled # Start webrepl if enabled
if self._config["webrepl"]["enabled"]: if self._config["webrepl"]["enabled"]:
print("Starting web REPL on port %d" % self._config["webrepl"]["port"]) print("Starting web REPL on port %d" % self._config["webrepl"]["port"])
...@@ -219,4 +223,6 @@ if __name__ == "__main__": ...@@ -219,4 +223,6 @@ if __name__ == "__main__":
del _MYNIT_SCHEMAS, _MynitBoot, _MynitConfig del _MYNIT_SCHEMAS, _MynitBoot, _MynitConfig
# Forcibly clean up before handing overto main.py # Forcibly clean up before handing overto main.py
gc.collect() # fmt: off
import gc; gc.collect(); del gc
# fmt: on
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment