Move the configuration into XDG_CONFIG_HOME
This patch stores the configuration data inside XDG_CONFIG_HOME instead of doing it directly inside $HOME. Of course, it has backwards compatibility, using the old file if the new doesn't exists.
This commit is contained in:
parent
14d56fcaf5
commit
b46d897e4d
1 changed files with 21 additions and 4 deletions
|
|
@ -31,7 +31,7 @@ class configuration(GObject.GObject):
|
|||
def get_config():
|
||||
if configuration.current_configuration is None:
|
||||
configuration.current_configuration = configuration()
|
||||
if (configuration.current_configuration.fill_config()):
|
||||
if (configuration.current_configuration._fill_config()):
|
||||
configuration.current_configuration = None
|
||||
return configuration.current_configuration
|
||||
|
||||
|
|
@ -40,8 +40,16 @@ class configuration(GObject.GObject):
|
|||
self.version = str(pkg_resources.require("devedeng")[0].version)
|
||||
print("Version: " + self.version)
|
||||
|
||||
def fill_config(self):
|
||||
def _get_config_folder(self):
|
||||
config_folder = os.environ.get("$XDG_CONFIG_HOME")
|
||||
if config_folder is None:
|
||||
config_folder = os.path.join(os.environ.get("HOME"), ".config")
|
||||
config_folder = os.path.join(config_folder, "devedeng")
|
||||
if not os.path.exists(config_folder):
|
||||
os.makedirs(config_folder)
|
||||
return config_folder
|
||||
|
||||
def _fill_config(self):
|
||||
self.cores = 0
|
||||
proc_file = open("/proc/cpuinfo", "r")
|
||||
for line in proc_file:
|
||||
|
|
@ -108,7 +116,12 @@ class configuration(GObject.GObject):
|
|||
self.subt_outline_color = (0, 0, 0, 1)
|
||||
self.subt_outline_thickness = 0.0
|
||||
|
||||
config_path = os.path.join(os.environ.get("HOME"), ".devedeng")
|
||||
config_folder = self._get_config_folder()
|
||||
config_path = os.path.join(config_folder, "devedeng.cfg")
|
||||
if not os.path.exists(config_path):
|
||||
# old config file
|
||||
config_path = os.path.join(os.environ.get("HOME"), ".devedeng")
|
||||
|
||||
try:
|
||||
config_data = open(config_path, "r")
|
||||
for linea in config_data:
|
||||
|
|
@ -184,7 +197,7 @@ class configuration(GObject.GObject):
|
|||
|
||||
def save_config(self):
|
||||
|
||||
config_path = os.path.join(os.environ.get("HOME"), ".devedeng")
|
||||
config_path = os.path.join(self._get_config_folder(), "devedeng.cfg")
|
||||
try:
|
||||
config_data = open(config_path, "w")
|
||||
config_data.write("video_format:")
|
||||
|
|
@ -236,6 +249,10 @@ class configuration(GObject.GObject):
|
|||
str(self.subt_outline_thickness))
|
||||
|
||||
config_data.close()
|
||||
# remove old configuration files
|
||||
config_path = os.path.join(os.environ.get("HOME"), ".devedeng")
|
||||
if os.path.exists(config_path):
|
||||
os.remove(config_path)
|
||||
except:
|
||||
pass
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue