From e3c4d14facf5b5bf76f2155560b498f4d1596b6f Mon Sep 17 00:00:00 2001 From: Patrick Nguyen Date: Fri, 3 Jun 2022 20:54:10 -0700 Subject: [PATCH] Removed config generator script --- .env.txt | 4 -- .gitignore | 1 - README.md | 4 +- genConfigHpp.py | 92 ------------------------------------------ include/config.hpp.txt | 12 ++++++ platformio.ini | 1 - 6 files changed, 14 insertions(+), 100 deletions(-) delete mode 100644 .env.txt delete mode 100644 genConfigHpp.py create mode 100644 include/config.hpp.txt diff --git a/.env.txt b/.env.txt deleted file mode 100644 index b09b41e..0000000 --- a/.env.txt +++ /dev/null @@ -1,4 +0,0 @@ -# WIFI SSID: str -ZBIN_CORE_WIFI_SSID= -# WIFI Password: str -ZBIN_CORE_WIFI_PWD= \ No newline at end of file diff --git a/.gitignore b/.gitignore index 4667006..e38eefe 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,3 @@ .vscode/ipch config.hpp -.env diff --git a/README.md b/README.md index deb2696..a1f54ec 100644 --- a/README.md +++ b/README.md @@ -15,9 +15,9 @@ The previous iteration was a Raspberry Pi-based system. This system is intended git clone git@github.com:zotbins/ZotbinsCore.git ``` -2. Create an `.env` file in the project directory following `.env.txt` as a template. +2. Create an `config.hpp` file in the `include` directory following `config.hpp.txt` as a template. -3. Fill in the values in `.env` with the appropriate values. +3. Fill in the values in `config.hpp` with the appropriate values. ![PlatformIO VSCode Toolbar](docs/images/platformio_toolbar.png) diff --git a/genConfigHpp.py b/genConfigHpp.py deleted file mode 100644 index aa85cfb..0000000 --- a/genConfigHpp.py +++ /dev/null @@ -1,92 +0,0 @@ -""" -Pre-compilation script for platformio.ini. -Edit .env if you wish to change the values. -""" - -from dataclasses import dataclass -import os -Import("env") - -try: - from dotenv import load_dotenv -except ImportError: - env.Execute("$PYTHONEXE -m pip install python-dotenv") - - -@dataclass -class Config: - """Class for environment variables""" - WIFI_SSID: str = "" - WIFI_PWD: str = "" - - -"""Config header file name""" -CONFIG_HEADER = "config.hpp" - -""" -Config header file contents template. -Values to be added by format(). -""" -CONFIG_HEADER_CONTENTS = """ -// AUTO GENERATED FILE, DO NOT EDIT -#ifndef CONFIG_HPP -#define CONFIG_HPP - -namespace Zotbins -{{ - namespace Config - {{ - const char *WIFI_SSID = \"{WIFI_SSID}\"; - const char *WIFI_PWD = \"{WIFI_PWD}\"; - }} -}} -#endif -""" - - -def loadConfig() -> Config: - """ - Load configuration from .env file. - If .env does not exist, return default values. - - Returns: - Config object with values of enviromental variables - """ - - # Return default if .env does not exist - if not os.path.exists(".env"): - return Config() - - # Load enviromental variables - load_dotenv() - WIFI_SSID = os.environ.get("ZBIN_CORE_WIFI_SSID", "") - WIFI_PWD = os.environ.get("ZBIN_CORE_WIFI_PWD", "") - - return Config(WIFI_SSID, WIFI_PWD) - - -def createConfigHeader(config: Config) -> None: - """ - Generates config.hpp in the include/ directory. - Uses the values in config to set values in header. - - Parameters: - config (Config) Config object with values of environmental variables - """ - - if os.path.exists("include/"): - CONFIG_HEADER_PATH = "include" + os.sep + CONFIG_HEADER - - # Write to header file - with open(CONFIG_HEADER_PATH, "w+") as file: - file.write(CONFIG_HEADER_CONTENTS.format( - WIFI_SSID=config.WIFI_SSID, - WIFI_PWD=config.WIFI_PWD, - )) - else: - raise FileNotFoundError("include/ directory not found") - - -# Load config and create config header file -config = loadConfig() -createConfigHeader(config) diff --git a/include/config.hpp.txt b/include/config.hpp.txt new file mode 100644 index 0000000..a5a3c95 --- /dev/null +++ b/include/config.hpp.txt @@ -0,0 +1,12 @@ +#ifndef CONFIG_HPP +#define CONFIG_HPP + +namespace Zotbins +{ + namespace Config + { + const char *WIFI_SSID = ""; + const char *WIFI_PWD = ""; + } +} +#endif \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 5c9e1bb..9bd4ae2 100644 --- a/platformio.ini +++ b/platformio.ini @@ -21,7 +21,6 @@ monitor_flags = --raw monitor_dtr = 0 monitor_rts = 0 test_ignore = test_desktop_* -extra_scripts = pre:genConfigHpp.py [env:myrelease] extends = esp32dev