~jblount/+junk/grumble

« back to all changes in this revision

Viewing changes to grumble/grumbleconfig.py

  • Committer: joshua at canonical
  • Date: 2010-04-07 19:35:56 UTC
  • Revision ID: joshua@canonical.com-20100407193556-d5r8kq2k4c2qljd6
Initial project creation with Quickly!

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
### BEGIN LICENSE
 
3
# This file is in the public domain
 
4
### END LICENSE
 
5
 
 
6
# THIS IS Grumble CONFIGURATION FILE
 
7
# YOU CAN PUT THERE SOME GLOBAL VALUE
 
8
# Do not touch unless you know what you're doing.
 
9
# you're warned :)
 
10
 
 
11
__all__ = [
 
12
    'project_path_not_found',
 
13
    'get_data_file',
 
14
    'get_data_path',
 
15
    ]
 
16
 
 
17
# Where your project will look for your data (for instance, images and ui
 
18
# files). By default, this is ../data, relative your trunk layout
 
19
__grumble_data_directory__ = '../data/'
 
20
__license__ = ''
 
21
 
 
22
import os
 
23
 
 
24
import gettext
 
25
from gettext import gettext as _
 
26
gettext.textdomain('grumble')
 
27
 
 
28
class project_path_not_found(Exception):
 
29
    """Raised when we can't find the project directory."""
 
30
 
 
31
 
 
32
def get_data_file(*path_segments):
 
33
    """Get the full path to a data file.
 
34
 
 
35
    Returns the path to a file underneath the data directory (as defined by
 
36
    `get_data_path`). Equivalent to os.path.join(get_data_path(),
 
37
    *path_segments).
 
38
    """
 
39
    return os.path.join(get_data_path(), *path_segments)
 
40
 
 
41
 
 
42
def get_data_path():
 
43
    """Retrieve grumble data path
 
44
 
 
45
    This path is by default <grumble_lib_path>/../data/ in trunk
 
46
    and /usr/share/grumble in an installed version but this path
 
47
    is specified at installation time.
 
48
    """
 
49
 
 
50
    # Get pathname absolute or relative.
 
51
    path = os.path.join(
 
52
        os.path.dirname(__file__), __grumble_data_directory__)
 
53
 
 
54
    abs_data_path = os.path.abspath(path)
 
55
    if not os.path.exists(abs_data_path):
 
56
        raise project_path_not_found
 
57
 
 
58
    return abs_data_path