|
@@ -21,6 +21,7 @@ from __future__ import print_function
|
|
|
import os
|
|
|
import subprocess
|
|
|
import sys
|
|
|
+import json
|
|
|
|
|
|
from lib_stov import stov_exceptions
|
|
|
|
|
@@ -51,7 +52,7 @@ class conf(object):
|
|
|
"db_version": "3",
|
|
|
"videocodec": "h264",
|
|
|
"maxresolution": "1080p",
|
|
|
- "maxfails": "50",
|
|
|
+ "maxfails": 50,
|
|
|
"check_title": "no"
|
|
|
}
|
|
|
|
|
@@ -92,13 +93,11 @@ class conf(object):
|
|
|
"""
|
|
|
try:
|
|
|
configfile = open(str(os.environ['HOME']) +
|
|
|
- "/.stov/stov.config", "w")
|
|
|
+ "/.stov/stov.json", "w")
|
|
|
except IOError:
|
|
|
raise stov_exceptions.ConfigFileWriteErrorException()
|
|
|
else:
|
|
|
- for key, value in self.values.items():
|
|
|
- configfile.write(key.upper() + "=" + self.values[key] +
|
|
|
- "\n")
|
|
|
+ json.dump(self.values, configfile, indent=0)
|
|
|
configfile.close()
|
|
|
|
|
|
def Initialize(self):
|
|
@@ -117,9 +116,10 @@ class conf(object):
|
|
|
self.values["youtube-dl"] = process.communicate()[0].strip()
|
|
|
self.WriteConfig()
|
|
|
|
|
|
- def ReadConfig(self):
|
|
|
- """Reads the existing configuration file and places the values in the
|
|
|
- dictionary. Existing values (such as default values) are overwritten.
|
|
|
+ def ReadOldConfig(self):
|
|
|
+ """Reads the existing plain text configuration file and places the
|
|
|
+ values in the dictionary. Existing values (such as default values)
|
|
|
+ are overwritten.
|
|
|
|
|
|
"""
|
|
|
try:
|
|
@@ -135,6 +135,19 @@ class conf(object):
|
|
|
self.dbpath = str(os.environ['HOME']) + "/.stov/" + \
|
|
|
self.values["database"]
|
|
|
|
|
|
+ def ReadConfig(self):
|
|
|
+ """Reads the existing json configuration files and loads the values in
|
|
|
+ the dictionary.
|
|
|
+ """
|
|
|
+ try:
|
|
|
+ configfile = open(str(os.environ['HOME']) + "/.stov/stov.json",
|
|
|
+ "r")
|
|
|
+ except IOError:
|
|
|
+ raise stov_exceptions.ConfigFileReadErrorException()
|
|
|
+ else:
|
|
|
+ self.values = json.load(configfile)
|
|
|
+ configfile.close()
|
|
|
+
|
|
|
def CheckConfig(self):
|
|
|
"""Checks if the configuration is up-to-date with the running
|
|
|
stov version.
|
|
@@ -151,7 +164,7 @@ class conf(object):
|
|
|
self.values["config_version"] = str(currentversion)
|
|
|
return False
|
|
|
else:
|
|
|
- self.values["config_version"] = str(currentversion)
|
|
|
+ self.values["config_version"] = currentversion
|
|
|
return True
|
|
|
|
|
|
def UpdateConfig(self):
|
|
@@ -229,3 +242,17 @@ class conf(object):
|
|
|
self.values[value] = user_input
|
|
|
self.dbpath = str(os.environ['HOME']) + "/.stov/" + \
|
|
|
self.values["database"]
|
|
|
+
|
|
|
+ def migrate_config(self):
|
|
|
+ """Migrates the configuration from the old plain text config to
|
|
|
+ the new and shiny json configuration file.
|
|
|
+ """
|
|
|
+ try:
|
|
|
+ self.ReadOldConfig()
|
|
|
+ self.WriteConfig()
|
|
|
+ except stov_exceptions.ConfigFileReadErrorException:
|
|
|
+ raise stov_exceptions.ConfigurationMigrationFailed()
|
|
|
+ except stov_exceptions.ConfigFileWriteErrorException:
|
|
|
+ raise stov_exceptions.ConfigurationMigrationFailed
|
|
|
+ else:
|
|
|
+ os.remove(str(os.environ['HOME']) + "/.stov/stov.config")
|