~ubuntu-app-review-contributors/ubuntu-app-reviews/gtumbler

« back to all changes in this revision

Viewing changes to gtumbler_lib/gtumblerconfig.py

  • Committer: App Bot
  • Author(s): Gabriele N. Tornetta
  • Date: 2012-07-09 21:32:00 UTC
  • Revision ID: appbot@holba.ch-20120709213200-ezm1clcugzgrc7vq
Tags: 12.07.1
New release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
 
2
### BEGIN LICENSE
 
3
# Copyright (C) 2012 Gabriele N. Tornetta <phoenix1987@gmail.com>
 
4
# This program is free software: you can redistribute it and/or modify it 
 
5
# under the terms of the GNU General Public License version 3, as published 
 
6
# by the Free Software Foundation.
 
7
 
8
# This program is distributed in the hope that it will be useful, but 
 
9
# WITHOUT ANY WARRANTY; without even the implied warranties of 
 
10
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR 
 
11
# PURPOSE.  See the GNU General Public License for more details.
 
12
 
13
# You should have received a copy of the GNU General Public License along 
 
14
# with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
### END LICENSE
 
16
 
 
17
# THIS IS Gtumbler CONFIGURATION FILE
 
18
# YOU CAN PUT THERE SOME GLOBAL VALUE
 
19
# Do not touch unless you know what you're doing.
 
20
# you're warned :)
 
21
 
 
22
__all__ = [
 
23
    'project_path_not_found',
 
24
    'get_data_file',
 
25
    'get_data_path',
 
26
    ]
 
27
 
 
28
# Where your project will look for your data (for instance, images and ui
 
29
# files). By default, this is ../data, relative your trunk layout
 
30
__gtumbler_data_directory__ = '../data/'
 
31
__license__ = 'GPL-3'
 
32
__version__ = 'VERSION'
 
33
 
 
34
import os
 
35
 
 
36
import gettext
 
37
from gettext import gettext as _
 
38
gettext.textdomain('gtumbler')
 
39
 
 
40
class project_path_not_found(Exception):
 
41
    """Raised when we can't find the project directory."""
 
42
 
 
43
 
 
44
def get_data_file(*path_segments):
 
45
    """Get the full path to a data file.
 
46
 
 
47
    Returns the path to a file underneath the data directory (as defined by
 
48
    `get_data_path`). Equivalent to os.path.join(get_data_path(),
 
49
    *path_segments).
 
50
    """
 
51
    return os.path.join(get_data_path(), *path_segments)
 
52
 
 
53
 
 
54
def get_data_path():
 
55
    """Retrieve gtumbler data path
 
56
 
 
57
    This path is by default <gtumbler_lib_path>/../data/ in trunk
 
58
    and /usr/share/gtumbler in an installed version but this path
 
59
    is specified at installation time.
 
60
    """
 
61
 
 
62
    # Get pathname absolute or relative.
 
63
    path = os.path.join(
 
64
        os.path.dirname(__file__), __gtumbler_data_directory__)
 
65
 
 
66
    abs_data_path = os.path.abspath(path)
 
67
    if not os.path.exists(abs_data_path):
 
68
        raise project_path_not_found
 
69
 
 
70
    return abs_data_path
 
71
 
 
72
 
 
73
def get_version():
 
74
    return __version__