Skip to content

Commit

Permalink
v0.3.6: Registers version, logging option, hybrid registers
Browse files Browse the repository at this point in the history
  • Loading branch information
bohdan-s committed Mar 7, 2022
1 parent 5cf2ac2 commit dfe0e44
Show file tree
Hide file tree
Showing 7 changed files with 660 additions and 106 deletions.
117 changes: 117 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
config.yaml
*.log.*

# 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/
*.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
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

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

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# 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/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
config.yaml
*.log.*

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ RUN pip install --no-cache-dir --upgrade pycryptodomex==3.11.0 -r requirements.t

COPY SunGather/ .

VOLUME /logs
VOLUME /config
COPY SunGather/config-example.yaml /config/config.yaml

USER sungather

CMD [ "python", "sungather.py", "-c", "/config/config.yaml" ]
CMD [ "python", "sungather.py", "-c", "/config/config.yaml", "-l", "/logs/" ]
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ or if using the webserver export
```sh
docker run -v {path to}/config.yaml:/config/config.yaml -e TZ=Australia/Sydney -p 8080:8080 --name sungather bohdans/sungather
```
with webserever export and logging
```sh
docker run -v {path to}/config.yaml:/config/config.yaml -v{logpath}:/logs -e TZ=Australia/Sydney -p 8080:8080 --name sungather bohdans/sungather
```
Note: replace Australia/Sydney with relevant timezone
<p align="right">(<a href="#top">back to top</a>)</p>

Expand Down
623 changes: 524 additions & 99 deletions SunGather/registers.yaml

Large diffs are not rendered by default.

16 changes: 11 additions & 5 deletions SunGather/sungather.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import importlib
import logging
import logging.handlers
import sys
import getopt
import yaml
Expand Down Expand Up @@ -394,9 +395,10 @@ def scrape(self):

def main():
configfilename = 'config.yaml'
logfolder = ''

try:
opts, args = getopt.getopt(sys.argv[1:],"hc:v:", "runonce")
opts, args = getopt.getopt(sys.argv[1:],"hc:l:v:", "runonce")
except getopt.GetoptError:
logging.debug(f'No options passed via command line')

Expand All @@ -407,14 +409,17 @@ def main():
print(f'\nCommandling arguments override any config file settings')
print(f'Options and arguments:')
print(f'-c config.yaml : Specify config file.')
print(f'-l /logs/ : Specify folder to store logs.')
print(f'-v 30 : Logging Level, 10 = Debug, 20 = Info, 30 = Warning (default), 40 = Error')
print(f'--runonce : Run once then exit')
print(f'-h : print this help message and exit (also --help)')
print(f'\nExample:')
print(f'python3 sungather.py -c /full/path/config.yaml\n')
sys.exit()
elif opt == '-c':
configfilename = arg
configfilename = arg
elif opt == '-l':
logfolder = arg
elif opt == '-v':
if arg.isnumeric():
if int(arg) >= 0 and int(arg) <= 50:
Expand All @@ -426,7 +431,7 @@ def main():
logging.error(f"Valid verbose options: 10 = Debug, 20 = Info, 30 = Warning (default), 40 = Error")
sys.exit(2)
elif opt == '--runonce':
runonce = True
runonce = True

logging.info(f'Starting SunGather {__version__}')

Expand All @@ -443,6 +448,7 @@ def main():
try:
registersfile = yaml.safe_load(open('registers.yaml'))
logging.info(f"Loaded registers: {os.getcwd()}/registers.yaml")
logging.info(f"Registers file version: {registersfile.get('version','UNKNOWN')}")
except Exception as err:
logging.error(f"Failed: Loading registers: {os.getcwd()}/registers.yaml {err}")
sys.exit(f"Failed: Loading registers: {os.getcwd()}/registers.yaml {err}")
Expand Down Expand Up @@ -470,8 +476,8 @@ def main():

if not config_inverter['log_file'] == "OFF":
if config_inverter['log_file'] == "DEBUG" or config_inverter['log_file'] == "INFO" or config_inverter['log_file'] == "WARNING" or config_inverter['log_file'] == "ERROR":
logfile = datetime.now().strftime("%Y%m%d_%H%M%S_SunGather.log")
fh = logging.FileHandler(logfile, mode='w', encoding='utf-8')
logfile = logfolder + "SunGather.log"
fh = logging.handlers.RotatingFileHandler(logfile, mode='w', encoding='utf-8', maxBytes=10485760, backupCount=10) # Log 10mb files, 10 x files = 100mb
fh.formatter = logger.handlers[0].formatter
fh.setLevel(config_inverter['log_file'])
logger.addHandler(fh)
Expand Down
2 changes: 1 addition & 1 deletion SunGather/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.3.5'
__version__ = '0.3.6'

0 comments on commit dfe0e44

Please sign in to comment.