p3lib 1.1.83__py3-none-any.whl → 1.1.84__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 CHANGED
@@ -338,49 +338,6 @@ class ConfigManager(object):
338
338
  configPath = configPath.strip()
339
339
 
340
340
  return join( configPath, cfgFilename )
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
341
 
385
342
  def __init__(self, uio, cfgFilename, defaultConfig, addDotToFilename=True, encrypt=False, cfgPath=None):
386
343
  """@brief Constructor
@@ -782,3 +739,69 @@ class ConfigAttrDetails(object):
782
739
  self.minValue = minValue #Only used for numbers
783
740
  self.maxValue = maxValue #Only used for numbers
784
741
  self.allowEmpty = allowEmpty #Only used for strings
742
+
743
+ class DotConfigManager(ConfigManager):
744
+ """@brief This extends the previous ConfigManager and stores config under the ~/.config folder
745
+ rather than in the home folder (~) using a filename prefixed with the . character.
746
+ The ~/.config folder holds either a single config file of the startup python filename.
747
+ The ./config folder can contain another python module folder which contains the config
748
+ file. E.G for this example app the ~/.config/examples/pconfig_example.cfg folder is used."""
749
+
750
+ @staticmethod
751
+ def GetDefaultConfigFilename():
752
+ """@brief Get the default name of the config file for this app. This will be the program name
753
+ (file that started up initially) without the .py extension. On Linux systems this
754
+ will reside in the ~/.config folder. If the ~/.config does not exist an attempt to
755
+ create it is made. If the ~/.config folder cannot be created then the config file
756
+ will be as detailed above but will be prefixed by a . character and will reside
757
+ in the users home folder."""
758
+ progName = sys.argv[0]
759
+ if progName.endswith('.py'):
760
+ progName = progName[0:-3]
761
+
762
+ folder = '.config'
763
+ homePath = os.path.expanduser("~")
764
+ configFolder = os.path.join(homePath, folder)
765
+
766
+ if not os.path.isdir(homePath):
767
+ raise Exception(f"{homePath} HOME path does not exist.")
768
+
769
+ # Create the ~/.config folder if it does not exist
770
+ if not os.path.isdir(configFolder):
771
+ # Create the ~/.config folder
772
+ os.makedir(configFolder)
773
+
774
+ # Note that we assume that addDotToFilename in the ConfigManager constructor is set True
775
+ # as this will prefix the filename with the . character.
776
+ if os.path.isdir(configFolder):
777
+ extraFolders = os.path.dirname(progName)
778
+ configFolder = os.path.join(configFolder, extraFolders)
779
+ if not os.path.isdir(configFolder):
780
+ os.makedirs(configFolder)
781
+ if not os.path.isdir(configFolder):
782
+ raise Exception(f"Failed to create the {configFolder} folder.")
783
+
784
+ configFolder = "config"
785
+ configFolder = os.path.join(configFolder, extraFolders)
786
+ configFilename = os.path.join(configFolder, os.path.basename(progName) + '.cfg')
787
+
788
+ else:
789
+ configFilename = progName
790
+
791
+ return configFilename
792
+
793
+ def __init__(self, defaultConfig, uio=None, encrypt=False):
794
+ """@brief Constructor
795
+ @param defaultConfig A default config instance containing all the default key-value pairs.
796
+ @param uio A UIO (User Input Output) instance. May be set to None if no user messages are required.
797
+ @param encrypt If True then data will be encrypted in the saved files.
798
+ The encryption uses part of the the local SSH RSA private key.
799
+ This is not secure but assuming the private key has not been compromised it's
800
+ probably the best we can do.
801
+ !!! Therefore if encrypt is set True then the an ssh key must be present !!!
802
+ ||| in the ~/.ssh folder named id_rsa. !!!"""
803
+ super().__init__(uio, DotConfigManager.GetDefaultConfigFilename(), defaultConfig, encrypt=encrypt)
804
+ # Ensure the config file is present and loaded into the internal dict.
805
+ self.load()
806
+
807
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: p3lib
3
- Version: 1.1.83
3
+ Version: 1.1.84
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=S0qcWiiTA8Kz3bIja41NTHJdqGS6lI5iklHb-dCAtTc,32336
14
+ p3lib/pconfig.py,sha256=s6s8HRAXLgDO5hQsIbVP-XgLEhoTQKjwKHrwyJUO4UU,33945
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.83.dist-info/LICENSE,sha256=igqTy5u0kVWM1n-NUZMvAlinY6lVjAXKoag0okkS8V8,1067
19
- p3lib-1.1.83.dist-info/METADATA,sha256=sdLtW4qN9ORZQ_qgptOfxTBUYdxLdFlx_Z6PbewTpc0,918
20
- p3lib-1.1.83.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
21
- p3lib-1.1.83.dist-info/top_level.txt,sha256=SDCpXYh-19yCFp4Z8ZK4B-3J4NvTCJElZ42NPgcR6-U,6
22
- p3lib-1.1.83.dist-info/RECORD,,
18
+ p3lib-1.1.84.dist-info/LICENSE,sha256=igqTy5u0kVWM1n-NUZMvAlinY6lVjAXKoag0okkS8V8,1067
19
+ p3lib-1.1.84.dist-info/METADATA,sha256=SLRlR7NXQivWGy6xkcl_ph9ZaP7RRcDPmNoAqrqmzEM,918
20
+ p3lib-1.1.84.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
21
+ p3lib-1.1.84.dist-info/top_level.txt,sha256=SDCpXYh-19yCFp4Z8ZK4B-3J4NvTCJElZ42NPgcR6-U,6
22
+ p3lib-1.1.84.dist-info/RECORD,,
File without changes