Can build torch-pub.exe and load config file

This commit is contained in:
B.J. Dweck 2020-10-16 15:04:50 +02:00
parent 363a214f13
commit 9716f0199f
6 changed files with 81 additions and 28 deletions

3
pyproject.toml Normal file
View File

@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

34
setup.cfg Normal file
View File

@ -0,0 +1,34 @@
# import setuptools
# import torchsub
#
# setuptools.setup(
# name="torchsub",
# version=torchsub.__version__,
# author='Benjamin Dweck',
# author_email='bjdweck@gmail.com',
# url='http://git.rudefox.io/bj/torch-subscriber-simple',
# packages=setuptools.find_packages(),
# entry_points={
# 'console_scripts': ['torch-sub=torchsub.torch_sub:main'],
# },
# classifiers=[
# "Programming Language :: Python :: 3",
# "License :: OSI Approved :: MIT License",
# ],
# )
[metadata]
name = torchsub
version = 0.0.1
[options]
packages = find:
install_requires =
paho-mqtt~=1.5.1
[options.entry_points]
console_scripts =
torch-sub=torchsub.torch_sub:main
[options.packages.find]
exclude=test

View File

@ -1,19 +1,22 @@
from setuptools import setup # import setuptools
# import torchsub
#
# setuptools.setup(
# name="torchsub",
# version=torchsub.__version__,
# author='Benjamin Dweck',
# author_email='bjdweck@gmail.com',
# url='http://git.rudefox.io/bj/torch-subscriber-simple',
# packages=setuptools.find_packages(),
# entry_points={
# 'console_scripts': ['torch-sub=torchsub.torch_sub:main'],
# },
# classifiers=[
# "Programming Language :: Python :: 3",
# "License :: OSI Approved :: MIT License",
# ],
# )
setup( import setuptools
name='torch-subscriber-simple',
version='0.0.1', setuptools.setup()
packages=['torch_sub', 'torch_sub.test'],
url='http://git.rudefox.io/bj/torch-subscriber-simple',
license='MIT',
author='Benjamin Dweck',
author_email='bjdweck@gmail.com',
description='',
entry_points={
'console_scripts': ['torch-sub=torch_sub.torch_sub:main'],
},
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
],
)

View File

@ -10,7 +10,7 @@ from unittest.case import TestCase
import paho.mqtt.client as mqtt import paho.mqtt.client as mqtt
from torch_sub import torch_sub from torchsub import torch_sub
broker_hostname = "mqtt.example.com" broker_hostname = "mqtt.example.com"
broker_port = 8883 broker_port = 8883

View File

@ -2,6 +2,7 @@ import argparse
import configparser import configparser
import json import json
import os import os
import sys
import threading import threading
import paho.mqtt.subscribe as mqtt import paho.mqtt.subscribe as mqtt
@ -47,15 +48,23 @@ class Config:
self.topic = None self.topic = None
self.tls = None self.tls = None
parser = self.do_cli_argument_parsing() parser = self.do_cli_argument_parsing()
config_path = self.get_config_path(parser.parse_args()) (config_path, config_filename) = self.get_config_path(parser.parse_args())
print("Using torch configuration path: " + config_path) print("Using torch configuration path: " + config_path)
self.read_configuration_file(config_path) self.read_configuration_file(config_path, config_filename)
@staticmethod @staticmethod
def do_cli_argument_parsing(): def do_cli_argument_parsing():
parser = argparse.ArgumentParser(description='Simple Torch Flat-file Database Subscriber') parser = argparse.ArgumentParser(description='Simple Torch Flat-file Database Subscriber')
parser.add_argument('--config-dir', nargs='?', dest='configPath', default='/etc/torch', parser.add_argument('--config-dir',
nargs='?',
dest='configPath',
default='/etc/torch',
help='configuration directory (default: /etc/torch)') help='configuration directory (default: /etc/torch)')
parser.add_argument('--config-filename',
nargs='?',
dest='configFilename',
default='torch-sub.conf',
help='configuration filename (default: torch-sub.conf)')
return parser return parser
@staticmethod @staticmethod
@ -65,19 +74,23 @@ class Config:
config_path = os.environ.get("TORCH_CONFIG_DIR") config_path = os.environ.get("TORCH_CONFIG_DIR")
if not config_path.endswith("/"): if not config_path.endswith("/"):
config_path = config_path + "/" config_path = config_path + "/"
return config_path return config_path, args.configFilename
def read_configuration_file(self, config_path): def read_configuration_file(self, config_dir, config_filename):
config_file_path = os.path.join(config_dir, config_filename)
if not os.path.exists(config_file_path):
print("Unable to locate config file at '%s'" % config_file_path)
sys.exit(1)
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read(config_path + "torch-sub.conf") config.read(config_file_path)
mqtt_config = config['mqtt'] mqtt_config = config['mqtt']
self.broker_hostname = mqtt_config.get('BrokerHost', fallback="localhost") self.broker_hostname = mqtt_config.get('BrokerHost', fallback="localhost")
self.broker_port = mqtt_config.getint('BrokerPort', fallback=1883) self.broker_port = mqtt_config.getint('BrokerPort', fallback=1883)
self.topic = mqtt_config.get('Topic', fallback="torch/+/onion_url") self.topic = mqtt_config.get('Topic', fallback="torch/+/onion_url")
require_certificate = mqtt_config.getboolean('RequireCertificate', fallback=False) require_certificate = mqtt_config.getboolean('RequireCertificate', fallback=False)
ca_file = config_path + mqtt_config.get('CaFile') ca_file = config_dir + mqtt_config.get('CaFile', "")
cert_file = config_path + mqtt_config.get('CertFile') cert_file = config_dir + mqtt_config.get('CertFile', "")
key_file = config_path + mqtt_config.get('KeyFile') key_file = config_dir + mqtt_config.get('KeyFile', "")
self.tls = None self.tls = None
if require_certificate: if require_certificate:
self.tls = { self.tls = {