1 """Provides the prefix() function for finding cola resources"""
2 from __future__
import division
, absolute_import
, unicode_literals
6 from os
.path
import dirname
11 # Default git-cola icon theme
12 _default_icon_theme
= 'light'
14 _modpath
= core
.abspath(__file__
)
15 if os
.path
.join('share', 'git-cola', 'lib') in _modpath
:
16 # this is the release tree
17 # __file__ = '$prefix/share/git-cola/lib/cola/__file__.py'
18 _lib_dir
= dirname(dirname(_modpath
))
19 _prefix
= dirname(dirname(dirname(_lib_dir
)))
20 elif os
.path
.join('pkgs', 'cola') in _modpath
:
21 # Windows release tree
22 # __file__ = $installdir/pkgs/cola/resources.py
23 _prefix
= dirname(dirname(dirname(_modpath
)))
25 # this is the source tree
26 # __file__ = '$prefix/cola/__file__.py'
27 _prefix
= dirname(dirname(_modpath
))
31 """Return a path relative to cola's installation prefix"""
32 return os
.path
.join(_prefix
, *args
)
36 """Return a path relative to cola's /usr/share/doc/ directory"""
37 return os
.path
.join(_prefix
, 'share', 'doc', 'git-cola', *args
)
41 """Return the path to the cola html documentation."""
42 # html/index.html only exists after the install-docs target is run.
43 # Fallback to the source tree and lastly git-cola.rst.
44 paths_to_try
= (('html', 'index.html'),
45 ('_build', 'html', 'index.html'))
46 for paths
in paths_to_try
:
48 if core
.exists(docdir
):
50 return doc('git-cola.rst')
55 webbrowser
.open_new_tab('file://' + url
)
59 """Return a path relative to cola's /usr/share/ directory"""
60 return prefix('share', 'git-cola', *args
)
64 """Return the path to the icons directory
66 This typically returns share/git-cola/icons within
67 the git-cola installation prefix.
69 When theme is defined then it will return a subdirectory of the icons/
70 directory, e.g. "dark" for the dark icon theme.
72 When theme is set to an absolute directory path, that directory will be
73 returned, which effectively makes git-cola use those icons.
77 if not theme
or theme
== _default_icon_theme
:
78 icons
= share('icons')
80 theme_dir
= share('icons', theme
)
81 if os
.path
.isabs(theme
) and os
.path
.isdir(theme
):
83 elif os
.path
.isdir(theme_dir
):
86 icons
= share('icons')
91 def config_home(*args
):
92 config
= core
.getenv('XDG_CONFIG_HOME',
93 os
.path
.join(core
.expanduser('~'), '.config'))
94 return os
.path
.join(config
, 'git-cola', *args
)