p3lib 1.1.87__py3-none-any.whl → 1.1.89__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/pconfig.py +56 -38
- {p3lib-1.1.87.dist-info → p3lib-1.1.89.dist-info}/METADATA +1 -1
- {p3lib-1.1.87.dist-info → p3lib-1.1.89.dist-info}/RECORD +6 -6
- {p3lib-1.1.87.dist-info → p3lib-1.1.89.dist-info}/LICENSE +0 -0
- {p3lib-1.1.87.dist-info → p3lib-1.1.89.dist-info}/WHEEL +0 -0
- {p3lib-1.1.87.dist-info → p3lib-1.1.89.dist-info}/top_level.txt +0 -0
p3lib/pconfig.py
CHANGED
@@ -756,53 +756,45 @@ class DotConfigManager(ConfigManager):
|
|
756
756
|
The ~/.config folder holds either a single config file of the startup python filename.
|
757
757
|
The ./config folder can contain another python module folder which contains the config
|
758
758
|
file. E.G for this example app the ~/.config/examples/pconfig_example.cfg folder is used."""
|
759
|
+
DEFAULT_CONFIG = None # This must be overridden in a subclass to define the configuration parameters and values.
|
760
|
+
KEY_EDIT_ORDER_LIST = None
|
759
761
|
|
760
762
|
@staticmethod
|
761
763
|
def GetDefaultConfigFilename():
|
762
764
|
"""@brief Get the default name of the config file for this app. This will be the program name
|
763
|
-
(file that started up initially) without the .py extension.
|
764
|
-
will
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
folder = '.config'
|
773
|
-
homePath = os.path.expanduser("~")
|
774
|
-
configFolder = os.path.join(homePath, folder)
|
775
|
-
|
776
|
-
if not os.path.isdir(homePath):
|
777
|
-
raise Exception(f"{homePath} HOME path does not exist.")
|
765
|
+
(file that started up initially) without the .py extension. A .cfg extension is added
|
766
|
+
and it will be found in the ~/.config folder."""
|
767
|
+
dotConfigFolder = '.config'
|
768
|
+
homePath = os.path.expanduser("~")
|
769
|
+
configFolder = os.path.join(homePath, dotConfigFolder)
|
770
|
+
|
771
|
+
if not os.path.isdir(homePath):
|
772
|
+
raise Exception(f"{homePath} HOME path does not exist.")
|
778
773
|
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
# Note that we assume that addDotToFilename in the ConfigManager constructor is set True
|
785
|
-
# as this will prefix the filename with the . character.
|
786
|
-
if os.path.isdir(configFolder):
|
787
|
-
extraFolders = os.path.dirname(progName)
|
788
|
-
configFolder = os.path.join(configFolder, extraFolders)
|
789
|
-
if not os.path.isdir(configFolder):
|
790
|
-
os.makedirs(configFolder)
|
791
|
-
if not os.path.isdir(configFolder):
|
792
|
-
raise Exception(f"Failed to create the {configFolder} folder.")
|
793
|
-
|
794
|
-
configFolder = "config"
|
795
|
-
configFolder = os.path.join(configFolder, extraFolders)
|
796
|
-
configFilename = os.path.join(configFolder, os.path.basename(progName) + '.cfg')
|
774
|
+
# Create the ~/.config folder if it does not exist
|
775
|
+
if not os.path.isdir(configFolder):
|
776
|
+
# Create the ~/.config folder
|
777
|
+
os.makedir(configFolder)
|
797
778
|
|
798
|
-
|
799
|
-
|
779
|
+
progName = sys.argv[0]
|
780
|
+
if progName.endswith('.py'):
|
781
|
+
progName = progName[0:-3]
|
782
|
+
progName = os.path.basename(progName).strip()
|
800
783
|
|
801
|
-
|
802
|
-
|
803
|
-
|
784
|
+
# Note that we assume that addDotToFilename in the ConfigManager constructor is set True
|
785
|
+
# as this will prefix the filename with the . character.
|
786
|
+
if os.path.isdir(configFolder):
|
787
|
+
configFilename = os.path.join(".config", progName + ".cfg")
|
788
|
+
|
789
|
+
else:
|
790
|
+
raise Exception(f"Failed to create the {configFolder} folder.")
|
791
|
+
|
792
|
+
return configFilename
|
793
|
+
|
794
|
+
def __init__(self, defaultConfig, keyEditOrderList=None, uio=None, encrypt=False):
|
804
795
|
"""@brief Constructor
|
805
796
|
@param defaultConfig A default config instance containing all the default key-value pairs.
|
797
|
+
@param keyEditOrderList A list of all the dict keys in the order that the caller wishes them to be displayed top the user.
|
806
798
|
@param uio A UIO (User Input Output) instance. May be set to None if no user messages are required.
|
807
799
|
@param encrypt If True then data will be encrypted in the saved files.
|
808
800
|
The encryption uses part of the the local SSH RSA private key.
|
@@ -811,7 +803,33 @@ class DotConfigManager(ConfigManager):
|
|
811
803
|
!!! Therefore if encrypt is set True then the an ssh key must be present !!!
|
812
804
|
||| in the ~/.ssh folder named id_rsa. !!!"""
|
813
805
|
super().__init__(uio, DotConfigManager.GetDefaultConfigFilename(), defaultConfig, encrypt=encrypt)
|
806
|
+
self._keyEditOrderList = keyEditOrderList
|
814
807
|
# Ensure the config file is present and loaded into the internal dict.
|
815
808
|
self.load()
|
816
809
|
|
810
|
+
def show(self):
|
811
|
+
"""@brief A helper method to show the dictionary config to the user.
|
812
|
+
@return A dictionary mapping the attribute ID's (keys) to dictionary keys (values)."""
|
813
|
+
maxKeyLen=10
|
814
|
+
# If the caller wants to present the parameters to the user in a partiular order
|
815
|
+
if self._keyEditOrderList:
|
816
|
+
keys = self._keyEditOrderList
|
817
|
+
defaultKeys = list(self._configDict.keys())
|
818
|
+
for defaultKey in defaultKeys:
|
819
|
+
if defaultKey not in keys:
|
820
|
+
raise Exception(f"BUG: DotConfigManager: {defaultKey} key is missing from the keyEditOrderList.")
|
821
|
+
# Present the parameters to the user in any order.
|
822
|
+
else:
|
823
|
+
keys = list(self._configDict.keys())
|
817
824
|
|
825
|
+
for key in keys:
|
826
|
+
if len(key) > maxKeyLen:
|
827
|
+
maxKeyLen = len(key)
|
828
|
+
self._info("ID PARAMETER"+" "*(maxKeyLen-8)+" VALUE")
|
829
|
+
id=1
|
830
|
+
idKeyDict = {}
|
831
|
+
for key in keys:
|
832
|
+
idKeyDict[id]=key
|
833
|
+
self._info("{:<3d} {:<{}} {}".format(id, key, maxKeyLen+1, self._configDict[key]))
|
834
|
+
id=id+1
|
835
|
+
return idKeyDict
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: p3lib
|
3
|
-
Version: 1.1.
|
3
|
+
Version: 1.1.89
|
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
|
@@ -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=
|
14
|
+
p3lib/pconfig.py,sha256=KLKS3G6Xc2qgDoDCe1bWHqrl13RwrCXL7j80TWaIZWg,35296
|
15
15
|
p3lib/ssh.py,sha256=klqQ9YuqU8GwPVPHrAJeEs5PI5hgoYiXflq2kIGG3as,39509
|
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.89.dist-info/LICENSE,sha256=igqTy5u0kVWM1n-NUZMvAlinY6lVjAXKoag0okkS8V8,1067
|
19
|
+
p3lib-1.1.89.dist-info/METADATA,sha256=MavcK6Pe6ORhP_GNX2WZ7mNcVMbLgKA7J3KSAFGR_N4,918
|
20
|
+
p3lib-1.1.89.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
|
21
|
+
p3lib-1.1.89.dist-info/top_level.txt,sha256=SDCpXYh-19yCFp4Z8ZK4B-3J4NvTCJElZ42NPgcR6-U,6
|
22
|
+
p3lib-1.1.89.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|