summaryrefslogtreecommitdiffstats
path: root/base/server/src
diff options
context:
space:
mode:
Diffstat (limited to 'base/server/src')
-rw-r--r--base/server/src/engine/pkihelper.py30
-rw-r--r--base/server/src/engine/pkimanifest.py37
-rw-r--r--base/server/src/engine/pkiparser.py31
3 files changed, 46 insertions, 52 deletions
diff --git a/base/server/src/engine/pkihelper.py b/base/server/src/engine/pkihelper.py
index df3658307..9c775f65d 100644
--- a/base/server/src/engine/pkihelper.py
+++ b/base/server/src/engine/pkihelper.py
@@ -1692,17 +1692,16 @@ class file:
config.pki_log.info(log.PKIHELPER_COPY_WITH_SLOT_SUBSTITUTION_2,
old_name, new_name,
extra = config.PKI_INDENTATION_LEVEL_2)
- FILE = open(new_name, "w")
- for line in fileinput.FileInput(old_name):
- for slot in slots:
- if slot != '__name__' and slots[slot] in line:
- config.pki_log.debug(
- log.PKIHELPER_SLOT_SUBSTITUTION_2,
- slots[slot], master[slot],
- extra = config.PKI_INDENTATION_LEVEL_3)
- line = line.replace(slots[slot], master[slot])
- FILE.write(line)
- FILE.close()
+ with open(new_name, "w") as FILE:
+ for line in fileinput.FileInput(old_name):
+ for slot in slots:
+ if slot != '__name__' and slots[slot] in line:
+ config.pki_log.debug(
+ log.PKIHELPER_SLOT_SUBSTITUTION_2,
+ slots[slot], master[slot],
+ extra = config.PKI_INDENTATION_LEVEL_3)
+ line = line.replace(slots[slot], master[slot])
+ FILE.write(line)
if uid == None:
uid = identity.get_uid()
if gid == None:
@@ -1750,11 +1749,10 @@ class file:
config.pki_log.info(log.PKIHELPER_NOISE_FILE_2, name, bytes,
extra = config.PKI_INDENTATION_LEVEL_2)
open(name, "w").close()
- FILE = open(name, "w")
- noise = ''.join(random.choice(string.ascii_letters + \
- string.digits) for x in range(bytes))
- FILE.write(noise)
- FILE.close()
+ with open(name, "w") as FILE:
+ noise = ''.join(random.choice(string.ascii_letters +\
+ string.digits) for x in range(bytes))
+ FILE.write(noise)
# chmod <perms> <name>
config.pki_log.debug(log.PKIHELPER_CHMOD_2, perms, name,
extra = config.PKI_INDENTATION_LEVEL_3)
diff --git a/base/server/src/engine/pkimanifest.py b/base/server/src/engine/pkimanifest.py
index f53b76492..addc5a7d8 100644
--- a/base/server/src/engine/pkimanifest.py
+++ b/base/server/src/engine/pkimanifest.py
@@ -38,13 +38,13 @@ RECORD_TYPE_SYMLINK = "symlink"
# PKI Deployment Manifest Record Class
class record(object):
- __slots__= "name",\
- "type",\
- "user",\
- "group",\
- "uid",\
- "gid",\
- "permissions",\
+ __slots__ = "name", \
+ "type", \
+ "user", \
+ "group", \
+ "uid", \
+ "gid", \
+ "permissions", \
"acls",
def items(self):
@@ -73,29 +73,26 @@ class file:
def write(self):
try:
- fd = open(self.filename, "wt")
- c = csv.writer(fd)
- for record in database:
- c.writerow(tuple(record))
- fd.close()
+ with open(self.filename, "wt") as fd:
+ c = csv.writer(fd)
+ for record in database:
+ c.writerow(tuple(record))
except IOError as exc:
config.pki_log.error(log.PKI_IOERROR_1, exc,
- extra=config.PKI_INDENTATION_LEVEL_1)
+ extra = config.PKI_INDENTATION_LEVEL_1)
raise
def read(self):
try:
- fd = open(self.filename, "rt")
- cr = csv.reader(fd)
- for row in cr:
- print tuple(row)
- fd.close()
+ with open(self.filename, "rt") as fd:
+ cr = csv.reader(fd)
+ for row in cr:
+ print tuple(row)
except IOError as exc:
config.pki_log.error(log.PKI_IOERROR_1, exc,
- extra=config.PKI_INDENTATION_LEVEL_1)
+ extra = config.PKI_INDENTATION_LEVEL_1)
raise
-
# PKI Deployment Global Named Tuples
database = []
file = file()
diff --git a/base/server/src/engine/pkiparser.py b/base/server/src/engine/pkiparser.py
index 6a94e3827..8c9b6d620 100644
--- a/base/server/src/engine/pkiparser.py
+++ b/base/server/src/engine/pkiparser.py
@@ -208,22 +208,21 @@ class PKIConfigParser:
@staticmethod
def read_simple_configuration_file(filename):
values = {}
- f = open(filename)
- for line in f:
- # First, remove comments:
- if PKIConfigParser.COMMENT_CHAR in line:
- # split on comment char, keep only the part before
- line, comment = line.split(PKIConfigParser.COMMENT_CHAR, 1)
- # Second, find lines with an name=value:
- if PKIConfigParser.OPTION_CHAR in line:
- # split on name char:
- name, value = line.split(PKIConfigParser.OPTION_CHAR, 1)
- # strip spaces:
- name = name.strip()
- value = value.strip()
- # store in dictionary:
- values[name] = value
- f.close()
+ with open(filename) as f:
+ for line in f:
+ # First, remove comments:
+ if PKIConfigParser.COMMENT_CHAR in line:
+ # split on comment char, keep only the part before
+ line, comment = line.split(PKIConfigParser.COMMENT_CHAR, 1)
+ # Second, find lines with an name=value:
+ if PKIConfigParser.OPTION_CHAR in line:
+ # split on name char:
+ name, value = line.split(PKIConfigParser.OPTION_CHAR, 1)
+ # strip spaces:
+ name = name.strip()
+ value = value.strip()
+ # store in dictionary:
+ values[name] = value
return values