Can build torch-pub.exe and load config file
This commit is contained in:
parent
363a214f13
commit
9716f0199f
3
pyproject.toml
Normal file
3
pyproject.toml
Normal file
|
@ -0,0 +1,3 @@
|
|||
[build-system]
|
||||
requires = ["setuptools", "wheel"]
|
||||
build-backend = "setuptools.build_meta"
|
34
setup.cfg
Normal file
34
setup.cfg
Normal 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
|
39
setup.py
39
setup.py
|
@ -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(
|
||||
name='torch-subscriber-simple',
|
||||
version='0.0.1',
|
||||
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",
|
||||
],
|
||||
)
|
||||
import setuptools
|
||||
|
||||
setuptools.setup()
|
||||
|
|
|
@ -10,7 +10,7 @@ from unittest.case import TestCase
|
|||
|
||||
import paho.mqtt.client as mqtt
|
||||
|
||||
from torch_sub import torch_sub
|
||||
from torchsub import torch_sub
|
||||
|
||||
broker_hostname = "mqtt.example.com"
|
||||
broker_port = 8883
|
||||
|
|
|
@ -2,6 +2,7 @@ import argparse
|
|||
import configparser
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import threading
|
||||
|
||||
import paho.mqtt.subscribe as mqtt
|
||||
|
@ -47,15 +48,23 @@ class Config:
|
|||
self.topic = None
|
||||
self.tls = None
|
||||
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)
|
||||
self.read_configuration_file(config_path)
|
||||
self.read_configuration_file(config_path, config_filename)
|
||||
|
||||
@staticmethod
|
||||
def do_cli_argument_parsing():
|
||||
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)')
|
||||
parser.add_argument('--config-filename',
|
||||
nargs='?',
|
||||
dest='configFilename',
|
||||
default='torch-sub.conf',
|
||||
help='configuration filename (default: torch-sub.conf)')
|
||||
return parser
|
||||
|
||||
@staticmethod
|
||||
|
@ -65,19 +74,23 @@ class Config:
|
|||
config_path = os.environ.get("TORCH_CONFIG_DIR")
|
||||
if not config_path.endswith("/"):
|
||||
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.read(config_path + "torch-sub.conf")
|
||||
config.read(config_file_path)
|
||||
mqtt_config = config['mqtt']
|
||||
self.broker_hostname = mqtt_config.get('BrokerHost', fallback="localhost")
|
||||
self.broker_port = mqtt_config.getint('BrokerPort', fallback=1883)
|
||||
self.topic = mqtt_config.get('Topic', fallback="torch/+/onion_url")
|
||||
require_certificate = mqtt_config.getboolean('RequireCertificate', fallback=False)
|
||||
ca_file = config_path + mqtt_config.get('CaFile')
|
||||
cert_file = config_path + mqtt_config.get('CertFile')
|
||||
key_file = config_path + mqtt_config.get('KeyFile')
|
||||
ca_file = config_dir + mqtt_config.get('CaFile', "")
|
||||
cert_file = config_dir + mqtt_config.get('CertFile', "")
|
||||
key_file = config_dir + mqtt_config.get('KeyFile', "")
|
||||
self.tls = None
|
||||
if require_certificate:
|
||||
self.tls = {
|
Loading…
Reference in New Issue
Block a user