1
0
mirror of https://github.com/gryf/pygtktalog.git synced 2025-12-17 03:20:17 +01:00

Changed default config file location to XDG_CONFIG_HOME

This commit is contained in:
2016-11-15 10:32:48 +01:00
parent 93b98bbe2b
commit e3febf46eb
3 changed files with 45 additions and 19 deletions

View File

@@ -143,11 +143,16 @@ NOTES
=====
Catalog file is plain sqlite database (optionally compressed with bzip2). All
images are stored in ~/.pygtktalog/images directory. Names for images are
generated sha512 hash from image file itself. There is small possibility for two
identical hash for different image files. However, no images are overwritten.
Thumbnail filename for each image is simply concatenation of image filename in
images directory and '_t' string.
images are stored in ``[CONFIG_PATH]/images`` directory, where ``[CONFIG_PATH]``
is one of the following location:
- ``$XDG_CONFIG_HOME/pygtktalog``
- ``$HOME/.pytgtktalog``
Names for images are generated sha512 hash from image file itself. There is
small possibility for two identical hash for different image files. However, no
images are overwritten. Thumbnail filename for each image is simply
concatenation of image filename in images directory and ``_t`` string.
There is also converter from old database to new for internal use only. In
public release there will be no other formats so it will be useless, and
@@ -156,8 +161,8 @@ images without big image will be lost. There are serious changes with
application design, and I decided, that is better to keep media unpacked on
disk, instead of pack it every time with save and unpack with open methods. New
design prevent from deleting any file from media directory (placed in
~/.pygtktalog/images). Functionality for exporting images and corresponding db
file is planned.
``[CONFIG_PATH]/images``). Functionality for exporting images and corresponding
db file is planned.
LICENSE
=======

View File

@@ -156,15 +156,10 @@ class ConfigModel(Model):
dstring = ('cd','ejectapp','imgprog')
try:
path = os.path.join(os.environ['HOME'], ".pygtktalog")
except KeyError:
raise KeyError, "Cannot stat path for current user home!"
path = os.path.join(path, "config.ini")
def __init__(self):
Model.__init__(self)
self._set_config_path()
self.category_tree = gtk.ListStore(gobject.TYPE_STRING)
self.refresh_ext()
@@ -332,6 +327,36 @@ class ConfigModel(Model):
self.search_history = self.search_history[:self.HISTORY_MAX]
return
def _set_config_path(self):
"""
Look for configuration files in following location:
~/.config/pygtktalog/config.ini
~/.pygtktalog/config.ini
Note, that ~/.config is the default XDG defined location for the
configuration. Apropriate XDG variable wil be checked first, in order
to locate configuration directory.
"""
xdg_path = os.getenv('XDG_CONFIG_HOME',
os.path.expanduser("~/.config"))
# Default config file location
cfg_file = os.path.join(xdg_path, "pygtktalog/config.ini")
# Check for other possibilities
for path in (os.path.join(xdg_path, "pygtktalog/config.ini"),
os.path.expanduser("~/.pygtktalog/config.ini")):
if os.path.exists(path):
cfg_file = path
break
if not os.path.exists(cfg_file):
try:
os.makedirs(os.path.dirname(cfg_file))
except OSError:
pass
self.path = cfg_file
def __str__(self):
"""show prefs in string way"""
string = "[varname]\tvalue\n"

View File

@@ -174,11 +174,8 @@ class MainModel(ModelMT):
# - #rrggbb
self.tag_cloud = []
try:
path = os.path.join(os.environ['HOME'], ".pygtktalog")
imgpath = os.path.join(path, "images")
except KeyError:
raise KeyError, "Cannot stat path for current user home!"
path = os.path.dirname(self.config.path)
imgpath = os.path.join(path, "images")
if os.path.exists(path):
if not os.path.isdir(path):
@@ -2012,4 +2009,3 @@ class MainModel(ModelMT):
#name = name.replace('?','_')
return name