models.main: Do not return cached values in everything()
[git-cola.git] / cola / resources.py
blobcd25f76a2e560a647a2fe613a737a6c44b0c5128
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))
16 def prefix(*args):
17 """Returns a path relative to cola's installation prefix"""
18 return os.path.join(_prefix, *args)
20 def doc(*args):
21 """Returns a path relative to cola's /usr/share/doc/ directory"""
22 return os.path.join(_prefix, 'share', 'doc', 'git-cola', *args)
24 def html_docs():
25 """Returns the path to the cola html documentation."""
26 return doc('git-cola.html')
28 def share(*args):
29 """Returns a path relative to cola's /usr/share/ directory"""
30 return prefix('share', 'git-cola', *args)
32 def icon(basename):
33 """Returns the full path to an icon file given a basename."""
34 return share('icons', basename)
36 def qm(name):
37 """Returns the path to a qm file given its name"""
38 return share('qm', name + '.qm')
40 def stylesheet(name):
41 """Returns a path relative to cola's /usr/share/../styles directory"""
42 stylesheet = share('styles', name + '.qss')
43 if os.path.exists(stylesheet):
44 return stylesheet
45 else:
46 return None
48 def style_dir():
49 """Returns the path to the style dir within the cola install tree."""
50 return share('styles')
52 def resource_dirs(path):
53 """Returns directories beneath a specific path"""
54 return [p for p in glob.glob(os.path.join(path, '*')) if os.path.isdir(p)]