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/_version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "2.1.26"
1
+ __version__ = "2.1.27"
@@ -0,0 +1 @@
1
+ __version__ = "2.1.26"
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 = {key.decode('utf-8'): value.decode('utf-8') for key, value in info.properties.items()}
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
- result = ping(key[key.index(":") + 1:])
115
- if not result or self.get_instance().target_conn not in key.lower():
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
- print(str(self.get_instance().found_devices))
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
@@ -13,6 +13,11 @@ Quarchpy
13
13
  Change Log
14
14
  ----------
15
15
 
16
+ 2.1.27
17
+ ------
18
+ - new QPS 1.41 same QIS 1.43
19
+ - mDNS scanning improvelemts
20
+
16
21
  2.1.26
17
22
  ------
18
23
  - minor bugfix