Skip to content

Commit

Permalink
Merge pull request #35 from ArthurMitchell42/V0.3.2
Browse files Browse the repository at this point in the history
V0.3.2
  • Loading branch information
ArthurMitchell42 authored Mar 1, 2024
2 parents 3536f4d + 8699bc0 commit 281803e
Show file tree
Hide file tree
Showing 53 changed files with 3,380 additions and 1,580 deletions.
7 changes: 7 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[flake8]
ignore = E121 E122 E123 E124 E126 E127 E128 E201 E221 E241 E251 E302 E305 W504
exclude = .git,__pycache__,venv
max-line-length = 100

per-file-ignores =
gui_data_format.py: E501
2 changes: 1 addition & 1 deletion .github/workflows/docker-build-manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ env:
REGISTRY: docker.io
# github.repository as <account>/<repo>
IMAGE_NAME: kronos443/nutcase

jobs:
build:
runs-on: ubuntu-latest
Expand Down
167 changes: 165 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,167 @@
venv
__pycache__
scrap2/
nutcase/config/*.log
nutcase/config/*.log.*
nutcase/app/coverage.txt

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
nutcase/app/coverage.txt
nutcase/app/coverage.txt
4 changes: 4 additions & 0 deletions nutcase/.coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[run]
omit =
*/venv/*
/usr/*
58 changes: 29 additions & 29 deletions nutcase/app/app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import logging
# from logging.handlers import SMTPHandler, RotatingFileHandler
import os
from flask import Flask
from config import Config_Development # , Config_Production, Config
from flask import Flask
from config import Config_Development # , Config_Production, Config

from app.utils import webhook
from app.utils import configuration
from app.utils import app_log_config

#=================================================
# =================================================
# Initialise components

#==================================================================================================
# ========================================================================================
# Main app creation function
#==================================================================================================
# ========================================================================================
def create_app(config_class=Config_Development):
app = Flask(__name__)
app.config.from_object(config_class)

#====================================================================================
# ====================================================================================
# Register the app Blueprints
#====================================================================================
# ====================================================================================
from app.main import bp as main_bp
app.register_blueprint(main_bp)

Expand All @@ -30,44 +30,44 @@ def create_app(config_class=Config_Development):
from app.events import bp as events_bp
app.register_blueprint(events_bp, url_prefix='/events')

#====================================================================================
# ====================================================================================
# Set up the application logging
#====================================================================================
# ====================================================================================
app_log_config.Add_Logging_Levels()

Logfile_Directory = os.path.join(app.config['CONFIG_PATH'], app.config['LOGFILE_SUBPATH'])
if not os.path.exists(Logfile_Directory):
os.mkdir(Logfile_Directory)

app_log_config.Add_RF_Handler( app )
app_log_config.Add_RF_Handler(app)

#====================================================================================
# ====================================================================================
# Set the logging level from the environment variable LOG_LEVEL if present.
#====================================================================================
# ====================================================================================
Console_Level = os.environ.get('LOG_LEVEL', app.config['DEFAULT_CONSOLE_LEVEL']).upper()
Logfile_Level = os.environ.get('LOG_LEVEL', app.config['DEFAULT_LOGFILE_LEVEL']).upper()

app.logger.info("Init: Console_Level {} Logfile_Level {}".format( Console_Level, Logfile_Level ))
app_log_config.Set_Log_Level( app, Console_Level, "con" )
app_log_config.Set_Log_Level( app, Logfile_Level, "rfh" )
app.logger.setLevel( 1 ) # Set the root logger to pass everything on
#====================================================================================
app.logger.info("Init: Console_Level {} Logfile_Level {}".format(Console_Level, Logfile_Level))
app_log_config.Set_Log_Level(app, Console_Level, "con")
app_log_config.Set_Log_Level(app, Logfile_Level, "rfh")
app.logger.setLevel(1) # Set the root logger to pass everything on

# ====================================================================================
# Load the app configuration from a YAML file
#====================================================================================
configuration.Load_Config( app )
# ====================================================================================
configuration.Load_Config(app)

#====================================================================================
# ====================================================================================
# Log starting and call a web hook
#====================================================================================
# ====================================================================================
app.logger.info("{} starting. Version {}, Logging: console {} logfile {}".format(
app.config['APP_NAME'], app.config['APP_VERSION'],
logging.getLevelName( app_log_config.Get_Handler( app, 'con' ).level),
logging.getLevelName( app_log_config.Get_Handler( app, 'rfh' ).level),
))
webhook.Call_Webhook( app, "ok", { "status": "up", "msg": "NUTCase starting" } )
app.config['APP_NAME'], app.config['APP_VERSION'],
logging.getLevelName(app_log_config.Get_Handler(app, 'con').level),
logging.getLevelName(app_log_config.Get_Handler(app, 'rfh').level),
))

webhook.Call_Webhook(app, "ok", {"status": "up", "msg": "NUTCase starting"})

return app

from app import models
# from app import models
2 changes: 1 addition & 1 deletion nutcase/app/app/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

bp = Blueprint('api', __name__)

from app.api import routes
from app.api import routes # noqa: E402 F401
24 changes: 12 additions & 12 deletions nutcase/app/app/api/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from app.utils import scrape
from app.utils import gui_data_format

#====================================================================================
# ====================================================================================
# Serve the end-point /api/status
#====================================================================================
# ====================================================================================
@bp.route('/status')
def route_status():
Result = {}
Expand All @@ -19,35 +19,35 @@ def route_status():
current_app.logger.debug("No device in args")
return Result

Scrape_Return, Scrape_Data = scrape.Get_Scrape_Data( Args )
Scrape_Return, Scrape_Data = scrape.Get_Scrape_Data(Args)
if not Scrape_Return:
current_app.logger.debug("No scrape data")
return Result
Result = gui_data_format.Process_Data_For_GUI( Scrape_Data, Device )

Result = gui_data_format.Process_Data_For_GUI(Scrape_Data, Device)
return Result

#====================================================================================
# ====================================================================================
# Serve the end-point /api/status
#====================================================================================
# ====================================================================================
@bp.route('/devices')
def route_devices():
Result = {}
Device = request.args.get('dev')
Addr = request.args.get('addr')
Result = gui_data_format.Process_Device_Pulldown( Addr, Device, Result )

Result = gui_data_format.Process_Device_Pulldown(Addr, Device, Result)
return Result

#====================================================================================
# ====================================================================================
# Serve the end-point /api/default - Returns JSON for the default (or last) server
# in the config file server section.
#====================================================================================
# ====================================================================================
@bp.route('/default')
def route_default():
Result = {}

if len( current_app.config['SERVERS'] ) == 0:
if len(current_app.config['SERVERS']) == 0:
return Result

for s in current_app.config['SERVERS']:
Expand Down
4 changes: 2 additions & 2 deletions nutcase/app/app/cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#import os
#import click
# import os
# import click

def register(app):
@app.cli.group()
Expand Down
2 changes: 1 addition & 1 deletion nutcase/app/app/events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

bp = Blueprint('events', __name__)

from app.events import routes
from app.events import routes # noqa: E402 F401
3 changes: 1 addition & 2 deletions nutcase/app/app/events/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Events_Form(FlaskForm):
(20, "Info"),
(30, "Warning"),
(40, "Alert"),
],
],
# default=('alert', "Alert")
coerce=int
)
Expand All @@ -22,4 +22,3 @@ class Events_Form(FlaskForm):
], coerce=int)

submit = SubmitField('Clear')

Loading

0 comments on commit 281803e

Please sign in to comment.