p3lib 1.1.96__py3-none-any.whl → 1.1.98__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.
- p3lib/boot_manager.py +63 -57
- {p3lib-1.1.96.dist-info → p3lib-1.1.98.dist-info}/METADATA +1 -1
- {p3lib-1.1.96.dist-info → p3lib-1.1.98.dist-info}/RECORD +6 -6
- {p3lib-1.1.96.dist-info → p3lib-1.1.98.dist-info}/LICENSE +0 -0
- {p3lib-1.1.96.dist-info → p3lib-1.1.98.dist-info}/WHEEL +0 -0
- {p3lib-1.1.96.dist-info → p3lib-1.1.98.dist-info}/top_level.txt +0 -0
p3lib/boot_manager.py
CHANGED
@@ -27,68 +27,68 @@ class BootManager(object):
|
|
27
27
|
parser.add_argument(BootManager.CHECK_CMD_OPT, help="Check the status of an auto started icons_gw instance.", action="store_true", default=False)
|
28
28
|
|
29
29
|
@staticmethod
|
30
|
-
def HandleOptions(uio, options, enable_syslog,
|
30
|
+
def HandleOptions(uio, options, enable_syslog, serviceName=None, restartSeconds=1):
|
31
31
|
"""@brief Handle one of the bot manager command line options if the
|
32
32
|
user passed it on the cmd line.
|
33
33
|
@param uio A UIO instance.
|
34
34
|
@param options As returned from parser.parse_args() where parser
|
35
35
|
is an instance of argparse.ArgumentParser.
|
36
36
|
@param enable_syslog True to enable systemd syslog output.
|
37
|
-
@param
|
38
|
-
|
37
|
+
@param serviceName The name of the service. If not set then the name of the initially executed
|
38
|
+
python file is used.
|
39
39
|
@param restartSeconds The number of seconds to sleep before restarting a service that has stopped (default=1).
|
40
40
|
@return True if handled , False if not."""
|
41
41
|
handled = False
|
42
42
|
if options.check_auto_start:
|
43
|
-
BootManager.CheckAutoStartStatus(uio,
|
43
|
+
BootManager.CheckAutoStartStatus(uio, serviceName)
|
44
44
|
handled = True
|
45
45
|
|
46
46
|
elif options.enable_auto_start:
|
47
|
-
BootManager.EnableAutoStart(uio, enable_syslog,
|
47
|
+
BootManager.EnableAutoStart(uio, enable_syslog, serviceName, restartSeconds)
|
48
48
|
handled = True
|
49
49
|
|
50
50
|
elif options.disable_auto_start:
|
51
|
-
BootManager.DisableAutoStart(uio,
|
51
|
+
BootManager.DisableAutoStart(uio, serviceName)
|
52
52
|
handled = True
|
53
53
|
|
54
54
|
return handled
|
55
55
|
|
56
56
|
@staticmethod
|
57
|
-
def EnableAutoStart(uio, enable_syslog,
|
57
|
+
def EnableAutoStart(uio, enable_syslog, serviceName, restartSeconds):
|
58
58
|
"""@brief Enable this program to auto start when the computer on which it is installed starts.
|
59
59
|
@param uio A UIO instance.
|
60
60
|
@param options As returned from parser.parse_args() where parser
|
61
61
|
is an instance of argparse.ArgumentParser.
|
62
62
|
@param enable_syslog True to enable systemd syslog output.
|
63
|
-
@param
|
64
|
-
|
63
|
+
@param serviceName The name of the service. If not set then the name of the initially executed
|
64
|
+
python file is used.
|
65
65
|
@param restartSeconds The number of seconds to sleep before restarting a service that has stopped (default=1)."""
|
66
|
-
bootManager = BootManager(uio=uio, ensureRootUser=True,
|
66
|
+
bootManager = BootManager(uio=uio, ensureRootUser=True, serviceName=serviceName, restartSeconds=restartSeconds)
|
67
67
|
arsString = " ".join(sys.argv)
|
68
68
|
bootManager.add(argString=arsString, enableSyslog=enable_syslog)
|
69
69
|
|
70
70
|
@staticmethod
|
71
|
-
def DisableAutoStart(uio,
|
71
|
+
def DisableAutoStart(uio, serviceName):
|
72
72
|
"""@brief Enable this program to auto start when the computer on which it is installed starts.
|
73
73
|
@param uio A UIO instance.
|
74
|
-
@param
|
75
|
-
|
76
|
-
bootManager = BootManager(uio=uio, ensureRootUser=True,
|
74
|
+
@param serviceName The name of the service. If not set then the name of the initially executed
|
75
|
+
python file is used."""
|
76
|
+
bootManager = BootManager(uio=uio, ensureRootUser=True, serviceName=serviceName)
|
77
77
|
bootManager.remove()
|
78
78
|
|
79
79
|
@staticmethod
|
80
|
-
def CheckAutoStartStatus(uio,
|
80
|
+
def CheckAutoStartStatus(uio, serviceName):
|
81
81
|
"""@brief Check the status of a process previously set to auto start.
|
82
82
|
@param uio A UIO instance.
|
83
|
-
@param
|
84
|
-
|
85
|
-
bootManager = BootManager(uio=uio,
|
83
|
+
@param serviceName The name of the service. If not set then the name of the initially executed
|
84
|
+
python file is used."""
|
85
|
+
bootManager = BootManager(uio=uio, serviceName=serviceName)
|
86
86
|
lines = bootManager.getStatus()
|
87
87
|
if lines and len(lines) > 0:
|
88
88
|
for line in lines:
|
89
89
|
uio.info(line)
|
90
90
|
|
91
|
-
def __init__(self, uio=None, allowRootUser=True, ensureRootUser=False,
|
91
|
+
def __init__(self, uio=None, allowRootUser=True, ensureRootUser=False, serviceName=None, restartSeconds=1):
|
92
92
|
"""@brief Constructor
|
93
93
|
@param uio A UIO instance to display user output. If unset then no output
|
94
94
|
is displayed to user.
|
@@ -98,15 +98,15 @@ class BootManager(object):
|
|
98
98
|
the installed program should be installed for the root
|
99
99
|
user on Linux systems.
|
100
100
|
@param ensureRootUser If True the current user must be root user (Linux systems).
|
101
|
-
@param
|
102
|
-
|
101
|
+
@param serviceName The name of the service. If not set then the name of the initially executed
|
102
|
+
python file is used.
|
103
103
|
@param restartSeconds The number of seconds to sleep before restarting a service that has stopped (default=1)."""
|
104
104
|
self._uio = uio
|
105
105
|
self._allowRootUser=allowRootUser
|
106
106
|
self._osName = platform.system()
|
107
107
|
self._platformBootManager = None
|
108
108
|
if self._osName == BootManager.LINUX_OS_NAME:
|
109
|
-
self._platformBootManager = LinuxBootManager(uio, self._allowRootUser, ensureRootUser,
|
109
|
+
self._platformBootManager = LinuxBootManager(uio, self._allowRootUser, ensureRootUser, serviceName, restartSeconds)
|
110
110
|
else:
|
111
111
|
raise Exception("{} is an unsupported OS.".format(self._osName) )
|
112
112
|
|
@@ -174,13 +174,13 @@ class LinuxBootManager(object):
|
|
174
174
|
raise Exception(f"{serviceFolder} folder not found.")
|
175
175
|
return serviceFolder
|
176
176
|
|
177
|
-
def __init__(self, uio, allowRootUser, ensureRootUser,
|
177
|
+
def __init__(self, uio, allowRootUser, ensureRootUser, serviceName, restartSeconds):
|
178
178
|
"""@brief Constructor
|
179
179
|
@param uio A UIO instance to display user output. If unset then no output is displayed to user.
|
180
180
|
@param allowRootUser If True then allow root user to to auto start programs.
|
181
181
|
@param ensureRootUser If True the current user must be root user.
|
182
|
-
@param
|
183
|
-
|
182
|
+
@param serviceName The name of the service. If not set then the name of the initially executed
|
183
|
+
python file is used.
|
184
184
|
@param restartSeconds The number of seconds to sleep before restarting a service that has stopped."""
|
185
185
|
self._uio = uio
|
186
186
|
self._logFile = None
|
@@ -202,7 +202,7 @@ class LinuxBootManager(object):
|
|
202
202
|
self._cmdLinePrefix = self._systemCtlBin
|
203
203
|
self._username = getpass.getuser()
|
204
204
|
self._serviceFolder = LinuxBootManager.GetServiceFolder(self._rootMode)
|
205
|
-
self.
|
205
|
+
self._serviceName = serviceName
|
206
206
|
self._restartSeconds = restartSeconds
|
207
207
|
|
208
208
|
def _getInstallledStartupScript(self):
|
@@ -275,34 +275,38 @@ class LinuxBootManager(object):
|
|
275
275
|
if not os.path.isdir(exePath):
|
276
276
|
self._fatalError("{} path not found".format(exePath))
|
277
277
|
|
278
|
-
|
279
|
-
if
|
280
|
-
|
278
|
+
appName = os.path.basename(exeFile)
|
279
|
+
if len(appName) == 0:
|
280
|
+
self._fatalError("No app found to execute.")
|
281
281
|
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
appName = os.path.basename(exeFile)
|
286
|
-
if len(appName) == 0:
|
287
|
-
self._fatalError("No app found to execute.")
|
282
|
+
absApp = os.path.join(exePath, appName)
|
283
|
+
if not os.path.isfile( absApp ):
|
284
|
+
self._fatalError("{} file not found.".format(absApp) )
|
288
285
|
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
appName = appName.replace(".py", "")
|
294
|
-
if self._rootMode:
|
295
|
-
# We can only save to /var/log/ is we are root user.
|
296
|
-
self._logFile = os.path.join(LinuxBootManager.LOG_PATH, appName)
|
286
|
+
appName = appName.replace(".py", "")
|
287
|
+
if self._rootMode:
|
288
|
+
# We can only save to /var/log/ is we are root user.
|
289
|
+
self._logFile = os.path.join(LinuxBootManager.LOG_PATH, appName)
|
297
290
|
|
298
291
|
return (appName, absApp)
|
299
292
|
|
293
|
+
def _getServiceName(self):
|
294
|
+
"""@brief Get the name of the service.
|
295
|
+
@return The name of the service."""
|
296
|
+
if self._serviceName:
|
297
|
+
serviceName = self._serviceName
|
298
|
+
else:
|
299
|
+
appName, _ = self._getApp()
|
300
|
+
serviceName = appName
|
301
|
+
return "{}.service".format(serviceName)
|
302
|
+
|
300
303
|
def _getServiceFile(self, appName):
|
301
304
|
"""@brief Get the name of the service file.
|
302
305
|
@param appName The name of the app to execute.
|
303
306
|
@return The absolute path to the service file """
|
304
|
-
serviceName =
|
307
|
+
serviceName = self._getServiceName()
|
305
308
|
serviceFile = os.path.join(self._serviceFolder, serviceName)
|
309
|
+
self._uio.info(f"SERVICE FILE: {serviceFile}")
|
306
310
|
return serviceFile
|
307
311
|
|
308
312
|
def add(self, user, argString=None, enableSyslog=False):
|
@@ -321,8 +325,9 @@ class LinuxBootManager(object):
|
|
321
325
|
user = self._username
|
322
326
|
|
323
327
|
appName, absApp = self._getApp()
|
328
|
+
serviceName = self._getServiceName()
|
324
329
|
|
325
|
-
serviceFile = self._getServiceFile(
|
330
|
+
serviceFile = self._getServiceFile(serviceName)
|
326
331
|
|
327
332
|
lines = []
|
328
333
|
lines.append("[Unit]")
|
@@ -372,12 +377,12 @@ class LinuxBootManager(object):
|
|
372
377
|
|
373
378
|
cmd = "{} daemon-reload".format(self._cmdLinePrefix)
|
374
379
|
self._runLocalCmd(cmd)
|
375
|
-
cmd = "{} enable {}".format(self._cmdLinePrefix,
|
376
|
-
self._info("Enabled {} on restart".format(
|
380
|
+
cmd = "{} enable {}".format(self._cmdLinePrefix, serviceName)
|
381
|
+
self._info("Enabled {} on restart".format(serviceName))
|
377
382
|
self._runLocalCmd(cmd)
|
378
|
-
cmd = "{} start {}".format(self._cmdLinePrefix,
|
383
|
+
cmd = "{} start {}".format(self._cmdLinePrefix, serviceName)
|
379
384
|
self._runLocalCmd(cmd)
|
380
|
-
self._info("Started {}".format(
|
385
|
+
self._info("Started {}".format(serviceName))
|
381
386
|
|
382
387
|
def remove(self):
|
383
388
|
"""@brief Remove the executable file to the processes started at boot time.
|
@@ -385,29 +390,30 @@ class LinuxBootManager(object):
|
|
385
390
|
named the same as the python file executed without the .py suffix."""
|
386
391
|
appName, _ = self._getApp()
|
387
392
|
|
393
|
+
serviceName = self._getServiceName()
|
388
394
|
serviceFile = self._getServiceFile(appName)
|
389
395
|
if os.path.isfile(serviceFile):
|
390
|
-
cmd = "{} disable {}".format(self._cmdLinePrefix,
|
396
|
+
cmd = "{} disable {}".format(self._cmdLinePrefix, serviceName)
|
391
397
|
self._runLocalCmd(cmd)
|
392
|
-
self._info("Disabled {} on restart".format(
|
398
|
+
self._info("Disabled {} on restart".format(serviceName))
|
393
399
|
|
394
|
-
cmd = "{} stop {}".format(self._cmdLinePrefix,
|
400
|
+
cmd = "{} stop {}".format(self._cmdLinePrefix, serviceName)
|
395
401
|
self._runLocalCmd(cmd)
|
396
|
-
self._info("Stopped {}".format(
|
402
|
+
self._info("Stopped {}".format(serviceName))
|
397
403
|
|
398
404
|
os.remove(serviceFile)
|
399
405
|
self._log("Removed {}".format(serviceFile))
|
400
406
|
else:
|
401
|
-
self._info("{} service not found".format(
|
407
|
+
self._info("{} service not found".format(serviceName))
|
402
408
|
|
403
409
|
def getStatusLines(self):
|
404
410
|
"""@brief Get a status report.
|
405
411
|
@return Lines of text indicating the status of a previously started process."""
|
406
|
-
|
412
|
+
serviceName = self._getServiceName()
|
407
413
|
if self._rootMode:
|
408
|
-
p = Popen([self._systemCtlBin, 'status',
|
414
|
+
p = Popen([self._systemCtlBin, 'status', serviceName], stdin=PIPE, stdout=PIPE, stderr=PIPE)
|
409
415
|
else:
|
410
|
-
p = Popen([self._systemCtlBin, '--user', 'status',
|
416
|
+
p = Popen([self._systemCtlBin, '--user', 'status', serviceName], stdin=PIPE, stdout=PIPE, stderr=PIPE)
|
411
417
|
output, err = p.communicate(b"input data that is passed to subprocess' stdin")
|
412
418
|
response = output.decode() + "\n" + err.decode()
|
413
419
|
lines = response.split("\n")
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: p3lib
|
3
|
-
Version: 1.1.
|
3
|
+
Version: 1.1.98
|
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
|
@@ -2,7 +2,7 @@ p3lib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
2
|
p3lib/ate.py,sha256=_BiqMUYNAlp4O8MkP_PAUe62Bzd8dzV4Ipv62OFS6Ok,4759
|
3
3
|
p3lib/bokeh_auth.py,sha256=zi_Hty2WkCJVNQ4sINNRo5FBXujuJky9phyoF6M55ms,15180
|
4
4
|
p3lib/bokeh_gui.py,sha256=55sajP_x9O1lE0uP3w3-T5f2oMzk7jSolLqxlEdLeLg,40245
|
5
|
-
p3lib/boot_manager.py,sha256=
|
5
|
+
p3lib/boot_manager.py,sha256=l7WlaoIRt4cu2jAdCs3FnDeNO2v2jzqideNZ3qg2r_4,19652
|
6
6
|
p3lib/conduit.py,sha256=jPkjdtyCx2I6SFqcEo8y2g7rgnZ-jNY7oCuYIETzT5Q,6046
|
7
7
|
p3lib/database_if.py,sha256=XKu1w3zftGbj4Rh54wrWJnoCtqHkhCzJUPN2S70XIKg,11915
|
8
8
|
p3lib/helper.py,sha256=xTKPgpziwr4zyaoc0sjZRFr0M91fo7Tok_nSAvtiTZE,12020
|
@@ -15,8 +15,8 @@ p3lib/pconfig.py,sha256=82rX7zvJVbSFtYYHvhj9I6GTdpjf9v73fNs9WQE-5ik,35388
|
|
15
15
|
p3lib/ssh.py,sha256=OyoAQ_h1L2RfkjTAChDrvLFfl4Fe_gBNdX5rvK-wKiw,42125
|
16
16
|
p3lib/table_plot.py,sha256=RPncwVlGUkkx5Fw0dHQedXo0TSPlTi__VrJBDzaMsuI,32116
|
17
17
|
p3lib/uio.py,sha256=Aaxc99XiE3d2f9vLjaN-bZsckoNxay5t0ujdK6PXGrw,23265
|
18
|
-
p3lib-1.1.
|
19
|
-
p3lib-1.1.
|
20
|
-
p3lib-1.1.
|
21
|
-
p3lib-1.1.
|
22
|
-
p3lib-1.1.
|
18
|
+
p3lib-1.1.98.dist-info/LICENSE,sha256=igqTy5u0kVWM1n-NUZMvAlinY6lVjAXKoag0okkS8V8,1067
|
19
|
+
p3lib-1.1.98.dist-info/METADATA,sha256=WFRcH8Vj2UU7yFKB7WSeK36IU2lnGh-t9oo6RxSLGmk,918
|
20
|
+
p3lib-1.1.98.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
|
21
|
+
p3lib-1.1.98.dist-info/top_level.txt,sha256=SDCpXYh-19yCFp4Z8ZK4B-3J4NvTCJElZ42NPgcR6-U,6
|
22
|
+
p3lib-1.1.98.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|