p3lib 1.1.105__py3-none-any.whl → 1.1.107__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/helper.py +41 -0
- p3lib/pconfig.py +58 -22
- {p3lib-1.1.105.dist-info → p3lib-1.1.107.dist-info}/METADATA +1 -1
- {p3lib-1.1.105.dist-info → p3lib-1.1.107.dist-info}/RECORD +7 -7
- {p3lib-1.1.105.dist-info → p3lib-1.1.107.dist-info}/WHEEL +1 -1
- {p3lib-1.1.105.dist-info → p3lib-1.1.107.dist-info}/LICENSE +0 -0
- {p3lib-1.1.105.dist-info → p3lib-1.1.107.dist-info}/top_level.txt +0 -0
p3lib/helper.py
CHANGED
@@ -377,3 +377,44 @@ def appendCreateFile(uio, aFile, quiet=False):
|
|
377
377
|
fd.close()
|
378
378
|
if not quiet:
|
379
379
|
uio.info("Created {}".format(aFile))
|
380
|
+
|
381
|
+
def getAbsFile(filename):
|
382
|
+
"""@brief Check that the file exists in several places.
|
383
|
+
1 - The startup folder
|
384
|
+
2 - An 'assets' folder in the startup folder
|
385
|
+
3 - An 'assets' folder in the startup parent folder
|
386
|
+
3 - In an 'assets' folder in a python site-packages folder.
|
387
|
+
@param filename The name of the icon file.
|
388
|
+
@return The abs path of the file or None if not found."""
|
389
|
+
file_found = None
|
390
|
+
abs_filename = os.path.abspath(filename)
|
391
|
+
if os.path.isfile(abs_filename):
|
392
|
+
file_found = abs_filename
|
393
|
+
|
394
|
+
else:
|
395
|
+
startup_file = os.path.abspath(sys.argv[0])
|
396
|
+
startup_path = os.path.dirname(startup_file)
|
397
|
+
path1 = os.path.join(startup_path, 'assets')
|
398
|
+
abs_filename = os.path.join(path1, filename)
|
399
|
+
if os.path.isfile(abs_filename):
|
400
|
+
file_found = abs_filename
|
401
|
+
|
402
|
+
else:
|
403
|
+
startup_parent_path = os.path.join(startup_path, '..')
|
404
|
+
path2 = os.path.join(startup_parent_path, 'assets')
|
405
|
+
abs_filename = os.path.join(path2, filename)
|
406
|
+
if os.path.isfile(abs_filename):
|
407
|
+
file_found = abs_filename
|
408
|
+
|
409
|
+
else:
|
410
|
+
# Try all the site packages folders we know about.
|
411
|
+
for path in sys.path:
|
412
|
+
if 'site-packages' in path:
|
413
|
+
site_packages_path = path
|
414
|
+
path3 = os.path.join(site_packages_path, 'assets')
|
415
|
+
abs_filename = os.path.join(path3, filename)
|
416
|
+
if os.path.isfile(abs_filename):
|
417
|
+
file_found = abs_filename
|
418
|
+
break
|
419
|
+
|
420
|
+
return file_found
|
p3lib/pconfig.py
CHANGED
@@ -339,7 +339,15 @@ class ConfigManager(object):
|
|
339
339
|
|
340
340
|
return join( configPath, cfgFilename )
|
341
341
|
|
342
|
-
def __init__(self,
|
342
|
+
def __init__(self,
|
343
|
+
uio,
|
344
|
+
cfgFilename,
|
345
|
+
defaultConfig,
|
346
|
+
addDotToFilename=True,
|
347
|
+
encrypt=False,
|
348
|
+
cfgPath=None,
|
349
|
+
stripUnknownKeys=True,
|
350
|
+
addNewKeys=True):
|
343
351
|
"""@brief Constructor
|
344
352
|
@param uio A UIO (User Input Output) instance. May be set to None if no user messages are required.
|
345
353
|
@param cfgFilename The name of the config file. If this is None then the default config filename is used.
|
@@ -351,13 +359,17 @@ class ConfigManager(object):
|
|
351
359
|
probably the best we can do. Therefore if encrypt is set True then the
|
352
360
|
an ssh key must be present in the ~/.ssh folder named id_rsa.
|
353
361
|
@param cfgPath The config path when the config file will be stored. By default this is unset and the
|
354
|
-
current users home folder is the location of the config file.
|
362
|
+
current users home folder is the location of the config file.
|
363
|
+
@param stripUnknownKeys If True then keys in the dict but not in the default config dict are stripped from the config.
|
364
|
+
@param addNewKeys If keys are found in the default config that are not in the config dict, add them."""
|
355
365
|
self._uio = uio
|
356
366
|
self._cfgFilename = cfgFilename
|
357
367
|
self._defaultConfig = defaultConfig
|
358
368
|
self._addDotToFilename = addDotToFilename
|
359
369
|
self._encrypt = encrypt
|
360
370
|
self._cfgPath = cfgPath
|
371
|
+
self._stripUnknownKeys = stripUnknownKeys
|
372
|
+
self._addNewKeys = addNewKeys
|
361
373
|
self._configDict = {}
|
362
374
|
|
363
375
|
# If the user passed None in as the cfg filename then generate the default config file.
|
@@ -463,7 +475,8 @@ class ConfigManager(object):
|
|
463
475
|
return dictLoaded
|
464
476
|
|
465
477
|
def load(self, showLoadedMsg=True):
|
466
|
-
"""@brief Load the config.
|
478
|
+
"""@brief Load the config.
|
479
|
+
@param showLoadedMsg If True load messages are displayed."""
|
467
480
|
|
468
481
|
if not isfile(self._cfgFile):
|
469
482
|
|
@@ -483,17 +496,19 @@ class ConfigManager(object):
|
|
483
496
|
# Config parameters may be added or dropped over time. We use the default config to
|
484
497
|
# check for parameters that should be added/removed.
|
485
498
|
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
499
|
+
if self._addNewKeys:
|
500
|
+
# Add any missing keys to the loaded config from the default config.
|
501
|
+
for defaultKey in defaultConfigKeys:
|
502
|
+
if defaultKey not in loadedConfigKeys:
|
503
|
+
loadedConfig[defaultKey] = self._defaultConfig[defaultKey]
|
504
|
+
self._debug("----------> DEFAULT VALUE ADDED: {} = {}".format(defaultKey, loadedConfig[defaultKey]))
|
491
505
|
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
506
|
+
if self._stripUnknownKeys:
|
507
|
+
# If some keys have been dropped from the config, remove them.
|
508
|
+
for loadedConfigKey in loadedConfigKeys:
|
509
|
+
if loadedConfigKey not in defaultConfigKeys:
|
510
|
+
self._debug("----------> DROPPED FROM CONFIG: {} = {}".format(loadedConfigKey, loadedConfig[loadedConfigKey]))
|
511
|
+
loadedConfig.pop(loadedConfigKey, None)
|
497
512
|
|
498
513
|
self._configDict = loadedConfig
|
499
514
|
self._info("Loaded config from %s" % (self._cfgFile) )
|
@@ -760,10 +775,12 @@ class DotConfigManager(ConfigManager):
|
|
760
775
|
KEY_EDIT_ORDER_LIST = None
|
761
776
|
|
762
777
|
@staticmethod
|
763
|
-
def GetDefaultConfigFilename():
|
778
|
+
def GetDefaultConfigFilename(filenameOverride=None):
|
764
779
|
"""@brief Get the default name of the config file for this app. This will be the program name
|
765
780
|
(file that started up initially) without the .py extension. A .cfg extension is added
|
766
|
-
and it will be found in the ~/.config folder.
|
781
|
+
and it will be found in the ~/.config folder.
|
782
|
+
@param filenameOverride The name for the config file in the .config folder. If left as None then the program name ise used
|
783
|
+
as the config filename."""
|
767
784
|
dotConfigFolder = '.config'
|
768
785
|
if platform.system() == 'Linux' and os.geteuid() == 0:
|
769
786
|
homePath = "/root"
|
@@ -779,10 +796,13 @@ class DotConfigManager(ConfigManager):
|
|
779
796
|
# Create the ~/.config folder
|
780
797
|
os.makedirs(configFolder)
|
781
798
|
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
799
|
+
if filenameOverride:
|
800
|
+
progName = filenameOverride
|
801
|
+
else:
|
802
|
+
progName = sys.argv[0]
|
803
|
+
if progName.endswith('.py'):
|
804
|
+
progName = progName[0:-3]
|
805
|
+
progName = os.path.basename(progName).strip()
|
786
806
|
|
787
807
|
# Note that we assume that addDotToFilename in the ConfigManager constructor is set True
|
788
808
|
# as this will prefix the filename with the . character.
|
@@ -794,7 +814,14 @@ class DotConfigManager(ConfigManager):
|
|
794
814
|
|
795
815
|
return configFilename
|
796
816
|
|
797
|
-
def __init__(self,
|
817
|
+
def __init__(self,
|
818
|
+
defaultConfig,
|
819
|
+
keyEditOrderList=None,
|
820
|
+
uio=None,
|
821
|
+
encrypt=False,
|
822
|
+
stripUnknownKeys=True,
|
823
|
+
addNewKeys=True,
|
824
|
+
filenameOverride=None):
|
798
825
|
"""@brief Constructor
|
799
826
|
@param defaultConfig A default config instance containing all the default key-value pairs.
|
800
827
|
@param keyEditOrderList A list of all the dict keys in the order that the caller wishes them to be displayed top the user.
|
@@ -804,8 +831,17 @@ class DotConfigManager(ConfigManager):
|
|
804
831
|
This is not secure but assuming the private key has not been compromised it's
|
805
832
|
probably the best we can do.
|
806
833
|
!!! Therefore if encrypt is set True then the an ssh key must be present !!!
|
807
|
-
||| in the ~/.ssh folder named id_rsa. !!!
|
808
|
-
|
834
|
+
||| in the ~/.ssh folder named id_rsa. !!!
|
835
|
+
@param stripUnknownKeys If True then keys in the dict but not in the default config dict are stripped from the config.
|
836
|
+
@param addNewKeys If keys are found in the default config that are not in the config dict, add them.
|
837
|
+
@param filenameOverride The name for the config file in the .config folder. If left as None then the program name ise used
|
838
|
+
as the config filename."""
|
839
|
+
super().__init__(uio,
|
840
|
+
DotConfigManager.GetDefaultConfigFilename(filenameOverride),
|
841
|
+
defaultConfig,
|
842
|
+
encrypt=encrypt,
|
843
|
+
stripUnknownKeys=stripUnknownKeys,
|
844
|
+
addNewKeys=addNewKeys)
|
809
845
|
self._keyEditOrderList = keyEditOrderList
|
810
846
|
# Ensure the config file is present and loaded into the internal dict.
|
811
847
|
self.load()
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: p3lib
|
3
|
-
Version: 1.1.
|
3
|
+
Version: 1.1.107
|
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
|
@@ -7,18 +7,18 @@ p3lib/conduit.py,sha256=jPkjdtyCx2I6SFqcEo8y2g7rgnZ-jNY7oCuYIETzT5Q,6046
|
|
7
7
|
p3lib/database_if.py,sha256=XKu1w3zftGbj4Rh54wrWJnoCtqHkhCzJUPN2S70XIKg,11915
|
8
8
|
p3lib/file_io.py,sha256=A7_GKYPlmjRjq6U1YuWhmB0OhLhNm6cWQfQX8qfgYTk,5041
|
9
9
|
p3lib/gnome_desktop_app.py,sha256=zl9SKRBV8ipVg2faCs_gbAr8c42J1N_pntbFGG2BMiE,6694
|
10
|
-
p3lib/helper.py,sha256=
|
10
|
+
p3lib/helper.py,sha256=RHA0T1ckG3wLgTXgI_1mrtbzvMBaIwd8ow7x9orXUfA,13730
|
11
11
|
p3lib/json_networking.py,sha256=6u4s1SmypjTYPnSxHP712OgQ3ZJaxOqIkgHQ1J7Qews,9738
|
12
12
|
p3lib/mqtt_rpc.py,sha256=6LmFA1kR4HSJs9eWbOJORRHNY01L_lHWjvtE2fmY8P8,10511
|
13
13
|
p3lib/netif.py,sha256=3QV5OGdHhELIf4MBj6mx5MNCtVeZ7JXoNEkeu4KzCaE,9796
|
14
14
|
p3lib/netplotly.py,sha256=PMDx-w1jtRVW6Od5u_kuKbBxNpTS_Y88mMF60puMxLM,9363
|
15
15
|
p3lib/ngt.py,sha256=Y4HsSiaBEYi7OFWkqkDDJende_yyxsvIjUremfArXgA,39204
|
16
|
-
p3lib/pconfig.py,sha256=
|
16
|
+
p3lib/pconfig.py,sha256=wVWEYk4DghKQZaOuihJF2NcQzY1kdgCtW54BQ2McviE,37200
|
17
17
|
p3lib/ssh.py,sha256=OyoAQ_h1L2RfkjTAChDrvLFfl4Fe_gBNdX5rvK-wKiw,42125
|
18
18
|
p3lib/table_plot.py,sha256=RPncwVlGUkkx5Fw0dHQedXo0TSPlTi__VrJBDzaMsuI,32116
|
19
19
|
p3lib/uio.py,sha256=Aaxc99XiE3d2f9vLjaN-bZsckoNxay5t0ujdK6PXGrw,23265
|
20
|
-
p3lib-1.1.
|
21
|
-
p3lib-1.1.
|
22
|
-
p3lib-1.1.
|
23
|
-
p3lib-1.1.
|
24
|
-
p3lib-1.1.
|
20
|
+
p3lib-1.1.107.dist-info/LICENSE,sha256=igqTy5u0kVWM1n-NUZMvAlinY6lVjAXKoag0okkS8V8,1067
|
21
|
+
p3lib-1.1.107.dist-info/METADATA,sha256=kh2ALja9g0U6Wl8ZsW1ATL63LJKlVli7ilyqjYtH4MI,919
|
22
|
+
p3lib-1.1.107.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
|
23
|
+
p3lib-1.1.107.dist-info/top_level.txt,sha256=SDCpXYh-19yCFp4Z8ZK4B-3J4NvTCJElZ42NPgcR6-U,6
|
24
|
+
p3lib-1.1.107.dist-info/RECORD,,
|
File without changes
|
File without changes
|