Uhm. Pulling names now.

This commit is contained in:
Mike 2020-07-26 01:59:59 +01:00
parent 8b29523643
commit e8ef1e0b11
6 changed files with 192 additions and 0 deletions

72
MikesServoMapper.py Normal file
View File

@ -0,0 +1,72 @@
import logging
import pprint
import sys
import yaml
class MikesServoMapper:
def __init__(self, config_file: str, names):
# noinspection PyTypeChecker
self.__logger: logging.Logger = None
self.__logger_formatter = None
self.init_logging()
self.__names = list(names)
self.__names.sort()
self.__config = None
self.load_config(config_file)
self.pull_config_names()
self.__logger.info("Names: %s" % (pprint.pformat(self.__names)))
def init_logging(self):
self.__logger = logging.Logger("Mikes Servo Mapper")
self.__logger_formatter = logging.Formatter(fmt="Hi poop")
stream_handler = logging.StreamHandler(sys.stdout)
self.__logger.addHandler(stream_handler)
self.__logger.info("Logging initialized")
def load_config(self, config_file):
if config_file is None:
return
with open(config_file) as f:
config = yaml.safe_load(f)
self.__logger.info("Loaded config: %s" % (pprint.pformat(config),))
self.__config = config
def pull_config_names(self):
if self.__config is None:
self.__logger.info("No config specified; Won't pull names")
return
self.__logger.info("Pulling names from config")
if "names" not in self.__config:
self.__logger.warning("Key \"names\" is not in config; Cannot pull names")
return
config_names = self.__config["names"]
if not isinstance(config_names, list):
self.__logger.warning("Config had key \"names\" but it wasn't a list; Won't pull names")
return
self.__logger.info("Names before pulling from config: %s" % (self.__names,))
for name in config_names:
self.__names.append(name)
self.__names.sort()
self.__logger.info("Names after pulling from config: %s" % (self.__names,))

View File

@ -4,6 +4,7 @@ verify_ssl = true
name = "pypi"
[packages]
pyaml = "*"
[dev-packages]

45
Pipfile.lock generated Normal file
View File

@ -0,0 +1,45 @@
{
"_meta": {
"hash": {
"sha256": "1f84f63565324f6ff4b4071af61c776885d170eed424917d7adb74b2b97517e3"
},
"pipfile-spec": 6,
"requires": {
"python_version": "3.7"
},
"sources": [
{
"name": "pypi",
"url": "https://pypi.python.org/simple",
"verify_ssl": true
}
]
},
"default": {
"pyaml": {
"hashes": [
"sha256:29a5c2a68660a799103d6949167bd6c7953d031449d08802386372de1db6ad71",
"sha256:67081749a82b72c45e5f7f812ee3a14a03b3f5c25ff36ec3b290514f8c4c4b99"
],
"index": "pypi",
"version": "==20.4.0"
},
"pyyaml": {
"hashes": [
"sha256:06a0d7ba600ce0b2d2fe2e78453a470b5a6e000a985dd4a4e54e436cc36b0e97",
"sha256:240097ff019d7c70a4922b6869d8a86407758333f02203e0fc6ff79c5dcede76",
"sha256:4f4b913ca1a7319b33cfb1369e91e50354d6f07a135f3b901aca02aa95940bd2",
"sha256:69f00dca373f240f842b2931fb2c7e14ddbacd1397d57157a9b005a6a9942648",
"sha256:73f099454b799e05e5ab51423c7bcf361c58d3206fa7b0d555426b1f4d9a3eaf",
"sha256:74809a57b329d6cc0fdccee6318f44b9b8649961fa73144a98735b0aaf029f1f",
"sha256:7739fc0fa8205b3ee8808aea45e968bc90082c10aef6ea95e855e10abf4a37b2",
"sha256:95f71d2af0ff4227885f7a6605c37fd53d3a106fcab511b8860ecca9fcf400ee",
"sha256:b8eac752c5e14d3eca0e6dd9199cd627518cb5ec06add0de9d32baeee6fe645d",
"sha256:cc8955cfbfc7a115fa81d85284ee61147059a753344bc51098f3ccd69b0d7e0c",
"sha256:d13155f591e6fcc1ec3b30685d50bf0711574e2c0dfffd7644babf8b5102ca1a"
],
"version": "==5.3.1"
}
},
"develop": {}
}

28
README.md Normal file
View File

@ -0,0 +1,28 @@
# Mike's Servo Mapper
A simple command line utility to map servos to
Written and tested using the Adafruit I2C servo driver board: [PCA9685](https://www.adafruit.com/product/815)
## Requiremments
* ```pipenv```
## Installation
cd to this repo's directory and install pip dependencies with:
```pipenv install```
## Execution
cd to this repo's directory and execute using:
```pipenv run python3 main.py```
## Command Line Arguments
TODO

5
configs/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
# Ignore any configs placed here
*.yaml

41
main.py Normal file
View File

@ -0,0 +1,41 @@
from MikesServoMapper import MikesServoMapper
import argparse
def main():
parser = argparse.ArgumentParser(
prog="Mike's Servo Mapper (for adafruit driver board)"
)
parser.add_argument(
"--config", "--config-file",
help="Path to a yaml file describing some configuration stuffs",
required=False,
default=None,
dest="config_file"
)
parser.add_argument(
"--name",
help="Specify a target name (can be used multiple times)",
required=False,
default=[],
action="append",
dest="names"
)
args = parser.parse_args()
mapper = MikesServoMapper(
config_file=args.config_file,
names=args.names
)
mapper.run()
if __name__ == "__main__":
main()