1 """Provides the prefix() function for finding cola resources"""
2 from __future__
import division
, absolute_import
, unicode_literals
4 from os
.path
import dirname
11 # Default git-cola icon theme
12 _default_icon_theme
= 'light'
14 _modpath
= core
.abspath(core
.realpath(__file__
))
16 os
.path
.join('share', 'git-cola', 'lib') in _modpath
17 or os
.path
.join('site-packages', 'cola') in _modpath
19 # this is the release tree
20 # __file__ = '$prefix/share/git-cola/lib/cola/__file__.py'
21 _lib_dir
= dirname(dirname(_modpath
))
22 _prefix
= dirname(dirname(dirname(_lib_dir
)))
23 elif os
.path
.join('pkgs', 'cola') in _modpath
:
24 # Windows release tree
25 # __file__ = $installdir/pkgs/cola/resources.py
26 _prefix
= dirname(dirname(dirname(_modpath
)))
28 # this is the source tree
29 # __file__ = '$prefix/cola/__file__.py'
30 _prefix
= dirname(dirname(_modpath
))
34 """Return a path relative to cola's installation prefix"""
35 return os
.path
.join(_prefix
, *args
)
39 """Return a command sibling to the main program"""
40 bindir
= os
.path
.dirname(sys
.argv
[0])
41 return os
.path
.join(bindir
, name
)
45 """Return a path relative to cola's /usr/share/doc/ directory"""
46 return os
.path
.join(_prefix
, 'share', 'doc', 'git-cola', *args
)
50 """Return the path to the cola html documentation."""
51 # html/index.html only exists after the install-docs target is run.
52 # Fallback to the source tree and lastly git-cola.rst.
53 paths_to_try
= (('html', 'index.html'), ('_build', 'html', 'index.html'))
54 for paths
in paths_to_try
:
56 if core
.exists(docdir
):
58 return doc('git-cola.rst')
63 webbrowser
.open_new_tab('file://' + url
)
67 """Return a path relative to cola's /usr/share/ directory"""
68 return prefix('share', 'git-cola', *args
)
72 """Return the path to the icons directory
74 This typically returns share/git-cola/icons within
75 the git-cola installation prefix.
77 When theme is defined then it will return a subdirectory of the icons/
78 directory, e.g. "dark" for the dark icon theme.
80 When theme is set to an absolute directory path, that directory will be
81 returned, which effectively makes git-cola use those icons.
85 if not theme
or theme
== _default_icon_theme
:
86 icons
= share('icons')
88 theme_dir
= share('icons', theme
)
89 if os
.path
.isabs(theme
) and os
.path
.isdir(theme
):
91 elif os
.path
.isdir(theme_dir
):
94 icons
= share('icons')
99 def config_home(*args
):
100 config
= core
.getenv(
101 'XDG_CONFIG_HOME', os
.path
.join(core
.expanduser('~'), '.config')
103 return os
.path
.join(config
, 'git-cola', *args
)