Merge pull request #230 from filippsen/makefile-fix
[git-cola.git] / cola / resources.py
blob0194b478fad801904274c3f11a1bd9d2c932d3d3
1 """Provides the prefix() function for finding cola resources"""
2 import os
3 import webbrowser
4 from os.path import dirname
6 from cola import core
9 _modpath = core.abspath(__file__)
10 if os.path.join('share', 'git-cola', 'lib') in _modpath:
11 # this is the release tree
12 # __file__ = '$prefix/share/git-cola/lib/cola/__file__.py'
13 _lib_dir = dirname(dirname(_modpath))
14 _prefix = dirname(dirname(dirname(_lib_dir)))
15 else:
16 # this is the source tree
17 # __file__ = '$prefix/cola/__file__.py'
18 _prefix = dirname(dirname(_modpath))
21 def prefix(*args):
22 """Return a path relative to cola's installation prefix"""
23 return os.path.join(_prefix, *args)
26 def doc(*args):
27 """Return a path relative to cola's /usr/share/doc/ directory"""
28 return os.path.join(_prefix, 'share', 'doc', 'git-cola', *args)
31 def html_docs():
32 """Return the path to the cola html documentation."""
33 # index.html only exists after the install-docs target is run,
34 # so fallback to git-cola.txt.
35 htmldocs = doc('html', 'index.html')
36 if core.exists(htmldocs):
37 return htmldocs
38 return doc('git-cola.txt')
41 def show_html_docs():
42 url = html_docs()
43 webbrowser.open_new_tab(url)
45 def share(*args):
46 """Return a path relative to cola's /usr/share/ directory"""
47 return prefix('share', 'git-cola', *args)
50 def icon(basename):
51 """Return the full path to an icon file given a basename."""
52 return 'icons:'+basename
55 def icon_dir():
56 """Return the path to the style dir within the cola install tree."""
57 return share('icons')
60 def config_home(*args):
61 config = core.getenv('XDG_CONFIG_HOME',
62 os.path.join(core.expanduser('~'), '.config'))
63 return os.path.join(config, 'git-cola', *args)