p3lib 1.1.80__py3-none-any.whl → 1.1.82__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/bokeh_auth.py CHANGED
@@ -149,10 +149,16 @@ class LoginHandler(RequestHandler):
149
149
  self._recordLoginAttempt(username, password)
150
150
  valid = False
151
151
  credentialsJsonFile = GetCredentialsFile()
152
+ LoginHandler.SaveInfoAccessLogMessage(f"credentialsJsonFile = {credentialsJsonFile}")
153
+ fileExists = os.path.isfile(credentialsJsonFile)
154
+ LoginHandler.SaveInfoAccessLogMessage(f"fileExists = {fileExists}")
152
155
  ch = CredentialsHasher(credentialsJsonFile)
153
- if ch.verify(username, password):
156
+ verified = ch.verify(username, password)
157
+ LoginHandler.SaveInfoAccessLogMessage(f"verified = {verified}")
158
+ if verified:
154
159
  valid = True
155
160
  self._recordLoginSuccess(username, password)
161
+ LoginHandler.SaveInfoAccessLogMessage(f"check_permission(): valid = {valid}")
156
162
  return valid
157
163
 
158
164
  def post(self):
p3lib/boot_manager.py CHANGED
@@ -13,8 +13,65 @@ class BootManager(object):
13
13
  Currently supports the following platforms
14
14
  Linux"""
15
15
 
16
- LINUX_OS_NAME = "Linux"
16
+ LINUX_OS_NAME = "Linux"
17
+ ENABLE_CMD_OPT = "--enable_auto_start"
18
+ DISABLE_CMD_OPT = "--disable_auto_start"
19
+ CHECK_CMD_OPT = "--check_auto_start"
17
20
 
21
+ @staticmethod
22
+ def AddCmdArgs(parser):
23
+ """@brief Add cmd line arguments to enable, disable and show the systemd boot state.
24
+ @param parser An instance of argparse.ArgumentParser."""
25
+ parser.add_argument(BootManager.ENABLE_CMD_OPT, help="Auto start when this computer starts.", action="store_true", default=False)
26
+ parser.add_argument(BootManager.DISABLE_CMD_OPT, help="Disable auto starting when this computer starts.", action="store_true", default=False)
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
+
29
+ @staticmethod
30
+ def HandleOptions(uio, options, enable_syslog):
31
+ """@brief Handle one of the bot manager command line options if the
32
+ user passed it on the cmd line.
33
+ @param uio A UIO instance.
34
+ @param options As returned from parser.parse_args() where parser
35
+ is an instance of argparse.ArgumentParser.
36
+ @param enable_syslog True to enable systemd syslog output.
37
+ @return True if handled , False if not."""
38
+ handled = False
39
+ if options.check_auto_start:
40
+ BootManager.CheckAutoStartStatus(uio)
41
+ handled = True
42
+
43
+ elif options.enable_auto_start:
44
+ BootManager.EnableAutoStart(uio, enable_syslog)
45
+ handled = True
46
+
47
+ elif options.disable_auto_start:
48
+ BootManager.DisableAutoStart(uio)
49
+ handled = True
50
+
51
+ return handled
52
+
53
+ @staticmethod
54
+ def EnableAutoStart(uio, enable_syslog):
55
+ """@brief Enable this program to auto start when the computer on which it is installed starts."""
56
+ bootManager = BootManager(uio=uio, ensureRootUser=True)
57
+ arsString = " ".join(sys.argv)
58
+ bootManager.add(argString=arsString, enableSyslog=enable_syslog)
59
+
60
+ @staticmethod
61
+ def DisableAutoStart(uio):
62
+ """@brief Enable this program to auto start when the computer on which it is installed starts."""
63
+ bootManager = BootManager(uio=uio, ensureRootUser=True)
64
+ bootManager.remove()
65
+
66
+ @staticmethod
67
+ def CheckAutoStartStatus(uio):
68
+ """@brief Check the status of a process previously set to auto start."""
69
+ bootManager = BootManager(uio=uio)
70
+ lines = bootManager.getStatus()
71
+ if lines and len(lines) > 0:
72
+ for line in lines:
73
+ uio.info(line)
74
+
18
75
  def __init__(self, uio=None, allowRootUser=True, ensureRootUser=False):
19
76
  """@brief Constructor
20
77
  @param uio A UIO instance to display user output. If unset then no output
@@ -130,41 +187,14 @@ class LinuxBootManager(object):
130
187
  named the same as the python file executed without the .py suffix.
131
188
  @return The startup script file (absolute path)."""""
132
189
  startupScript=None
133
- pythonFile = sys.argv[0] # The python file executed at program startup
134
- if pythonFile.startswith("./"):
135
- pythonFile=pythonFile[2:]
136
-
137
- envPaths = self._getPaths()
138
-
139
- # Search first for a file that does not have the .py suffix as
140
- # this may be installed via a deb/rpm installation.
141
- exeFile=os.path.basename( pythonFile.replace(".py", "") )
142
- if envPaths and len(envPaths) > 0:
143
- for envPath in envPaths:
144
- _exeStartupScript = os.path.join(envPath, exeFile)
145
- if os.path.isfile(_exeStartupScript):
146
- startupScript=_exeStartupScript
147
- break
148
-
149
- # If the script file has not been found then search for a file with
150
- # the .py suffix.
151
- if not startupScript:
152
- if envPaths and len(envPaths) > 0:
153
- for envPath in envPaths:
154
- _startupScript = os.path.join(envPath, pythonFile)
155
- if os.path.isfile(_startupScript):
156
- startupScript=_startupScript
157
- break
158
-
159
- if not startupScript:
160
- paths = self._getPaths()
161
- if len(paths):
162
- for _path in paths:
163
- self._info(_path)
164
- self._fatalError("{} startup script not found using the PATH env var".format(pythonFile) )
165
- else:
166
- self._fatalError("No PATH env var found.")
167
-
190
+ argList = sys.argv
191
+ # If the first argument in the arg is a file.
192
+ if len(argList) > 0:
193
+ firstArg = argList[0]
194
+ if os.path.isfile(firstArg) or os.path.islink(firstArg):
195
+ startupScript = firstArg
196
+ if startupScript is None:
197
+ raise Exception("Failed to find the startup script.")
168
198
  return startupScript
169
199
 
170
200
  def _getPaths(self):
@@ -287,6 +317,13 @@ class LinuxBootManager(object):
287
317
  if user and len(user) > 0:
288
318
  lines.append('Environment="HOME=/home/{}"'.format(user))
289
319
  if argString:
320
+ argString = argString.strip()
321
+ if argString.startswith(absApp):
322
+ argString=argString.replace(absApp, "")
323
+ # We don't want the enable cmd opt in the cmd we add to the systemd file.
324
+ if argString.find(BootManager.ENABLE_CMD_OPT):
325
+ argString = argString.replace(BootManager.ENABLE_CMD_OPT, "")
326
+ argString = argString.strip()
290
327
  lines.append("ExecStart={} {}".format(absApp, argString))
291
328
  else:
292
329
  lines.append("ExecStart={}".format(absApp))
@@ -299,6 +336,7 @@ class LinuxBootManager(object):
299
336
  fd = open(serviceFile, 'w')
300
337
  fd.write( "\n".join(lines) )
301
338
  fd.close()
339
+ self._info(f"Created {serviceFile}")
302
340
  except IOError:
303
341
  self._fatalError("Failed to create {}".format(serviceFile) )
304
342
 
p3lib/pconfig.py CHANGED
@@ -1,4 +1,4 @@
1
- #!/bin/sh/env python3d
1
+ #!/bin/sh/env python3
2
2
 
3
3
  import os
4
4
  import base64
@@ -6,6 +6,7 @@ import datetime
6
6
  import sys
7
7
  import json
8
8
  import copy
9
+ import platform
9
10
 
10
11
  from shutil import copyfile
11
12
 
@@ -313,31 +314,28 @@ class ConfigManager(object):
313
314
  if not cfgFilename:
314
315
  raise Exception("No config filename defined.")
315
316
 
316
- cfgFilename = cfgFilename
317
317
  if addDotToFilename:
318
318
  if not cfgFilename.startswith("."):
319
319
 
320
320
  cfgFilename=".%s" % (cfgFilename)
321
321
 
322
- else:
323
-
324
- cfgFilename=cfgFilename
325
-
326
322
  #The the config path has been set then use it
327
323
  if cfgPath:
328
324
  configPath = cfgPath
329
325
 
330
326
  else:
331
- configPath=""
332
- #If an absolute path is set for the config file then don't try to
333
- #put the file in the users home dir
334
- if not cfgFilename.startswith("/"):
335
- configPath = expanduser("~")
336
- configPath = configPath.strip()
337
- #If no user is known then default to root user.
338
- #This occurs on Omega2 startup apps.
339
- if len(configPath) == 0 or configPath == '/' or configPath == '/root':
340
- configPath="/root"
327
+ # If the root user on a Linux system
328
+ if platform.system() == 'Linux' and os.geteuid() == 0:
329
+ # This should be the root users config folder.
330
+ configPath="/root"
331
+
332
+ else:
333
+ configPath=""
334
+ #If an absolute path is set for the config file then don't try to
335
+ #put the file in the users home dir
336
+ if not cfgFilename.startswith("/"):
337
+ configPath = expanduser("~")
338
+ configPath = configPath.strip()
341
339
 
342
340
  return join( configPath, cfgFilename )
343
341
 
p3lib/uio.py CHANGED
@@ -113,7 +113,7 @@ class UIO(object):
113
113
  self._print('{}INFO{}: {}'.format(UIO.GetInfoEscapeSeq(), UIO.DISPLAY_RESET_ESCAPE_SEQ, text))
114
114
  else:
115
115
  self._print('INFO: {}'.format(text))
116
- self._update_syslog(PRIORITY.INFO, text)
116
+ self._update_syslog(PRIORITY.INFO, "INFO: "+text)
117
117
 
118
118
  def debug(self, text):
119
119
  """@brief Present a debug level message to the user if debuging is enabled.
@@ -128,7 +128,7 @@ class UIO(object):
128
128
  self.storeToDebugLog('{}DEBUG{}: {}'.format(UIO.GetDebugEscapeSeq(), UIO.DISPLAY_RESET_ESCAPE_SEQ, text))
129
129
  else:
130
130
  self.storeToDebugLog('DEBUG: {}'.format(text))
131
- self._update_syslog(PRIORITY.DEBUG, text)
131
+ self._update_syslog(PRIORITY.DEBUG, "DEBUG: "+text)
132
132
 
133
133
  def warn(self, text):
134
134
  """@brief Present a warning level message to the user.
@@ -137,7 +137,7 @@ class UIO(object):
137
137
  self._print('{}WARN{}: {}'.format(UIO.GetWarnEscapeSeq(), UIO.DISPLAY_RESET_ESCAPE_SEQ, text))
138
138
  else:
139
139
  self._print('WARN: {}'.format(text))
140
- self._update_syslog(PRIORITY.WARNING, text)
140
+ self._update_syslog(PRIORITY.WARNING, "WARN: "+text)
141
141
 
142
142
  def error(self, text):
143
143
  """@brief Present an error level message to the user.
@@ -146,7 +146,7 @@ class UIO(object):
146
146
  self._print('{}ERROR{}: {}'.format(UIO.GetErrorEscapeSeq(), UIO.DISPLAY_RESET_ESCAPE_SEQ, text))
147
147
  else:
148
148
  self._print('ERROR: {}'.format(text))
149
- self._update_syslog(PRIORITY.ERROR, text)
149
+ self._update_syslog(PRIORITY.ERROR, "ERROR: "+text)
150
150
 
151
151
  def _print(self, text):
152
152
  """@brief Print text to stdout"""
@@ -382,7 +382,10 @@ class UIO(object):
382
382
  @param syslogProgramName The name of the program that is being logged. If defined this appears after the username in the syslog output."""
383
383
  self._sysLogEnabled = enabled
384
384
  self._sysLogHost = host
385
- self._syslogProgramName = programName
385
+ if programName:
386
+ self._syslogProgramName = programName
387
+ else:
388
+ self._syslogProgramName = sys.argv[0]
386
389
 
387
390
  def _update_syslog(self, pri, msg):
388
391
  """Send a message to syslog is syslog is enabled
@@ -398,7 +401,7 @@ class UIO(object):
398
401
  """
399
402
  if self._sysLogEnabled:
400
403
  aMsg=msg
401
- #Ensure we have no zero characters in the message.
404
+ #Ensure we have no 0x00 characters in the message.
402
405
  # syslog will throw an error if it finds any
403
406
  if "\x00" in aMsg:
404
407
  aMsg=aMsg.replace("\x00", "")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: p3lib
3
- Version: 1.1.80
3
+ Version: 1.1.82
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,8 +1,8 @@
1
1
  p3lib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  p3lib/ate.py,sha256=_BiqMUYNAlp4O8MkP_PAUe62Bzd8dzV4Ipv62OFS6Ok,4759
3
- p3lib/bokeh_auth.py,sha256=wQKSiF_gYvCs5aWUptiDkloC2tmEO-5XiAQ0mO8KFYk,14767
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=IrIJg9LOsxWBP1-1wNR_mO_jzR1FAWVOBVtw7mHHLgw,14968
5
+ p3lib/boot_manager.py,sha256=h5In_QoRDH8oHivcu4gyTzGXWg3joKBiVCz2B8Ttn8E,16941
6
6
  p3lib/conduit.py,sha256=jPkjdtyCx2I6SFqcEo8y2g7rgnZ-jNY7oCuYIETzT5Q,6046
7
7
  p3lib/database_if.py,sha256=XKu1w3zftGbj4Rh54wrWJnoCtqHkhCzJUPN2S70XIKg,11915
8
8
  p3lib/helper.py,sha256=-B63_ncfchMwXrvyVcnj9sxwGnMJ3ASmLmpoYa4tBmM,11862
@@ -11,12 +11,12 @@ p3lib/mqtt_rpc.py,sha256=6LmFA1kR4HSJs9eWbOJORRHNY01L_lHWjvtE2fmY8P8,10511
11
11
  p3lib/netif.py,sha256=3QV5OGdHhELIf4MBj6mx5MNCtVeZ7JXoNEkeu4KzCaE,9796
12
12
  p3lib/netplotly.py,sha256=PMDx-w1jtRVW6Od5u_kuKbBxNpTS_Y88mMF60puMxLM,9363
13
13
  p3lib/ngt.py,sha256=rXA-6zQkfeOupZ-3Q-k3-1DvbKYIi2TCtLKgUb0waWY,37726
14
- p3lib/pconfig.py,sha256=_ri9w3aauHXZp8u2YLYHBVroFR_iCqaTCwj_MRa3rHo,30153
14
+ p3lib/pconfig.py,sha256=IWNEE1DKGwLo78CsUoJLtwGNEMuVLfL4zTKPy_SxygY,30089
15
15
  p3lib/ssh.py,sha256=klqQ9YuqU8GwPVPHrAJeEs5PI5hgoYiXflq2kIGG3as,39509
16
16
  p3lib/table_plot.py,sha256=RPncwVlGUkkx5Fw0dHQedXo0TSPlTi__VrJBDzaMsuI,32116
17
- p3lib/uio.py,sha256=hMarPnYXnqVF23HUIeDfzREo7TMdBjrupXMY_ffuCbI,23133
18
- p3lib-1.1.80.dist-info/LICENSE,sha256=igqTy5u0kVWM1n-NUZMvAlinY6lVjAXKoag0okkS8V8,1067
19
- p3lib-1.1.80.dist-info/METADATA,sha256=mWNK7BKcx26J9B9-OGr8zyc3fr0qZ2Pe7TFNyDb7LQw,918
20
- p3lib-1.1.80.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
21
- p3lib-1.1.80.dist-info/top_level.txt,sha256=SDCpXYh-19yCFp4Z8ZK4B-3J4NvTCJElZ42NPgcR6-U,6
22
- p3lib-1.1.80.dist-info/RECORD,,
17
+ p3lib/uio.py,sha256=Aaxc99XiE3d2f9vLjaN-bZsckoNxay5t0ujdK6PXGrw,23265
18
+ p3lib-1.1.82.dist-info/LICENSE,sha256=igqTy5u0kVWM1n-NUZMvAlinY6lVjAXKoag0okkS8V8,1067
19
+ p3lib-1.1.82.dist-info/METADATA,sha256=Ug7Hh8J-1kXHvVGX5zCVGQItaWSbRDz6LsgsJ5XmXtI,918
20
+ p3lib-1.1.82.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
21
+ p3lib-1.1.82.dist-info/top_level.txt,sha256=SDCpXYh-19yCFp4Z8ZK4B-3J4NvTCJElZ42NPgcR6-U,6
22
+ p3lib-1.1.82.dist-info/RECORD,,
File without changes