Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue on logging #26

Merged
merged 22 commits into from Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
48fb736
Merge pull request #5 from mudpi/feature
yeyeto2788 Mar 15, 2021
bafee4a
Merge pull request #6 from mudpi/feature
yeyeto2788 Mar 16, 2021
4834059
Fix Logger class attributes
yeyeto2788 Mar 16, 2021
f63f732
Fix minor issue on logging
yeyeto2788 Mar 16, 2021
810f31d
Merge pull request #7 from mudpi/feature
yeyeto2788 Mar 18, 2021
c5a4a24
Add some PEP fix to the code for more readability
yeyeto2788 Mar 18, 2021
60887ea
Add more PEP fixes
yeyeto2788 Mar 18, 2021
b8a0dd4
Add proper gitignore to avoid submitting code not needed
yeyeto2788 Mar 18, 2021
7aa887c
Comment the build folder so it can get deleted
yeyeto2788 Mar 18, 2021
521ab70
Add validation for not existing pin on a given board.
yeyeto2788 Mar 18, 2021
996ba04
Resolve some linting issues
yeyeto2788 Mar 18, 2021
2c74358
Merge branch 'feature' into pr/8
yeyeto2788 Mar 22, 2021
10bc228
Revert little change on logger
yeyeto2788 Mar 22, 2021
221826b
Merge branch 'feature' of https://github.com/mudpi/mudpi-core into mu…
yeyeto2788 Mar 23, 2021
ddcb75a
Merge branch 'mudpi-feature' into feature
yeyeto2788 Mar 23, 2021
a8f5f60
Merge branch 'feature' of https://github.com/mudpi/mudpi-core into mu…
yeyeto2788 Mar 25, 2021
cb3aefe
Merge branch 'mudpi-feature' into feature
yeyeto2788 Mar 25, 2021
8fef56a
Merge branch 'feature' of https://github.com/mudpi/mudpi-core into mu…
yeyeto2788 Mar 29, 2021
46f248e
Merge branch 'mudpi-feature' into feature
yeyeto2788 Mar 29, 2021
37ce37b
Merge pull request #11 from mudpi/feature
yeyeto2788 Mar 29, 2021
1562a81
Merge branch 'feature' of https://github.com/mudpi/mudpi-core into mu…
yeyeto2788 Apr 8, 2021
91c1541
Merge branch 'mudpi-feature' into feature
yeyeto2788 Apr 8, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
116 changes: 112 additions & 4 deletions .gitignore
Expand Up @@ -4,14 +4,115 @@ scripts/
tests/
img/
build/
media/
mudpi.config
*.log
# Python compiled
__pycache__/
*.egg-info
*.py[cod]
*$py.class

# Virtual Environments
# 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

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

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
Expand All @@ -20,6 +121,13 @@ ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# IDE configs
.idea/
.DS_Store
.DS_Store
41 changes: 21 additions & 20 deletions examples/custom_extension/grow/__init__.py
@@ -1,36 +1,37 @@
"""
Custom Extension Example
Provide a good description of what
your extension is adding to MudPi
or what it does.
Custom Extension Example
Provide a good description of what
your extension is adding to MudPi
or what it does.
"""
from mudpi.extensions import BaseExtension


# Your extension should extend the BaseExtension class
class Extension(BaseExtension):
# The minimum your extension needs is a namespace. This
# should be the same as your folder name and unique for
# all extensions. Interfaces all components use this namespace.
namespace = 'grow'
namespace = 'grow'

# You can also set an update interval at which components
# should be updated to gather new data / state.
update_interval = 1

# You can also set an update interval at which components
# should be updated to gather new data / state.
update_interval = 1

def init(self, config):
""" Prepare the extension and all components """
# This is called on MudPi start and passed config on start.
# Here is where devices should be setup, connections made,
# components created and added etc.

# Must return True or an error will be assumed disabling the extension
return True
def init(self, config):
""" Prepare the extension and all components """
# This is called on MudPi start and passed config on start.
# Here is where devices should be setup, connections made,
# components created and added etc.

# Must return True or an error will be assumed disabling the extension
return True

def validate(self, config):
""" Validate the extension configuration """
# Here the extension configuration is passed in before the init() method
# is called. The validate method is used to prepare a valid configuration
# is called. The validate method is used to prepare a valid configuration
# for the extension before initialization. This method should return the
# validated config or raise a ConfigError.
return config

return config
37 changes: 21 additions & 16 deletions mudpi/config.py
@@ -1,8 +1,9 @@
import os
import json
import yaml
from mudpi.constants import (FONT_YELLOW, RED_BACK, FONT_RESET, IMPERIAL_SYSTEM, PATH_MUDPI, PATH_CONFIG, DEFAULT_CONFIG_FILE)
from mudpi.exceptions import ConfigNotFoundError, ConfigError
from mudpi.constants import (FONT_YELLOW, RED_BACK, FONT_RESET, IMPERIAL_SYSTEM, PATH_MUDPI,
PATH_CONFIG, DEFAULT_CONFIG_FILE)
from mudpi.exceptions import ConfigNotFoundError, ConfigError, ConfigFormatError


class Config(object):
Expand All @@ -11,14 +12,15 @@ class Config(object):
A class to represent the MudPi configuration that
is typically pulled from a file.
"""

def __init__(self, config_path=None):
self.config_path = config_path or os.path.abspath(os.path.join(os.getcwd(), PATH_CONFIG))

self.config = {}
self.set_defaults()


""" Properties """

@property
def name(self):
return self.config.get('mudpi', {}).get('name', 'MudPi')
Expand Down Expand Up @@ -134,15 +136,17 @@ def load_from_json(self, json_data):
self.config = json.loads(json_data)
return self.config
except Exception as e:
print(f'{RED_BACK}Problem loading configs from JSON {FONT_RESET}\n{FONT_YELLOW}{e}{FONT_RESET}\r')
print(
f'{RED_BACK}Problem loading configs from JSON {FONT_RESET}\n{FONT_YELLOW}{e}{FONT_RESET}\r')

def load_from_yaml(self, yaml_data):
""" Load configs from YAML """
try:
self.config = yaml.load(yaml_data, yaml.FullLoader)
return self.config
except Exception as e:
print(f'{RED_BACK}Problem loading configs from YAML {FONT_RESET}\n{FONT_YELLOW}{e}{FONT_RESET}\r')
print(
f'{RED_BACK}Problem loading configs from YAML {FONT_RESET}\n{FONT_YELLOW}{e}{FONT_RESET}\r')

def save_to_file(self, file=None, format=None, config=None):
""" Save current configs to a file
Expand Down Expand Up @@ -170,33 +174,34 @@ def save_to_file(self, file=None, format=None, config=None):
return True

def validate_file(self, file, exists=True):
""" Validate a file path and return a prepared path to save
""" Validate a file path and return a prepared path to save
Set exists to False to prevent file exists check
"""
if '.' in file:
if '.' in file:
if not self.file_exists(file) and exists:
raise ConfigNotFoundError(f"The config path {file} does not exist.")
return False

extensions = ['.config', '.json', '.yaml', '.conf']

if not any([file.endswith(extension) for extension in extensions]):
raise ConfigFormatError("An unknown config file format was provided in the config path.")
return False
raise ConfigFormatError(
"An unknown config file format was provided in the config path.")
else:
# Path provided but not file
file = os.path.join(file, DEFAULT_CONFIG_FILE)
return file

def config_format(self, file):
""" Returns the file format if supported """

config_format = None
if '.' in file:
if any(extension in file for extension in ['.config', '.json', '.conf']):
config_format = 'json'
elif '.yaml' in file:
config_format = 'yaml'
else:
config_format = None

return config_format

return config_format

def get(self, key, default=None, replace_char=None):
""" Get an item from the config with a default
Expand All @@ -212,4 +217,4 @@ def get(self, key, default=None, replace_char=None):

def __repr__(self):
""" Debug print of config """
return f'<Config {self.config_path}>'
return f'<Config {self.config_path}>'
4 changes: 2 additions & 2 deletions mudpi/debug/dump.py
Expand Up @@ -107,9 +107,9 @@ def dumpall():
for x in a.register.names:
r = a.register.get(x)
if r.size == 2:
v = '0x%04X' % (r.value)
v = '0x%04X' % r.value
else:
v = ' 0x%02X' % (r.value)
v = ' 0x%02X' % r.value

print('%-20s = %s @0x%2X (size:%s)' % (r.name, v, r.address, r.size))

Expand Down