123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- import config
- import function
- import json
- import logging
- import mqtt
- import os
- import report
- import subprocess
- import time
-
- logger = logging.getLogger(config.APP_NAME)
-
-
- VERS_MAJOR = 1
- VERS_MINOR = 2
- VERS_PATCH = 6
-
- INFO_TOPIC = "__info__"
- INFO_DATA = {
- "app_name": os.path.splitext(os.path.basename(__file__))[0],
- "version": {
- "readable": "%d.%d.%d" % (VERS_MAJOR, VERS_MINOR, VERS_PATCH),
- "major": VERS_MAJOR,
- "minor": VERS_MINOR,
- "patch": VERS_PATCH
- },
- "git": {
- "url": subprocess.check_output(["git", "config", "--get", "remote.origin.url"])[:-1].decode("utf-8"),
- "ref": subprocess.check_output(["git", "log", "-1", '--format="%H"'])[1:-2].decode("utf-8")
- }
- }
-
-
- def __info_publisher__(client, userdata, message):
- data = json.loads(message.payload)
- if data != INFO_DATA:
- client.publish(INFO_TOPIC, json.dumps(INFO_DATA))
-
-
- if __name__ == "__main__":
- if config.DEBUG:
- report.appLoggingConfigure(None, 'stdout', ((config.APP_NAME, logging.DEBUG), ),
- target_level=logging.WARNING, fmt=report.SHORT_FMT, host='localhost', port=19996)
- else:
- report.stdoutLoggingConfigure(((config.APP_NAME, logging.WARNING), ), report.SHORT_FMT)
- #
- mc = mqtt.mqtt_client(host=config.MQTT_SERVER, port=config.MQTT_PORT, username=config.MQTT_USER,
- password=config.MQTT_PASSWORD, name=config.APP_NAME)
- mc.add_callback(INFO_TOPIC, __info_publisher__)
-
- func = function.all_functions(mc)
-
- while (True):
- time.sleep(1)
|