quarchpy 2.1.26__py2.py3-none-any.whl → 2.1.27__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- quarchpy/__pycache__/_version.cpython-311.pyc +0 -0
- quarchpy/_version.py +1 -1
- quarchpy/_version.py.bak +1 -0
- quarchpy/connection_specific/QPS/qps.jar +0 -0
- quarchpy/connection_specific/__pycache__/mDNS.cpython-311.pyc +0 -0
- quarchpy/connection_specific/mDNS.py +20 -5
- quarchpy/connection_specific/mDNS.py.bak +141 -0
- quarchpy/docs/CHANGES.rst +5 -0
- quarchpy/docs/_build/doctrees/CHANGES.doctree +0 -0
- quarchpy/docs/_build/doctrees/environment.pickle +0 -0
- quarchpy/docs/_build/doctrees/source/changelog.doctree +0 -0
- quarchpy/docs/_build/html/CHANGES.html +132 -125
- quarchpy/docs/_build/html/_sources/CHANGES.rst.txt +5 -0
- quarchpy/docs/_build/html/index.html +64 -63
- quarchpy/docs/_build/html/searchindex.js +1 -1
- quarchpy/docs/_build/html/source/changelog.html +196 -188
- {quarchpy-2.1.26.dist-info → quarchpy-2.1.27.dist-info}/METADATA +6 -1
- {quarchpy-2.1.26.dist-info → quarchpy-2.1.27.dist-info}/RECORD +20 -22
- quarchpy/__pycache__/run.cpython-311.pyc +0 -0
- quarchpy/debug/__pycache__/module_debug.cpython-311.pyc +0 -0
- quarchpy/debug/__pycache__/simple_terminal.cpython-311.pyc +0 -0
- quarchpy/debug/__pycache__/upgrade_quarchpy.cpython-311.pyc +0 -0
- {quarchpy-2.1.26.dist-info → quarchpy-2.1.27.dist-info}/WHEEL +0 -0
- {quarchpy-2.1.26.dist-info → quarchpy-2.1.27.dist-info}/top_level.txt +0 -0
Binary file
|
quarchpy/_version.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
__version__ = "2.1.
|
1
|
+
__version__ = "2.1.27"
|
quarchpy/_version.py.bak
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
__version__ = "2.1.26"
|
Binary file
|
Binary file
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import platform # For getting the operating system name
|
2
2
|
import subprocess # For executing a shell command
|
3
|
-
|
3
|
+
import logging
|
4
4
|
from zeroconf import Zeroconf
|
5
5
|
|
6
6
|
|
@@ -70,17 +70,27 @@ class MyListener:
|
|
70
70
|
"""
|
71
71
|
Handle service addition event.
|
72
72
|
"""
|
73
|
+
logging.debug("Adding service: " +name)
|
73
74
|
info = zc.get_service_info(type_, name)
|
75
|
+
# Log the service name
|
74
76
|
if "Quarch:" in str(info):
|
75
77
|
# decode the incoming properties from mdns
|
76
|
-
decoded_properties =
|
78
|
+
decoded_properties ={}
|
79
|
+
for key, value in info.properties.items():
|
80
|
+
decoded_properties[ key.decode('utf-8')]=value.decode('utf-8')
|
81
|
+
pass
|
82
|
+
#decoded_properties = {key.decode('utf-8'): value.decode('utf-8') for key, value in info.properties.items()}
|
77
83
|
decoded_ip = ".".join(str(byte) for byte in info.addresses[0])
|
78
84
|
self.get_instance().add_device(decoded_properties, decoded_ip)
|
79
85
|
|
86
|
+
|
87
|
+
|
88
|
+
|
80
89
|
def add_device(self, properties_dict, ip_address):
|
81
90
|
"""
|
82
91
|
Add a device to the found devices dictionary.
|
83
92
|
"""
|
93
|
+
logging.debug("Adding device: " +str(ip_address)+"\n"+str(properties_dict))
|
84
94
|
qtl_num = "QTL" + properties_dict['86'] if '86' in properties_dict else None
|
85
95
|
# Check if module contains REST connection
|
86
96
|
if '84' in properties_dict:
|
@@ -110,11 +120,16 @@ class MyListener:
|
|
110
120
|
Get the found devices and perform ping check.
|
111
121
|
"""
|
112
122
|
temp_dict = self.get_instance().found_devices
|
123
|
+
remove_device = False
|
113
124
|
for key, value in list(temp_dict.items()):
|
114
|
-
|
115
|
-
if
|
125
|
+
can_ping = ping(key[key.index(":") + 1:])
|
126
|
+
if can_ping is False:
|
127
|
+
remove_device=True # Remove the device if it can't be pinged
|
128
|
+
elif self.get_instance().target_conn not in key.lower() and self.get_instance().target_conn.lower() != "all":
|
129
|
+
remove_device = True # or if its of the wrong connection type.
|
130
|
+
if remove_device is True:
|
116
131
|
del self.get_instance().found_devices[key]
|
117
|
-
|
132
|
+
logging.debug("Returning found devices "+str(self.get_instance().found_devices))
|
118
133
|
return self.get_instance().found_devices
|
119
134
|
|
120
135
|
def get_zeroconf(self):
|
@@ -0,0 +1,141 @@
|
|
1
|
+
import platform # For getting the operating system name
|
2
|
+
import subprocess # For executing a shell command
|
3
|
+
import logging
|
4
|
+
from zeroconf import Zeroconf
|
5
|
+
|
6
|
+
|
7
|
+
def ping(host):
|
8
|
+
"""
|
9
|
+
Returns True if host (str) responds to a ping request.
|
10
|
+
"""
|
11
|
+
# Option for the number of packets as a function of
|
12
|
+
param = '-n' if platform.system().lower() == 'windows' else '-c'
|
13
|
+
|
14
|
+
# Building the command. Ex: "ping -c 1 google.com"
|
15
|
+
command = ['ping', param, '1', host]
|
16
|
+
|
17
|
+
# Execute the ping command and capture the output and return code
|
18
|
+
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
19
|
+
|
20
|
+
# Check the return code and output to determine the result
|
21
|
+
if result.returncode == 0 and ("destination host unreachable" not in str(result.stdout).lower()):
|
22
|
+
return True # Ping successful
|
23
|
+
else:
|
24
|
+
return False # Ping failed
|
25
|
+
|
26
|
+
|
27
|
+
class MyListener:
|
28
|
+
"""
|
29
|
+
MyListener class to handle service updates, removals, and additions in Zeroconf
|
30
|
+
"""
|
31
|
+
|
32
|
+
_instance = None
|
33
|
+
|
34
|
+
@classmethod
|
35
|
+
def get_instance(cls):
|
36
|
+
"""
|
37
|
+
Get an instance of MyListener class. If none exists, create one.
|
38
|
+
"""
|
39
|
+
if cls._instance is None:
|
40
|
+
cls._instance = MyListener()
|
41
|
+
return cls._instance
|
42
|
+
|
43
|
+
def __init__(self):
|
44
|
+
"""
|
45
|
+
Initialize MyListener instance.
|
46
|
+
"""
|
47
|
+
self.found_devices = {}
|
48
|
+
self.mdns_service_running = False
|
49
|
+
self.zeroconf = None
|
50
|
+
self.target_conn = None
|
51
|
+
|
52
|
+
def update_service(self, zc, type_, name):
|
53
|
+
"""
|
54
|
+
Handle service update event.
|
55
|
+
"""
|
56
|
+
info = zc.get_service_info(type_, name)
|
57
|
+
if "Quarch:" in str(info):
|
58
|
+
# decode the incoming properties from mdns
|
59
|
+
decoded_properties = {key.decode('utf-8'): value.decode('utf-8') for key, value in info.properties.items()}
|
60
|
+
decoded_ip = ".".join(str(byte) for byte in info.addresses[0])
|
61
|
+
self.get_instance().add_device(decoded_properties, decoded_ip)
|
62
|
+
|
63
|
+
def remove_service(self, zc, type_, name):
|
64
|
+
"""
|
65
|
+
Handle service removal event.
|
66
|
+
"""
|
67
|
+
return None
|
68
|
+
|
69
|
+
def add_service(self, zc, type_, name):
|
70
|
+
"""
|
71
|
+
Handle service addition event.
|
72
|
+
"""
|
73
|
+
logging.warning("Adding service: " +name)
|
74
|
+
info = zc.get_service_info(type_, name)
|
75
|
+
# Log the service name
|
76
|
+
if "Quarch:" in str(info):
|
77
|
+
# decode the incoming properties from mdns
|
78
|
+
decoded_properties ={}
|
79
|
+
for key, value in info.properties.items():
|
80
|
+
decoded_properties[ key.decode('utf-8')]=value.decode('utf-8')
|
81
|
+
pass
|
82
|
+
#decoded_properties = {key.decode('utf-8'): value.decode('utf-8') for key, value in info.properties.items()}
|
83
|
+
decoded_ip = ".".join(str(byte) for byte in info.addresses[0])
|
84
|
+
self.get_instance().add_device(decoded_properties, decoded_ip)
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
def add_device(self, properties_dict, ip_address):
|
90
|
+
"""
|
91
|
+
Add a device to the found devices dictionary.
|
92
|
+
"""
|
93
|
+
logging.warning("Adding device: " +str(ip_address)+"\n"+str(properties_dict))
|
94
|
+
qtl_num = "QTL" + properties_dict['86'] if '86' in properties_dict else None
|
95
|
+
# Check if module contains REST connection
|
96
|
+
if '84' in properties_dict:
|
97
|
+
# Check the user specified connection type
|
98
|
+
if self.get_instance().target_conn == "all" or self.get_instance().target_conn == "rest":
|
99
|
+
if properties_dict['84'] == '80':
|
100
|
+
# print("Rest connection exists for device: " + qtl_num)
|
101
|
+
# Updates the found devices dict
|
102
|
+
self.get_instance().update_device_dict(device_dict={"REST:" + ip_address: qtl_num})
|
103
|
+
# Check if module contains TCP connection
|
104
|
+
if '85' in properties_dict:
|
105
|
+
# Check the user specified connection type
|
106
|
+
if self.get_instance().target_conn == "all" or self.get_instance().target_conn == "tcp":
|
107
|
+
if properties_dict['85'] == "9760":
|
108
|
+
# print("TCP connection exists for device: " + qtl_num)
|
109
|
+
# Updates the found devices dict
|
110
|
+
self.get_instance().update_device_dict(device_dict={"TCP:" + ip_address: qtl_num})
|
111
|
+
|
112
|
+
def update_device_dict(self, device_dict):
|
113
|
+
"""
|
114
|
+
Update the found devices dictionary.
|
115
|
+
"""
|
116
|
+
self.get_instance().found_devices.update(device_dict)
|
117
|
+
|
118
|
+
def get_found_devices(self):
|
119
|
+
"""
|
120
|
+
Get the found devices and perform ping check.
|
121
|
+
"""
|
122
|
+
temp_dict = self.get_instance().found_devices
|
123
|
+
remove_device = False
|
124
|
+
for key, value in list(temp_dict.items()):
|
125
|
+
can_ping = ping(key[key.index(":") + 1:])
|
126
|
+
if can_ping is False:
|
127
|
+
remove_device=True # Remove the device if it can't be pinged
|
128
|
+
elif self.get_instance().target_conn not in key.lower() and self.get_instance().target_conn.lower() != "all":
|
129
|
+
remove_device = True # or if its of the wrong connection type.
|
130
|
+
if remove_device is True:
|
131
|
+
del self.get_instance().found_devices[key]
|
132
|
+
logging.warning("Returning found devices "+str(self.get_instance().found_devices))
|
133
|
+
return self.get_instance().found_devices
|
134
|
+
|
135
|
+
def get_zeroconf(self):
|
136
|
+
"""
|
137
|
+
Get the Zeroconf instance. If none exists, create one.
|
138
|
+
"""
|
139
|
+
if self.get_instance().zeroconf is None:
|
140
|
+
self.get_instance().zeroconf = Zeroconf()
|
141
|
+
return self.get_instance().zeroconf
|
quarchpy/docs/CHANGES.rst
CHANGED
Binary file
|
Binary file
|
Binary file
|