|
@@ -1,4 +1,4 @@
|
|
|
-# This file is part of stov, written by Helmut Pozimski 2012-2017.
|
|
|
+# This file is part of stov, written by Helmut Pozimski 2012-2021.
|
|
|
#
|
|
|
# stov is free software: you can redistribute it and/or modify
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
@@ -29,7 +29,7 @@ from lib_stov import stov_exceptions
|
|
|
LOGGER = logging.getLogger("stov")
|
|
|
|
|
|
|
|
|
-class Conf(object):
|
|
|
+class Conf:
|
|
|
"""This class is used to create the object which is responsible for all
|
|
|
configuration operations.
|
|
|
"""
|
|
@@ -121,8 +121,8 @@ class Conf(object):
|
|
|
try:
|
|
|
configfile = open(str(os.environ['HOME']) +
|
|
|
"/.stov/stov.json", "w")
|
|
|
- except IOError:
|
|
|
- raise stov_exceptions.ConfigFileWriteErrorException()
|
|
|
+ except IOError as exc:
|
|
|
+ raise stov_exceptions.ConfigFileWriteErrorException() from exc
|
|
|
else:
|
|
|
json.dump(self.values, configfile, indent=0)
|
|
|
configfile.close()
|
|
@@ -136,8 +136,8 @@ class Conf(object):
|
|
|
LOGGER.debug(_("Creating stov configuration directory"))
|
|
|
try:
|
|
|
os.mkdir(str(os.environ['HOME']) + "/.stov", 0o750)
|
|
|
- except os.error:
|
|
|
- raise stov_exceptions.DirectoryCreationFailedException()
|
|
|
+ except os.error as exc:
|
|
|
+ raise stov_exceptions.DirectoryCreationFailedException() from exc
|
|
|
else:
|
|
|
self.write_config()
|
|
|
|
|
@@ -152,15 +152,15 @@ class Conf(object):
|
|
|
try:
|
|
|
configfile = open(str(os.environ['HOME']) +
|
|
|
"/.stov/stov.config", "r")
|
|
|
- except IOError:
|
|
|
- raise stov_exceptions.ConfigFileReadErrorException()
|
|
|
+ except IOError as exc:
|
|
|
+ raise stov_exceptions.ConfigFileReadErrorException() from exc
|
|
|
for lines in configfile:
|
|
|
tmpline = lines.strip()
|
|
|
tmplist = tmpline.split("=")
|
|
|
self.values[tmplist[0].lower()] = tmplist[1]
|
|
|
configfile.close()
|
|
|
- self.dbpath = str(os.environ['HOME']) + "/.stov/" + \
|
|
|
- self.values["database"]
|
|
|
+ self.dbpath = str(os.environ['HOME']) + "/.stov/" \
|
|
|
+ + self.values["database"]
|
|
|
|
|
|
def read_config(self):
|
|
|
"""Reads the existing json configuration files and loads the values in
|
|
@@ -170,8 +170,8 @@ class Conf(object):
|
|
|
try:
|
|
|
configfile = open(str(os.environ['HOME']) + "/.stov/stov.json",
|
|
|
"r")
|
|
|
- except IOError:
|
|
|
- raise stov_exceptions.ConfigFileReadErrorException()
|
|
|
+ except IOError as exc:
|
|
|
+ raise stov_exceptions.ConfigFileReadErrorException() from exc
|
|
|
else:
|
|
|
self.values.update(json.load(configfile))
|
|
|
configfile.close()
|
|
@@ -183,8 +183,9 @@ class Conf(object):
|
|
|
"""
|
|
|
try:
|
|
|
current_version = int(self.values["config_version"])
|
|
|
- except ValueError:
|
|
|
- raise stov_exceptions.InvalidConfigurationVersionException()
|
|
|
+ except ValueError as exc:
|
|
|
+ raise stov_exceptions.InvalidConfigurationVersionException() \
|
|
|
+ from exc
|
|
|
self.values["config_version"] = "0"
|
|
|
self.read_config()
|
|
|
if self.values["config_version"] == "0" \
|
|
@@ -203,15 +204,15 @@ class Conf(object):
|
|
|
|
|
|
def check_db(self):
|
|
|
"""Checks the database if it is up-to-date"""
|
|
|
- currentdbversion = int(self.values["db_version"])
|
|
|
+ current_db_version = int(self.values["db_version"])
|
|
|
self.values["db_version"] = "0"
|
|
|
self.read_config()
|
|
|
if self.values["db_version"] == "0" or \
|
|
|
int(self.values["db_version"]) < \
|
|
|
- int(currentdbversion):
|
|
|
- self.values["db_version"] = str(currentdbversion)
|
|
|
+ int(current_db_version):
|
|
|
+ self.values["db_version"] = str(current_db_version)
|
|
|
return False
|
|
|
- self.values["db_version"] = str(currentdbversion)
|
|
|
+ self.values["db_version"] = str(current_db_version)
|
|
|
return True
|
|
|
|
|
|
def assist(self):
|
|
@@ -239,10 +240,10 @@ class Conf(object):
|
|
|
try:
|
|
|
self.read_old_config()
|
|
|
self.write_config()
|
|
|
- except stov_exceptions.ConfigFileReadErrorException:
|
|
|
- raise stov_exceptions.ConfigurationMigrationFailed()
|
|
|
- except stov_exceptions.ConfigFileWriteErrorException:
|
|
|
- raise stov_exceptions.ConfigurationMigrationFailed
|
|
|
+ except stov_exceptions.ConfigFileReadErrorException as exc:
|
|
|
+ raise stov_exceptions.ConfigurationMigrationFailed() from exc
|
|
|
+ except stov_exceptions.ConfigFileWriteErrorException as exc:
|
|
|
+ raise stov_exceptions.ConfigurationMigrationFailed from exc
|
|
|
else:
|
|
|
os.remove(str(os.environ['HOME']) + "/.stov/stov.config")
|
|
|
|
|
@@ -272,4 +273,10 @@ class Conf(object):
|
|
|
return logger
|
|
|
|
|
|
def get_value(self, identifier):
|
|
|
- return self.values[identifier];
|
|
|
+ """
|
|
|
+ Returns the value for the specified identifier
|
|
|
+
|
|
|
+ :param identifier: the identifier in the value dictionary
|
|
|
+ :return:
|
|
|
+ """
|
|
|
+ return self.values[identifier]
|