1 """Provides the prefix() function for finding cola resources"""
2 from __future__
import division
, absolute_import
, unicode_literals
4 from os
.path
import dirname
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
)))
24 # this is the source tree
25 # __file__ = '$prefix/cola/__file__.py'
26 _prefix
= dirname(dirname(_modpath
))
30 """Return a path relative to cola's installation prefix"""
31 return os
.path
.join(_prefix
, *args
)
35 """Return a path relative to cola's /usr/share/doc/ directory"""
36 return os
.path
.join(_prefix
, 'share', 'doc', 'git-cola', *args
)
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
:
47 if core
.exists(docdir
):
49 return doc('git-cola.rst')
54 webbrowser
.open_new_tab('file://' + url
)
58 """Return a path relative to cola's /usr/share/ directory"""
59 return prefix('share', 'git-cola', *args
)
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.
76 if not theme
or theme
== _default_icon_theme
:
77 icons
= share('icons')
79 theme_dir
= share('icons', theme
)
80 if os
.path
.isabs(theme
) and os
.path
.isdir(theme
):
82 elif os
.path
.isdir(theme_dir
):
85 icons
= share('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
)