summaryrefslogtreecommitdiffstats
path: root/base/common/python
diff options
context:
space:
mode:
authorEndi S. Dewata <edewata@redhat.com>2017-03-01 07:08:11 +0100
committerEndi S. Dewata <edewata@redhat.com>2017-03-01 18:02:27 +0100
commit7810a55d0b967ff5355312e952fc4c7314a45f35 (patch)
tree3095ce5d63821b122b69588882a8434d3eb8fb36 /base/common/python
parentd7c22171b84b7d8f7a068be42b07a53c8092eb48 (diff)
downloadpki-7810a55d0b967ff5355312e952fc4c7314a45f35.tar.gz
pki-7810a55d0b967ff5355312e952fc4c7314a45f35.tar.xz
pki-7810a55d0b967ff5355312e952fc4c7314a45f35.zip
Refactored PKIInstance.load().
The code that loads the password.conf in PKIInstance.load() has been converted into a general purpose load_properties() method. A corresponding store_properties() method has been added as well.
Diffstat (limited to 'base/common/python')
-rw-r--r--base/common/python/pki/util.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/base/common/python/pki/util.py b/base/common/python/pki/util.py
index 8a75ff6f5..68118f439 100644
--- a/base/common/python/pki/util.py
+++ b/base/common/python/pki/util.py
@@ -143,6 +143,39 @@ def customize_file(input_file, output_file, params):
outfile.write(line)
+def load_properties(filename, properties):
+
+ with open(filename) as f:
+
+ lines = f.read().splitlines()
+
+ for index, line in enumerate(lines):
+
+ line = line.strip()
+
+ if not line or line.startswith('#'):
+ continue
+
+ parts = line.split('=', 1)
+
+ if len(parts) < 2:
+ raise Exception('Missing delimiter in %s line %d' %
+ (filename, index + 1))
+
+ name = parts[0].strip()
+ value = parts[1].strip()
+ properties[name] = value
+
+
+def store_properties(filename, properties):
+
+ with open(filename, 'w') as f:
+
+ for name, value in properties.items():
+ line = '%s=%s\n' % (name, value)
+ f.write(line)
+
+
def copytree(src, dst, symlinks=False, ignore=None):
"""
Recursively copy a directory tree using copy2().