models.main: Add a serialilzer to run generate_remote_helpers()
[git-cola.git] / cola / resources.py
blob4cd5fe9354857fc4c23152528578a675f551decb
1 """Provides the prefix() function for finding cola resources"""
2 import os
3 import glob
5 _modpath = os.path.abspath(__file__)
6 if 'share' in __file__ and 'lib' in __file__:
7 # this is the release tree
8 # __file__ = '$prefix/share/git-cola/lib/cola/__file__.py'
9 _lib_dir = os.path.dirname(os.path.dirname(_modpath))
10 _prefix = os.path.dirname(os.path.dirname(os.path.dirname(_lib_dir)))
11 else:
12 # this is the source tree
13 # __file__ = '$prefix/cola/__file__.py'
14 _prefix = os.path.dirname(os.path.dirname(_modpath))
17 def prefix(*args):
18 """Return a path relative to cola's installation prefix"""
19 return os.path.join(_prefix, *args)
22 def doc(*args):
23 """Return a path relative to cola's /usr/share/doc/ directory"""
24 return os.path.join(_prefix, 'share', 'doc', 'git-cola', *args)
27 def html_docs():
28 """Return the path to the cola html documentation."""
29 # index.html only exists after the install-docs target is run,
30 # so fallback to git-cola.txt.
31 htmldocs = doc('html', 'index.html')
32 if os.path.exists(htmldocs):
33 return htmldocs
34 return doc('git-cola.txt')
37 def share(*args):
38 """Return a path relative to cola's /usr/share/ directory"""
39 return prefix('share', 'git-cola', *args)
42 def icon(basename):
43 """Return the full path to an icon file given a basename."""
44 return share('icons', basename)
47 def stylesheet(name):
48 """Return a path relative to cola's /usr/share/../styles directory"""
49 stylesheet = share('styles', name + '.qss')
50 if os.path.exists(stylesheet):
51 return stylesheet
52 else:
53 return None
56 def style_dir():
57 """Return the path to the style dir within the cola install tree."""
58 return share('styles')
61 def resource_dirs(path):
62 """Returns directories beneath a specific path"""
63 return [p for p in glob.glob(os.path.join(path, '*')) if os.path.isdir(p)]