summaryrefslogtreecommitdiffstats
path: root/pyload/config/Parser.py
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@users.noreply.github.com> 2015-04-19 16:37:00 +0200
committerGravatar Walter Purcaro <vuolter@users.noreply.github.com> 2015-04-19 16:37:00 +0200
commitf162ae0de0f71391c56957389cc3c8babc8022e1 (patch)
treec85c8117da6e20fe49f91c933d8c7e57eb808cb8 /pyload/config/Parser.py
parentMerge pull request #8 from ardi69/0.4.10 (diff)
downloadpyload-f162ae0de0f71391c56957389cc3c8babc8022e1.tar.xz
Use with statement
Diffstat (limited to 'pyload/config/Parser.py')
-rw-r--r--pyload/config/Parser.py27
1 files changed, 11 insertions, 16 deletions
diff --git a/pyload/config/Parser.py b/pyload/config/Parser.py
index b26af6202..a5be1444e 100644
--- a/pyload/config/Parser.py
+++ b/pyload/config/Parser.py
@@ -52,29 +52,26 @@ class ConfigParser(object):
copy(join(pypath, "pyload", "config", "default.conf"), "pyload.conf")
if not exists("plugin.conf"):
- f = open("plugin.conf", "wb")
- f.write("version: " + str(CONF_VERSION))
- f.close()
+ with open("plugin.conf", "wb") as f:
+ f.write("version: " + str(CONF_VERSION))
- f = open("pyload.conf", "rb")
- v = f.readline()
- f.close()
+ with open("pyload.conf", "rb") as f:
+ v = f.readline()
v = v[v.find(":") + 1:].strip()
if not v or int(v) < CONF_VERSION:
copy(join(pypath, "pyload", "config", "default.conf"), "pyload.conf")
print "Old version of config was replaced"
- f = open("plugin.conf", "rb")
- v = f.readline()
- f.close()
+ with open("plugin.conf", "rb") as f:
+ v = f.readline()
v = v[v.find(":") + 1:].strip()
if not v or int(v) < CONF_VERSION:
- f = open("plugin.conf", "wb")
- f.write("version: " + str(CONF_VERSION))
- f.close()
+ with open("plugin.conf", "wb") as f:
+ f.write("version: " + str(CONF_VERSION))
print "Old version of plugin-config replaced"
+
except Exception:
if n >= 3:
raise
@@ -104,9 +101,8 @@ class ConfigParser(object):
def parseConfig(self, config):
"""parses a given configfile"""
- f = open(config)
-
- config = f.read()
+ with open(config) as f:
+ config = f.read()
config = config.splitlines()[1:]
@@ -181,7 +177,6 @@ class ConfigParser(object):
print "Config Warning"
print_exc()
- f.close()
return conf