p3lib 1.1.81__tar.gz → 1.1.83__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.
Files changed (31) hide show
  1. {p3lib-1.1.81 → p3lib-1.1.83}/PKG-INFO +1 -1
  2. {p3lib-1.1.81 → p3lib-1.1.83}/setup.cfg +1 -1
  3. {p3lib-1.1.81 → p3lib-1.1.83}/src/p3lib/bokeh_auth.py +7 -1
  4. {p3lib-1.1.81 → p3lib-1.1.83}/src/p3lib/boot_manager.py +74 -36
  5. {p3lib-1.1.81 → p3lib-1.1.83}/src/p3lib/pconfig.py +49 -2
  6. {p3lib-1.1.81 → p3lib-1.1.83}/src/p3lib.egg-info/PKG-INFO +1 -1
  7. {p3lib-1.1.81 → p3lib-1.1.83}/LICENSE +0 -0
  8. {p3lib-1.1.81 → p3lib-1.1.83}/README.md +0 -0
  9. {p3lib-1.1.81 → p3lib-1.1.83}/pyproject.toml +0 -0
  10. {p3lib-1.1.81 → p3lib-1.1.83}/src/p3lib/__init__.py +0 -0
  11. {p3lib-1.1.81 → p3lib-1.1.83}/src/p3lib/ate.py +0 -0
  12. {p3lib-1.1.81 → p3lib-1.1.83}/src/p3lib/bokeh_gui.py +0 -0
  13. {p3lib-1.1.81 → p3lib-1.1.83}/src/p3lib/conduit.py +0 -0
  14. {p3lib-1.1.81 → p3lib-1.1.83}/src/p3lib/database_if.py +0 -0
  15. {p3lib-1.1.81 → p3lib-1.1.83}/src/p3lib/helper.py +0 -0
  16. {p3lib-1.1.81 → p3lib-1.1.83}/src/p3lib/json_networking.py +0 -0
  17. {p3lib-1.1.81 → p3lib-1.1.83}/src/p3lib/mqtt_rpc.py +0 -0
  18. {p3lib-1.1.81 → p3lib-1.1.83}/src/p3lib/netif.py +0 -0
  19. {p3lib-1.1.81 → p3lib-1.1.83}/src/p3lib/netplotly.py +0 -0
  20. {p3lib-1.1.81 → p3lib-1.1.83}/src/p3lib/ngt.py +0 -0
  21. {p3lib-1.1.81 → p3lib-1.1.83}/src/p3lib/ssh.py +0 -0
  22. {p3lib-1.1.81 → p3lib-1.1.83}/src/p3lib/table_plot.py +0 -0
  23. {p3lib-1.1.81 → p3lib-1.1.83}/src/p3lib/uio.py +0 -0
  24. {p3lib-1.1.81 → p3lib-1.1.83}/src/p3lib.egg-info/SOURCES.txt +0 -0
  25. {p3lib-1.1.81 → p3lib-1.1.83}/src/p3lib.egg-info/dependency_links.txt +0 -0
  26. {p3lib-1.1.81 → p3lib-1.1.83}/src/p3lib.egg-info/requires.txt +0 -0
  27. {p3lib-1.1.81 → p3lib-1.1.83}/src/p3lib.egg-info/top_level.txt +0 -0
  28. {p3lib-1.1.81 → p3lib-1.1.83}/tests/test_conduit.py +0 -0
  29. {p3lib-1.1.81 → p3lib-1.1.83}/tests/test_json_networking.py +0 -0
  30. {p3lib-1.1.81 → p3lib-1.1.83}/tests/test_netif.py +0 -0
  31. {p3lib-1.1.81 → p3lib-1.1.83}/tests/test_ssh.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: p3lib
3
- Version: 1.1.81
3
+ Version: 1.1.83
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.81
3
+ version = 1.1.83
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.
@@ -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):
@@ -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
 
@@ -339,11 +339,54 @@ class ConfigManager(object):
339
339
 
340
340
  return join( configPath, cfgFilename )
341
341
 
342
+ @staticmethod
343
+ def GetDefaultConfigFilename():
344
+ """@brief Get the default name of the config file for this app. This will be the program name
345
+ (file that started up initially) without the .py extension. On Linux systems this
346
+ will reside in the ~/.config folder. If the ~/.config does not exist an attempt to
347
+ create it is made. If the ~/.config folder cannot be created then the config file
348
+ will be as detailed above but will be prefixed by a . character and will reside
349
+ in the users home folder."""
350
+ progName = sys.argv[0]
351
+ if progName.endswith('.py'):
352
+ progName = progName[0:-3]
353
+
354
+ folder = '.config'
355
+ homePath = os.path.expanduser("~")
356
+ configFolder = os.path.join(homePath, folder)
357
+
358
+ if not os.path.isdir(homePath):
359
+ raise Exception(f"{homePath} HOME path does not exist.")
360
+
361
+ # Create the ~/.config folder if it does not exist
362
+ if not os.path.isdir(configFolder):
363
+ # Create the ~/.config folder
364
+ os.makedir(configFolder)
365
+
366
+ # Note that we assume that addDotToFilename in the ConfigManager constructor is set True
367
+ # as this will prefix the filename with the . character.
368
+ if os.path.isdir(configFolder):
369
+ extraFolders = os.path.dirname(progName)
370
+ configFolder = os.path.join(configFolder, extraFolders)
371
+ if not os.path.isdir(configFolder):
372
+ os.makedirs(configFolder)
373
+ if not os.path.isdir(configFolder):
374
+ raise Exception(f"Failed to create the {configFolder} folder.")
375
+
376
+ configFolder = "config"
377
+ configFolder = os.path.join(configFolder, extraFolders)
378
+ configFilename = os.path.join(configFolder, os.path.basename(progName) + '.cfg')
379
+
380
+ else:
381
+ configFilename = progName
382
+
383
+ return configFilename
384
+
342
385
  def __init__(self, uio, cfgFilename, defaultConfig, addDotToFilename=True, encrypt=False, cfgPath=None):
343
386
  """@brief Constructor
344
387
  @param uio A UIO (User Input Output) instance. May be set to None if no user messages are required.
345
- @param cfgFilename The name of the config file.
346
- @param defaultConfig A default config instance containg all the default key-value pairs.
388
+ @param cfgFilename The name of the config file. If this is None then the default config filename is used.
389
+ @param defaultConfig A default config instance containing all the default key-value pairs.
347
390
  @param addDotToFilename If True (default) then a . is added to the start of the filename. This hides the file in normal cases.
348
391
  @param encrypt If True then data will be encrypted in the saved files.
349
392
  The encryption uses part of the the local SSH RSA private key.
@@ -360,6 +403,10 @@ class ConfigManager(object):
360
403
  self._cfgPath = cfgPath
361
404
  self._configDict = {}
362
405
 
406
+ # If the user passed None in as the cfg filename then generate the default config file.
407
+ if self._cfgFilename is None:
408
+ self._cfgFilename = ConfigManager.GetDefaultConfigFilename()
409
+
363
410
  self._cfgFile = self._getConfigFile()
364
411
  self._modifiedTime = self._getModifiedTime()
365
412
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: p3lib
3
- Version: 1.1.81
3
+ Version: 1.1.83
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