p3lib 1.1.76__tar.gz → 1.1.77__tar.gz
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.
- {p3lib-1.1.76 → p3lib-1.1.77}/PKG-INFO +1 -1
- {p3lib-1.1.76 → p3lib-1.1.77}/setup.cfg +1 -1
- {p3lib-1.1.76 → p3lib-1.1.77}/src/p3lib/boot_manager.py +65 -22
- {p3lib-1.1.76 → p3lib-1.1.77}/src/p3lib.egg-info/PKG-INFO +1 -1
- {p3lib-1.1.76 → p3lib-1.1.77}/LICENSE +0 -0
- {p3lib-1.1.76 → p3lib-1.1.77}/README.md +0 -0
- {p3lib-1.1.76 → p3lib-1.1.77}/pyproject.toml +0 -0
- {p3lib-1.1.76 → p3lib-1.1.77}/src/p3lib/__init__.py +0 -0
- {p3lib-1.1.76 → p3lib-1.1.77}/src/p3lib/ate.py +0 -0
- {p3lib-1.1.76 → p3lib-1.1.77}/src/p3lib/bokeh_auth.py +0 -0
- {p3lib-1.1.76 → p3lib-1.1.77}/src/p3lib/bokeh_gui.py +0 -0
- {p3lib-1.1.76 → p3lib-1.1.77}/src/p3lib/conduit.py +0 -0
- {p3lib-1.1.76 → p3lib-1.1.77}/src/p3lib/database_if.py +0 -0
- {p3lib-1.1.76 → p3lib-1.1.77}/src/p3lib/helper.py +0 -0
- {p3lib-1.1.76 → p3lib-1.1.77}/src/p3lib/json_networking.py +0 -0
- {p3lib-1.1.76 → p3lib-1.1.77}/src/p3lib/mqtt_rpc.py +0 -0
- {p3lib-1.1.76 → p3lib-1.1.77}/src/p3lib/netif.py +0 -0
- {p3lib-1.1.76 → p3lib-1.1.77}/src/p3lib/netplotly.py +0 -0
- {p3lib-1.1.76 → p3lib-1.1.77}/src/p3lib/ngt.py +0 -0
- {p3lib-1.1.76 → p3lib-1.1.77}/src/p3lib/pconfig.py +0 -0
- {p3lib-1.1.76 → p3lib-1.1.77}/src/p3lib/ssh.py +0 -0
- {p3lib-1.1.76 → p3lib-1.1.77}/src/p3lib/table_plot.py +0 -0
- {p3lib-1.1.76 → p3lib-1.1.77}/src/p3lib/uio.py +0 -0
- {p3lib-1.1.76 → p3lib-1.1.77}/src/p3lib.egg-info/SOURCES.txt +0 -0
- {p3lib-1.1.76 → p3lib-1.1.77}/src/p3lib.egg-info/dependency_links.txt +0 -0
- {p3lib-1.1.76 → p3lib-1.1.77}/src/p3lib.egg-info/requires.txt +0 -0
- {p3lib-1.1.76 → p3lib-1.1.77}/src/p3lib.egg-info/top_level.txt +0 -0
- {p3lib-1.1.76 → p3lib-1.1.77}/tests/test_conduit.py +0 -0
- {p3lib-1.1.76 → p3lib-1.1.77}/tests/test_json_networking.py +0 -0
- {p3lib-1.1.76 → p3lib-1.1.77}/tests/test_netif.py +0 -0
- {p3lib-1.1.76 → p3lib-1.1.77}/tests/test_ssh.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: p3lib
|
3
|
-
Version: 1.1.
|
3
|
+
Version: 1.1.77
|
4
4
|
Summary: A group of python modules for networking, plotting data, config storage, automating boot scripts, ssh access and user input output.
|
5
5
|
Home-page: https://github.com/pjaos/p3lib
|
6
6
|
Author: Paul Austen
|
@@ -1,6 +1,6 @@
|
|
1
1
|
[metadata]
|
2
2
|
name = p3lib
|
3
|
-
version = 1.1.
|
3
|
+
version = 1.1.77
|
4
4
|
author = Paul Austen
|
5
5
|
author_email = pausten.os@gmail.com
|
6
6
|
description = A group of python modules for networking, plotting data, config storage, automating boot scripts, ssh access and user input output.
|
@@ -3,6 +3,7 @@
|
|
3
3
|
import os
|
4
4
|
import sys
|
5
5
|
import platform
|
6
|
+
import getpass
|
6
7
|
|
7
8
|
from subprocess import check_call, DEVNULL, STDOUT, Popen, PIPE
|
8
9
|
from datetime import datetime
|
@@ -35,10 +36,10 @@ class BootManager(object):
|
|
35
36
|
else:
|
36
37
|
raise Exception("{} is an unsupported OS.".format(self._osName) )
|
37
38
|
|
38
|
-
def add(self, user, argString=None, enableSyslog=False):
|
39
|
+
def add(self, user=None, argString=None, enableSyslog=False):
|
39
40
|
"""@brief Add an executable file to the processes started at boot time.
|
40
41
|
@param exeFile The file/program to be executed. This should be an absolute path.
|
41
|
-
@param user The user that will run the executable file.
|
42
|
+
@param user The user that will run the executable file. If left as None then the current user will be used.
|
42
43
|
@param argString The argument string that the program is to be launched with.
|
43
44
|
@param enableSyslog If True enable stdout and stderr to be sent to syslog."""
|
44
45
|
if self._platformBootManager:
|
@@ -63,9 +64,41 @@ class BootManager(object):
|
|
63
64
|
class LinuxBootManager(object):
|
64
65
|
"""@brief Responsible for adding/removing Linux services using systemd."""
|
65
66
|
|
66
|
-
LOG_PATH="/var/log"
|
67
|
-
|
68
|
-
|
67
|
+
LOG_PATH ="/var/log"
|
68
|
+
ROOT_SERVICE_FOLDER = "/etc/systemd/system/"
|
69
|
+
SYSTEM_CTL_1 = "/bin/systemctl"
|
70
|
+
SYSTEM_CTL_2 = "/usr/bin/systemctl"
|
71
|
+
|
72
|
+
@staticmethod
|
73
|
+
def GetSystemCTLBin():
|
74
|
+
"""@brief Get the location of the systemctl binary file on this system.
|
75
|
+
@return The systemctl bin file."""
|
76
|
+
binFile = None
|
77
|
+
if os.path.isfile(LinuxBootManager.SYSTEM_CTL_1):
|
78
|
+
binFile = LinuxBootManager.SYSTEM_CTL_1
|
79
|
+
elif os.path.isfile(LinuxBootManager.SYSTEM_CTL_2):
|
80
|
+
binFile = LinuxBootManager.SYSTEM_CTL_2
|
81
|
+
else:
|
82
|
+
raise Exception("Failed to find the location of the systemctl bin file on this machine.")
|
83
|
+
return binFile
|
84
|
+
|
85
|
+
@staticmethod
|
86
|
+
def GetServiceFolder(rootUser):
|
87
|
+
""""@brief Get the service folder to use.
|
88
|
+
@param rootUser False if non root user.
|
89
|
+
@return The folder that should hold the systemctl service files."""
|
90
|
+
serviceFolder = None
|
91
|
+
if rootUser:
|
92
|
+
serviceFolder = LinuxBootManager.ROOT_SERVICE_FOLDER
|
93
|
+
else:
|
94
|
+
homeFolder = os.path.expanduser('~')
|
95
|
+
serviceFolder = os.path.join(homeFolder, '.config/systemd/user/')
|
96
|
+
if not os.path.isdir(serviceFolder):
|
97
|
+
os.makedirs(serviceFolder)
|
98
|
+
|
99
|
+
if not os.path.isdir(serviceFolder):
|
100
|
+
raise Exception(f"{serviceFolder} folder not found.")
|
101
|
+
return serviceFolder
|
69
102
|
|
70
103
|
def __init__(self, uio, allowRootUser):
|
71
104
|
"""@brief Constructor
|
@@ -74,12 +107,20 @@ class LinuxBootManager(object):
|
|
74
107
|
self._uio = uio
|
75
108
|
self._logFile = None
|
76
109
|
self._allowRootUser=allowRootUser
|
77
|
-
|
78
|
-
if os.geteuid() != 0:
|
79
|
-
self._fatalError("Please run this command with root level access.")
|
80
|
-
|
81
110
|
self._info("OS: {}".format(platform.system()) )
|
82
|
-
|
111
|
+
self._rootMode = False # If True run as root, else False.
|
112
|
+
self._systemCtlBin = LinuxBootManager.GetSystemCTLBin()
|
113
|
+
if os.geteuid() == 0:
|
114
|
+
if not allowRootUser:
|
115
|
+
self._fatalError(self.__class__.__name__ + f": You are running as root user but allowRootUser={allowRootUser}.")
|
116
|
+
else:
|
117
|
+
self._rootMode = True
|
118
|
+
if not self._rootMode:
|
119
|
+
self._cmdLinePrefix = self._systemCtlBin + " --user"
|
120
|
+
else:
|
121
|
+
self._cmdLinePrefix = self._systemCtlBin
|
122
|
+
self._username = getpass.getuser()
|
123
|
+
self._serviceFolder = LinuxBootManager.GetServiceFolder(self._rootMode)
|
83
124
|
self._appName = None
|
84
125
|
|
85
126
|
def _getInstallledStartupScript(self):
|
@@ -188,7 +229,9 @@ class LinuxBootManager(object):
|
|
188
229
|
self._fatalError("{} file not found.".format(absApp) )
|
189
230
|
|
190
231
|
appName = appName.replace(".py", "")
|
191
|
-
self.
|
232
|
+
if self._rootMode:
|
233
|
+
# We can only save to /var/log/ is we are root user.
|
234
|
+
self._logFile = os.path.join(LinuxBootManager.LOG_PATH, appName)
|
192
235
|
|
193
236
|
return (appName, absApp)
|
194
237
|
|
@@ -197,7 +240,7 @@ class LinuxBootManager(object):
|
|
197
240
|
@param appName The name of the app to execute.
|
198
241
|
@return The absolute path to the service file """
|
199
242
|
serviceName = "{}.service".format(appName)
|
200
|
-
serviceFile = os.path.join(
|
243
|
+
serviceFile = os.path.join(self._serviceFolder, serviceName)
|
201
244
|
return serviceFile
|
202
245
|
|
203
246
|
def add(self, user, argString=None, enableSyslog=False):
|
@@ -209,9 +252,9 @@ class LinuxBootManager(object):
|
|
209
252
|
to non root user paths on Linux systems and the startup
|
210
253
|
script should then be executed with the same username in
|
211
254
|
order that the same config file is used.
|
255
|
+
If set to None then the current user is used.
|
212
256
|
@param argString The argument string that the program is to be launched with.
|
213
257
|
@param enableSyslog If True enable stdout and stderr to be sent to syslog."""
|
214
|
-
|
215
258
|
appName, absApp = self._getApp()
|
216
259
|
|
217
260
|
serviceFile = self._getServiceFile(appName)
|
@@ -253,12 +296,12 @@ class LinuxBootManager(object):
|
|
253
296
|
except IOError:
|
254
297
|
self._fatalError("Failed to create {}".format(serviceFile) )
|
255
298
|
|
256
|
-
cmd = "{} daemon-reload".format(
|
299
|
+
cmd = "{} daemon-reload".format(self._cmdLinePrefix)
|
257
300
|
self._runLocalCmd(cmd)
|
258
|
-
cmd = "{} enable {}".format(
|
301
|
+
cmd = "{} enable {}".format(self._cmdLinePrefix, appName)
|
259
302
|
self._info("Enabled {} on restart".format(appName))
|
260
303
|
self._runLocalCmd(cmd)
|
261
|
-
cmd = "{} start {}".format(
|
304
|
+
cmd = "{} start {}".format(self._cmdLinePrefix, appName)
|
262
305
|
self._runLocalCmd(cmd)
|
263
306
|
self._info("Started {}".format(appName))
|
264
307
|
|
@@ -270,11 +313,11 @@ class LinuxBootManager(object):
|
|
270
313
|
|
271
314
|
serviceFile = self._getServiceFile(appName)
|
272
315
|
if os.path.isfile(serviceFile):
|
273
|
-
cmd = "{} disable {}".format(
|
316
|
+
cmd = "{} disable {}".format(self._cmdLinePrefix, appName)
|
274
317
|
self._runLocalCmd(cmd)
|
275
318
|
self._info("Disabled {} on restart".format(appName))
|
276
319
|
|
277
|
-
cmd = "{} stop {}".format(
|
320
|
+
cmd = "{} stop {}".format(self._cmdLinePrefix, appName)
|
278
321
|
self._runLocalCmd(cmd)
|
279
322
|
self._info("Stopped {}".format(appName))
|
280
323
|
|
@@ -287,11 +330,11 @@ class LinuxBootManager(object):
|
|
287
330
|
"""@brief Get a status report.
|
288
331
|
@return Lines of text indicating the status of a previously started process."""
|
289
332
|
appName, _ = self._getApp()
|
290
|
-
|
333
|
+
if self._rootMode:
|
334
|
+
p = Popen([self._systemCtlBin, 'status', appName], stdin=PIPE, stdout=PIPE, stderr=PIPE)
|
335
|
+
else:
|
336
|
+
p = Popen([self._systemCtlBin, '--user', 'status', appName], stdin=PIPE, stdout=PIPE, stderr=PIPE)
|
291
337
|
output, err = p.communicate(b"input data that is passed to subprocess' stdin")
|
292
338
|
response = output.decode() + "\n" + err.decode()
|
293
339
|
lines = response.split("\n")
|
294
340
|
return lines
|
295
|
-
|
296
|
-
|
297
|
-
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: p3lib
|
3
|
-
Version: 1.1.
|
3
|
+
Version: 1.1.77
|
4
4
|
Summary: A group of python modules for networking, plotting data, config storage, automating boot scripts, ssh access and user input output.
|
5
5
|
Home-page: https://github.com/pjaos/p3lib
|
6
6
|
Author: Paul Austen
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|