~dholbach/ubuntu-app-reviews/xkcd-browser

« back to all changes in this revision

Viewing changes to xkcd_browser_lib/xkcd_browserconfig.py

  • Committer: brianrobles204 at gmail
  • Date: 2012-06-08 13:45:01 UTC
  • Revision ID: brianrobles204@gmail.com-20120608134501-d7mtub9mz12hy8gs
first version of the app

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
# This file is in the public domain
 
4
### END LICENSE
 
5
 
 
6
# THIS IS XkcdBrowser 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
__xkcd_browser_data_directory__ = '../data/'
 
20
__license__ = ''
 
21
__version__ = 'VERSION'
 
22
 
 
23
import os
 
24
 
 
25
import gettext
 
26
from gettext import gettext as _
 
27
gettext.textdomain('xkcd-browser')
 
28
 
 
29
class project_path_not_found(Exception):
 
30
    """Raised when we can't find the project directory."""
 
31
 
 
32
 
 
33
def get_data_file(*path_segments):
 
34
    """Get the full path to a data file.
 
35
 
 
36
    Returns the path to a file underneath the data directory (as defined by
 
37
    `get_data_path`). Equivalent to os.path.join(get_data_path(),
 
38
    *path_segments).
 
39
    """
 
40
    return os.path.join(get_data_path(), *path_segments)
 
41
 
 
42
 
 
43
def get_data_path():
 
44
    """Retrieve xkcd-browser data path
 
45
 
 
46
    This path is by default <xkcd_browser_lib_path>/../data/ in trunk
 
47
    and /usr/share/xkcd-browser in an installed version but this path
 
48
    is specified at installation time.
 
49
    """
 
50
 
 
51
    # Get pathname absolute or relative.
 
52
    path = os.path.join(
 
53
        os.path.dirname(__file__), __xkcd_browser_data_directory__)
 
54
 
 
55
    abs_data_path = os.path.abspath(path)
 
56
    if not os.path.exists(abs_data_path):
 
57
        raise project_path_not_found
 
58
 
 
59
    return abs_data_path
 
60
 
 
61
 
 
62
def get_version():
 
63
    return __version__