Skip to content

Commit 2d5e30f

Browse files
committed
initial version
1 parent 0dca191 commit 2d5e30f

17 files changed

+1169
-1
lines changed

.flake8

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[flake8]
2+
max-line-length=160

.gitignore

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# Generated
2+
_version.py
3+
4+
# Byte-compiled / optimized / DLL files
5+
__pycache__/
6+
*.py[cod]
7+
*$py.class
8+
9+
# C extensions
10+
*.so
11+
12+
# Distribution / packaging
13+
.Python
14+
build/
15+
develop-eggs/
16+
dist/
17+
downloads/
18+
eggs/
19+
.eggs/
20+
lib/
21+
lib64/
22+
parts/
23+
sdist/
24+
var/
25+
wheels/
26+
pip-wheel-metadata/
27+
share/python-wheels/
28+
*.egg-info/
29+
.installed.cfg
30+
*.egg
31+
MANIFEST
32+
33+
# PyInstaller
34+
# Usually these files are written by a python script from a template
35+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
36+
*.manifest
37+
*.spec
38+
39+
# Installer logs
40+
pip-log.txt
41+
pip-delete-this-directory.txt
42+
43+
# Unit test / coverage reports
44+
htmlcov/
45+
.tox/
46+
.nox/
47+
.coverage
48+
.coverage.*
49+
.cache
50+
nosetests.xml
51+
coverage.xml
52+
*.cover
53+
*.py,cover
54+
.hypothesis/
55+
.pytest_cache/
56+
57+
# Translations
58+
*.mo
59+
*.pot
60+
61+
# Django stuff:
62+
*.log
63+
local_settings.py
64+
db.sqlite3
65+
db.sqlite3-journal
66+
67+
# Flask stuff:
68+
instance/
69+
.webassets-cache
70+
71+
# Scrapy stuff:
72+
.scrapy
73+
74+
# Sphinx documentation
75+
docs/_build/
76+
77+
# PyBuilder
78+
target/
79+
80+
# Jupyter Notebook
81+
.ipynb_checkpoints
82+
83+
# IPython
84+
profile_default/
85+
ipython_config.py
86+
87+
# pyenv
88+
.python-version
89+
90+
# pipenv
91+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94+
# install all needed dependencies.
95+
#Pipfile.lock
96+
97+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
98+
__pypackages__/
99+
100+
# Celery stuff
101+
celerybeat-schedule
102+
celerybeat.pid
103+
104+
# SageMath parsed files
105+
*.sage.py
106+
107+
# Environments
108+
.env
109+
.venv
110+
env/
111+
venv/
112+
ENV/
113+
env.bak/
114+
venv.bak/
115+
116+
# Spyder project settings
117+
.spyderproject
118+
.spyproject
119+
120+
# Rope project settings
121+
.ropeproject
122+
123+
# mkdocs documentation
124+
/site
125+
126+
# mypy
127+
.mypy_cache/
128+
.dmypy.json
129+
dmypy.json
130+
131+
# Pyre type checker
132+
.pyre/

Makefile

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
MODULE := carconnectivity.carconnectivity
2+
BLUE='\033[0;34m'
3+
NC='\033[0m' # No Color
4+
5+
run:
6+
@python -m $(MODULE)
7+
8+
test:
9+
@pytest
10+
11+
lint:
12+
@echo "\n${BLUE}Running Pylint against source and test files...${NC}\n"
13+
@pylint ./examples ./src ./tests
14+
@echo "\n${BLUE}Running Flake8 against source and test files...${NC}\n"
15+
@flake8
16+
@echo "\n${BLUE}Running Bandit against source files...${NC}\n"
17+
@bandit -c pyproject.toml -r .
18+
19+
clean:
20+
rm -rf .pytest_cache .coverage .pytest_cache coverage.xml coverage_html_report
21+
22+
.PHONY: clean test

examples/all_cars.py

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
"""
2+
This script is an example showing how to retrieve all vehicles from the account using the CarConnectivity library.
3+
4+
Functions:
5+
main: The main function that sets up argument parsing, logging, and retrieves vehicle data.
6+
7+
Usage:
8+
python all_cars.py <config> [--tokenstorefile TOKENSTOREFILE] [-v] [--logging-format LOGGING_FORMAT] [--logging-date-format LOGGING_DATE_FORMAT]
9+
10+
Arguments:
11+
config: Path to the configuration file.
12+
--tokenstorefile: File to store tokenstore (default: /tmp/tokenstore).
13+
-v, --verbose: Logging level (verbosity).
14+
--logging-format: Logging format configured for python logging (default: %(asctime)s:%(levelname)s:%(message)s).
15+
--logging-date-format: Logging date format configured for python logging (default: %Y-%m-%dT%H:%M:%S%z).
16+
17+
Logging Levels:
18+
DEBUG, INFO, WARNING, ERROR, CRITICAL
19+
20+
Example:
21+
python all_cars.py config.json --tokenstorefile /path/to/tokenstore -v
22+
"""
23+
import argparse
24+
import json
25+
import os
26+
import tempfile
27+
import logging
28+
29+
from carconnectivity import carconnectivity
30+
31+
LOG_LEVELS: list[str] = ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]
32+
DEFAULT_LOG_LEVEL = "ERROR"
33+
LOG: logging.Logger = logging.getLogger("carconnectivity-example")
34+
35+
36+
def main() -> None:
37+
""" Simple example showing how to retrieve all vehicles from the account """
38+
parser = argparse.ArgumentParser(
39+
prog='allCars',
40+
description='Example retrieving all cars in all configured connectors'
41+
)
42+
parser.add_argument('config', help='Path to the configuration file')
43+
default_temp: str = os.path.join(tempfile.gettempdir(), 'tokenstore')
44+
parser.add_argument('--tokenstorefile', help=f'file to store tokenstore (default: {default_temp})', default=default_temp)
45+
46+
logging_group = parser.add_argument_group('Logging')
47+
logging_group.add_argument('-v', '--verbose', action="append_const", help='Logging level (verbosity)', const=-1,)
48+
logging_group.add_argument('--logging-format', dest='logging_format', help='Logging format configured for python logging '
49+
'(default: %%(asctime)s:%%(module)s:%%(message)s)', default='%(asctime)s:%(levelname)s:%(message)s')
50+
logging_group.add_argument('--logging-date-format', dest='logging_date_format', help='Logging format configured for python logging '
51+
'(default: %%Y-%%m-%%dT%%H:%%M:%%S%%z)', default='%Y-%m-%dT%H:%M:%S%z')
52+
53+
args = parser.parse_args()
54+
55+
log_level: int = LOG_LEVELS.index(DEFAULT_LOG_LEVEL)
56+
for adjustment in args.verbose or ():
57+
log_level = min(len(LOG_LEVELS) - 1, max(log_level + adjustment, 0))
58+
59+
logging.basicConfig(level=LOG_LEVELS[log_level], format=args.logging_format, datefmt=args.logging_date_format)
60+
61+
print('# read CarConnectivity configuration')
62+
with open(args.config, 'r', encoding='utf-8') as config_file:
63+
config_dict = json.load(config_file)
64+
print('# Login')
65+
car_connectivity = carconnectivity.CarConnectivity(config=config_dict, tokenstore_file=args.tokenstorefile)
66+
print('# getData')
67+
car_connectivity.get_garage()
68+
print('# Shutdown')
69+
car_connectivity.shutdown()
70+
71+
print('# done')
72+
73+
74+
if __name__ == '__main__':
75+
main()

pyproject.toml

+11-1
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ requires = [
44
"setuptools_scm>=8"
55
]
66
build-backend = "setuptools.build_meta"
7-
dynamic = ["version"]
87

98
[project]
109
name = "carconnectivity"
1110
description = "Library for retrieving information from car connectivity services"
11+
dynamic = ["version"]
1212
requires-python = ">=3.8"
1313
authors = [
1414
{ name = "Till Steinbach" }
@@ -34,3 +34,13 @@ classifiers = [
3434

3535
[project.scripts]
3636
allcars = "allCars:main"
37+
38+
[tool.setuptools_scm]
39+
write_to = "src/carconnectivity/_version.py"
40+
41+
[tool.pylint.format]
42+
max-line-length = 160
43+
ignore-patterns= "_version.py"
44+
45+
[tool.bandit]
46+
targets = "carconnectivity"

src/carconnectivity/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)