doc: update v3.3 release notes draft
[git-cola.git] / cola / resources.py
blobfe98df5d0e36d5ad6690fa81ab84b46dc56ca4a4
1 """Provides the prefix() function for finding cola resources"""
2 from __future__ import division, absolute_import, unicode_literals
3 import os
4 from os.path import dirname
5 import webbrowser
7 from . import core
10 # Default git-cola icon theme
11 _default_icon_theme = 'light'
13 _modpath = core.abspath(__file__)
14 if os.path.join('share', 'git-cola', 'lib') in _modpath:
15 # this is the release tree
16 # __file__ = '$prefix/share/git-cola/lib/cola/__file__.py'
17 _lib_dir = dirname(dirname(_modpath))
18 _prefix = dirname(dirname(dirname(_lib_dir)))
19 elif os.path.join('pkgs', 'cola') in _modpath:
20 # Windows release tree
21 # __file__ = $installdir/pkgs/cola/resources.py
22 _prefix = dirname(dirname(dirname(_modpath)))
23 else:
24 # this is the source tree
25 # __file__ = '$prefix/cola/__file__.py'
26 _prefix = dirname(dirname(_modpath))
29 def prefix(*args):
30 """Return a path relative to cola's installation prefix"""
31 return os.path.join(_prefix, *args)
34 def doc(*args):
35 """Return a path relative to cola's /usr/share/doc/ directory"""
36 return os.path.join(_prefix, 'share', 'doc', 'git-cola', *args)
39 def html_docs():
40 """Return the path to the cola html documentation."""
41 # html/index.html only exists after the install-docs target is run.
42 # Fallback to the source tree and lastly git-cola.rst.
43 paths_to_try = (('html', 'index.html'),
44 ('_build', 'html', 'index.html'))
45 for paths in paths_to_try:
46 docdir = doc(*paths)
47 if core.exists(docdir):
48 return docdir
49 return doc('git-cola.rst')
52 def show_html_docs():
53 url = html_docs()
54 webbrowser.open_new_tab('file://' + url)
57 def share(*args):
58 """Return a path relative to cola's /usr/share/ directory"""
59 return prefix('share', 'git-cola', *args)
62 def icon_dir(theme):
63 """Return the path to the icons directory
65 This typically returns share/git-cola/icons within
66 the git-cola installation prefix.
68 When theme is defined then it will return a subdirectory of the icons/
69 directory, e.g. "dark" for the dark icon theme.
71 When theme is set to an absolute directory path, that directory will be
72 returned, which effectively makes git-cola use those icons.
74 """
76 if not theme or theme == _default_icon_theme:
77 icons = share('icons')
78 else:
79 theme_dir = share('icons', theme)
80 if os.path.isabs(theme) and os.path.isdir(theme):
81 icons = theme
82 elif os.path.isdir(theme_dir):
83 icons = theme_dir
84 else:
85 icons = share('icons')
87 return icons
90 def config_home(*args):
91 config = core.getenv('XDG_CONFIG_HOME',
92 os.path.join(core.expanduser('~'), '.config'))
93 return os.path.join(config, 'git-cola', *args)