status: add icons and midlights to section items
[git-cola.git] / cola / resources.py
blob6a4eadccf9a4bd209b69b6f1a585a912f184d6eb
1 """Provides the prefix() function for finding cola resources"""
2 from __future__ import division, absolute_import, unicode_literals
4 import os
5 import webbrowser
6 from os.path import dirname
8 from cola import core
11 _modpath = core.abspath(__file__)
12 if os.path.join('share', 'git-cola', 'lib') in _modpath:
13 # this is the release tree
14 # __file__ = '$prefix/share/git-cola/lib/cola/__file__.py'
15 _lib_dir = dirname(dirname(_modpath))
16 _prefix = dirname(dirname(dirname(_lib_dir)))
17 elif os.path.join('pkgs', 'cola') in _modpath:
18 # Windows release tree
19 # __file__ = $installdir/pkgs/cola/resources.py
20 _prefix = dirname(dirname(dirname(_modpath)))
21 else:
22 # this is the source tree
23 # __file__ = '$prefix/cola/__file__.py'
24 _prefix = dirname(dirname(_modpath))
27 def prefix(*args):
28 """Return a path relative to cola's installation prefix"""
29 return os.path.join(_prefix, *args)
32 def doc(*args):
33 """Return a path relative to cola's /usr/share/doc/ directory"""
34 return os.path.join(_prefix, 'share', 'doc', 'git-cola', *args)
37 def html_docs():
38 """Return the path to the cola html documentation."""
39 # html/index.html only exists after the install-docs target is run.
40 # Fallback to the source tree and lastly git-cola.rst.
41 paths_to_try = (('html', 'index.html'),
42 ('_build', 'html', 'index.html'))
43 for paths in paths_to_try:
44 docdir = doc(*paths)
45 if core.exists(docdir):
46 return docdir
47 return doc('git-cola.rst')
50 def show_html_docs():
51 url = html_docs()
52 webbrowser.open_new_tab('file://' + url)
54 def share(*args):
55 """Return a path relative to cola's /usr/share/ directory"""
56 return prefix('share', 'git-cola', *args)
59 def icon(basename):
60 """Return the full path to an icon file given a basename."""
61 return 'icons:'+basename
64 def icon_dir():
65 """Return the path to the style dir within the cola install tree."""
66 return share('icons')
69 def config_home(*args):
70 config = core.getenv('XDG_CONFIG_HOME',
71 os.path.join(core.expanduser('~'), '.config'))
72 return os.path.join(config, 'git-cola', *args)