Skip to content

Commit b0e1d93

Browse files
authored
Merge pull request #26 from yeyeto2788/feature
Fix issue on logging
2 parents 2cf6836 + 91c1541 commit b0e1d93

File tree

13 files changed

+394
-114
lines changed

13 files changed

+394
-114
lines changed

.gitignore

Lines changed: 112 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,115 @@ scripts/
44
tests/
55
img/
66
build/
7-
media/
87
mudpi.config
98
*.log
109
# Python compiled
1110
__pycache__/
12-
*.egg-info
11+
*.py[cod]
12+
*$py.class
1313

14-
# Virtual Environments
14+
# C extensions
15+
*.so
16+
17+
# Distribution / packaging
18+
.Python
19+
build/
20+
develop-eggs/
21+
dist/
22+
downloads/
23+
eggs/
24+
.eggs/
25+
lib/
26+
lib64/
27+
parts/
28+
sdist/
29+
var/
30+
wheels/
31+
share/python-wheels/
32+
*.egg-info/
33+
.installed.cfg
34+
*.egg
35+
MANIFEST
36+
37+
# PyInstaller
38+
# Usually these files are written by a python script from a template
39+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
40+
*.manifest
41+
*.spec
42+
43+
# Installer logs
44+
pip-log.txt
45+
pip-delete-this-directory.txt
46+
47+
# Unit test / coverage reports
48+
htmlcov/
49+
.tox/
50+
.nox/
51+
.coverage
52+
.coverage.*
53+
.cache
54+
nosetests.xml
55+
coverage.xml
56+
*.cover
57+
*.py,cover
58+
.hypothesis/
59+
.pytest_cache/
60+
cover/
61+
62+
# Translations
63+
*.mo
64+
*.pot
65+
66+
# Django stuff:
67+
*.log
68+
local_settings.py
69+
db.sqlite3
70+
db.sqlite3-journal
71+
72+
# Flask stuff:
73+
instance/
74+
.webassets-cache
75+
76+
# Scrapy stuff:
77+
.scrapy
78+
79+
# Sphinx documentation
80+
docs/_build/
81+
82+
# PyBuilder
83+
.pybuilder/
84+
target/
85+
86+
# Jupyter Notebook
87+
.ipynb_checkpoints
88+
89+
# IPython
90+
profile_default/
91+
ipython_config.py
92+
93+
# pyenv
94+
# For a library or package, you might want to ignore these files since the code is
95+
# intended to run in multiple environments; otherwise, check them in:
96+
# .python-version
97+
98+
# pipenv
99+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
100+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
101+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
102+
# install all needed dependencies.
103+
#Pipfile.lock
104+
105+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
106+
__pypackages__/
107+
108+
# Celery stuff
109+
celerybeat-schedule
110+
celerybeat.pid
111+
112+
# SageMath parsed files
113+
*.sage.py
114+
115+
# Environments
15116
.env
16117
.venv
17118
env/
@@ -20,6 +121,13 @@ ENV/
20121
env.bak/
21122
venv.bak/
22123

124+
# Spyder project settings
125+
.spyderproject
126+
.spyproject
127+
128+
# Rope project settings
129+
.ropeproject
130+
23131
# IDE configs
24132
.idea/
25-
.DS_Store
133+
.DS_Store
Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,37 @@
11
"""
2-
Custom Extension Example
3-
Provide a good description of what
4-
your extension is adding to MudPi
5-
or what it does.
2+
Custom Extension Example
3+
Provide a good description of what
4+
your extension is adding to MudPi
5+
or what it does.
66
"""
77
from mudpi.extensions import BaseExtension
88

9+
910
# Your extension should extend the BaseExtension class
1011
class Extension(BaseExtension):
1112
# The minimum your extension needs is a namespace. This
1213
# should be the same as your folder name and unique for
1314
# all extensions. Interfaces all components use this namespace.
14-
namespace = 'grow'
15+
namespace = 'grow'
16+
17+
# You can also set an update interval at which components
18+
# should be updated to gather new data / state.
19+
update_interval = 1
1520

16-
# You can also set an update interval at which components
17-
# should be updated to gather new data / state.
18-
update_interval = 1
19-
20-
def init(self, config):
21-
""" Prepare the extension and all components """
22-
# This is called on MudPi start and passed config on start.
23-
# Here is where devices should be setup, connections made,
24-
# components created and added etc.
25-
26-
# Must return True or an error will be assumed disabling the extension
27-
return True
21+
def init(self, config):
22+
""" Prepare the extension and all components """
23+
# This is called on MudPi start and passed config on start.
24+
# Here is where devices should be setup, connections made,
25+
# components created and added etc.
26+
27+
# Must return True or an error will be assumed disabling the extension
28+
return True
2829

2930
def validate(self, config):
3031
""" Validate the extension configuration """
3132
# Here the extension configuration is passed in before the init() method
32-
# is called. The validate method is used to prepare a valid configuration
33+
# is called. The validate method is used to prepare a valid configuration
3334
# for the extension before initialization. This method should return the
3435
# validated config or raise a ConfigError.
35-
36-
return config
36+
37+
return config

mudpi/config.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import os
22
import json
33
import yaml
4-
from mudpi.constants import (FONT_YELLOW, RED_BACK, FONT_RESET, IMPERIAL_SYSTEM, PATH_MUDPI, PATH_CONFIG, DEFAULT_CONFIG_FILE)
5-
from mudpi.exceptions import ConfigNotFoundError, ConfigError
4+
from mudpi.constants import (FONT_YELLOW, RED_BACK, FONT_RESET, IMPERIAL_SYSTEM, PATH_MUDPI,
5+
PATH_CONFIG, DEFAULT_CONFIG_FILE)
6+
from mudpi.exceptions import ConfigNotFoundError, ConfigError, ConfigFormatError
67

78

89
class Config(object):
@@ -11,14 +12,15 @@ class Config(object):
1112
A class to represent the MudPi configuration that
1213
is typically pulled from a file.
1314
"""
15+
1416
def __init__(self, config_path=None):
1517
self.config_path = config_path or os.path.abspath(os.path.join(os.getcwd(), PATH_CONFIG))
16-
18+
1719
self.config = {}
1820
self.set_defaults()
1921

20-
2122
""" Properties """
23+
2224
@property
2325
def name(self):
2426
return self.config.get('mudpi', {}).get('name', 'MudPi')
@@ -134,15 +136,17 @@ def load_from_json(self, json_data):
134136
self.config = json.loads(json_data)
135137
return self.config
136138
except Exception as e:
137-
print(f'{RED_BACK}Problem loading configs from JSON {FONT_RESET}\n{FONT_YELLOW}{e}{FONT_RESET}\r')
139+
print(
140+
f'{RED_BACK}Problem loading configs from JSON {FONT_RESET}\n{FONT_YELLOW}{e}{FONT_RESET}\r')
138141

139142
def load_from_yaml(self, yaml_data):
140143
""" Load configs from YAML """
141144
try:
142145
self.config = yaml.load(yaml_data, yaml.FullLoader)
143146
return self.config
144147
except Exception as e:
145-
print(f'{RED_BACK}Problem loading configs from YAML {FONT_RESET}\n{FONT_YELLOW}{e}{FONT_RESET}\r')
148+
print(
149+
f'{RED_BACK}Problem loading configs from YAML {FONT_RESET}\n{FONT_YELLOW}{e}{FONT_RESET}\r')
146150

147151
def save_to_file(self, file=None, format=None, config=None):
148152
""" Save current configs to a file
@@ -170,33 +174,34 @@ def save_to_file(self, file=None, format=None, config=None):
170174
return True
171175

172176
def validate_file(self, file, exists=True):
173-
""" Validate a file path and return a prepared path to save
177+
""" Validate a file path and return a prepared path to save
174178
Set exists to False to prevent file exists check
175179
"""
176-
if '.' in file:
180+
if '.' in file:
177181
if not self.file_exists(file) and exists:
178182
raise ConfigNotFoundError(f"The config path {file} does not exist.")
179-
return False
183+
180184
extensions = ['.config', '.json', '.yaml', '.conf']
185+
181186
if not any([file.endswith(extension) for extension in extensions]):
182-
raise ConfigFormatError("An unknown config file format was provided in the config path.")
183-
return False
187+
raise ConfigFormatError(
188+
"An unknown config file format was provided in the config path.")
184189
else:
185190
# Path provided but not file
186191
file = os.path.join(file, DEFAULT_CONFIG_FILE)
187192
return file
188193

189194
def config_format(self, file):
190195
""" Returns the file format if supported """
196+
197+
config_format = None
191198
if '.' in file:
192199
if any(extension in file for extension in ['.config', '.json', '.conf']):
193200
config_format = 'json'
194201
elif '.yaml' in file:
195202
config_format = 'yaml'
196-
else:
197-
config_format = None
198-
199-
return config_format
203+
204+
return config_format
200205

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

213218
def __repr__(self):
214219
""" Debug print of config """
215-
return f'<Config {self.config_path}>'
220+
return f'<Config {self.config_path}>'

mudpi/debug/dump.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ def dumpall():
107107
for x in a.register.names:
108108
r = a.register.get(x)
109109
if r.size == 2:
110-
v = '0x%04X' % (r.value)
110+
v = '0x%04X' % r.value
111111
else:
112-
v = ' 0x%02X' % (r.value)
112+
v = ' 0x%02X' % r.value
113113

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

0 commit comments

Comments
 (0)