p3lib 1.1.97__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 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, appName=None, restartSeconds=1):
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 appName The name of the app. This is used as the service name. If not set then
38
- the name of the initially executed python file is used.
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, appName)
43
+ BootManager.CheckAutoStartStatus(uio, serviceName)
44
44
  handled = True
45
45
 
46
46
  elif options.enable_auto_start:
47
- BootManager.EnableAutoStart(uio, enable_syslog, appName, restartSeconds)
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, appName)
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, appName, restartSeconds):
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 appName The name of the app. This is used as the service name. If not set then
64
- the name of the initially executed python file is used.
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, appName=appName, restartSeconds=restartSeconds)
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, appName):
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 appName The name of the app. This is used as the service name. If not set then
75
- the name of the initially executed python file is used."""
76
- bootManager = BootManager(uio=uio, ensureRootUser=True, appName=appName)
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, appName):
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 appName The name of the app. This is used as the service name. If not set then
84
- the name of the initially executed python file is used."""
85
- bootManager = BootManager(uio=uio, appName=appName)
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, appName=None, restartSeconds=1):
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 appName The name of the app. This is used as the service name. If not set then
102
- the name of the initially executed python file is used.
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, appName, restartSeconds)
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, appName, restartSeconds):
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 appName The name of the app. This is used as the systemd service name. If not set then
183
- the name of the initially executed python file is used.
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._appName = appName
205
+ self._serviceName = serviceName
206
206
  self._restartSeconds = restartSeconds
207
207
 
208
208
  def _getInstallledStartupScript(self):
@@ -290,12 +290,23 @@ class LinuxBootManager(object):
290
290
 
291
291
  return (appName, absApp)
292
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
+
293
303
  def _getServiceFile(self, appName):
294
304
  """@brief Get the name of the service file.
295
305
  @param appName The name of the app to execute.
296
306
  @return The absolute path to the service file """
297
- serviceName = "{}.service".format(appName)
307
+ serviceName = self._getServiceName()
298
308
  serviceFile = os.path.join(self._serviceFolder, serviceName)
309
+ self._uio.info(f"SERVICE FILE: {serviceFile}")
299
310
  return serviceFile
300
311
 
301
312
  def add(self, user, argString=None, enableSyslog=False):
@@ -314,11 +325,7 @@ class LinuxBootManager(object):
314
325
  user = self._username
315
326
 
316
327
  appName, absApp = self._getApp()
317
-
318
- if self._appName:
319
- serviceName = self._appName
320
- else:
321
- serviceName = appName
328
+ serviceName = self._getServiceName()
322
329
 
323
330
  serviceFile = self._getServiceFile(serviceName)
324
331
 
@@ -370,12 +377,12 @@ class LinuxBootManager(object):
370
377
 
371
378
  cmd = "{} daemon-reload".format(self._cmdLinePrefix)
372
379
  self._runLocalCmd(cmd)
373
- cmd = "{} enable {}".format(self._cmdLinePrefix, appName)
374
- self._info("Enabled {} on restart".format(appName))
380
+ cmd = "{} enable {}".format(self._cmdLinePrefix, serviceName)
381
+ self._info("Enabled {} on restart".format(serviceName))
375
382
  self._runLocalCmd(cmd)
376
- cmd = "{} start {}".format(self._cmdLinePrefix, appName)
383
+ cmd = "{} start {}".format(self._cmdLinePrefix, serviceName)
377
384
  self._runLocalCmd(cmd)
378
- self._info("Started {}".format(appName))
385
+ self._info("Started {}".format(serviceName))
379
386
 
380
387
  def remove(self):
381
388
  """@brief Remove the executable file to the processes started at boot time.
@@ -383,29 +390,30 @@ class LinuxBootManager(object):
383
390
  named the same as the python file executed without the .py suffix."""
384
391
  appName, _ = self._getApp()
385
392
 
393
+ serviceName = self._getServiceName()
386
394
  serviceFile = self._getServiceFile(appName)
387
395
  if os.path.isfile(serviceFile):
388
- cmd = "{} disable {}".format(self._cmdLinePrefix, appName)
396
+ cmd = "{} disable {}".format(self._cmdLinePrefix, serviceName)
389
397
  self._runLocalCmd(cmd)
390
- self._info("Disabled {} on restart".format(appName))
398
+ self._info("Disabled {} on restart".format(serviceName))
391
399
 
392
- cmd = "{} stop {}".format(self._cmdLinePrefix, appName)
400
+ cmd = "{} stop {}".format(self._cmdLinePrefix, serviceName)
393
401
  self._runLocalCmd(cmd)
394
- self._info("Stopped {}".format(appName))
402
+ self._info("Stopped {}".format(serviceName))
395
403
 
396
404
  os.remove(serviceFile)
397
405
  self._log("Removed {}".format(serviceFile))
398
406
  else:
399
- self._info("{} service not found".format(appName))
407
+ self._info("{} service not found".format(serviceName))
400
408
 
401
409
  def getStatusLines(self):
402
410
  """@brief Get a status report.
403
411
  @return Lines of text indicating the status of a previously started process."""
404
- appName, _ = self._getApp()
412
+ serviceName = self._getServiceName()
405
413
  if self._rootMode:
406
- p = Popen([self._systemCtlBin, 'status', appName], stdin=PIPE, stdout=PIPE, stderr=PIPE)
414
+ p = Popen([self._systemCtlBin, 'status', serviceName], stdin=PIPE, stdout=PIPE, stderr=PIPE)
407
415
  else:
408
- p = Popen([self._systemCtlBin, '--user', 'status', appName], stdin=PIPE, stdout=PIPE, stderr=PIPE)
416
+ p = Popen([self._systemCtlBin, '--user', 'status', serviceName], stdin=PIPE, stdout=PIPE, stderr=PIPE)
409
417
  output, err = p.communicate(b"input data that is passed to subprocess' stdin")
410
418
  response = output.decode() + "\n" + err.decode()
411
419
  lines = response.split("\n")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: p3lib
3
- Version: 1.1.97
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=yJHpAUq0u-G2GPjwbKqqUv8yAnx5DrL4SZoAGpXYCRI,19301
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.97.dist-info/LICENSE,sha256=igqTy5u0kVWM1n-NUZMvAlinY6lVjAXKoag0okkS8V8,1067
19
- p3lib-1.1.97.dist-info/METADATA,sha256=TRvpOb05BcL3pggGRcj9vay_s-ST0sDkzXEtef9XH5A,918
20
- p3lib-1.1.97.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
21
- p3lib-1.1.97.dist-info/top_level.txt,sha256=SDCpXYh-19yCFp4Z8ZK4B-3J4NvTCJElZ42NPgcR6-U,6
22
- p3lib-1.1.97.dist-info/RECORD,,
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