~naingyeminn/my-fs-cli/quickly_trunk

« back to all changes in this revision

Viewing changes to my_fs_cli/my_fs_cliconfig.py

  • Committer: Naing Ye Minn
  • Date: 2012-07-01 19:10:21 UTC
  • Revision ID: naingyeminn@gmail.com-20120701191021-q81xjk6w26v7p73y
FirstĀ UploadĀ (Alpha)

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 Naing Ye Minn <naingyeminn@gmail.com>
 
4
# Permission is hereby granted, free of charge, to any person obtaining a copy
 
5
# of this software and associated documentation files (the "Software"), to deal
 
6
# in the Software without restriction, including without limitation the rights
 
7
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
8
# copies of the Software, and to permit persons to whom the Software is
 
9
# furnished to do so, subject to the following conditions:
 
10
 
11
# The above copyright notice and this permission notice shall be included in
 
12
# all copies or substantial portions of the Software.
 
13
 
14
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
15
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
16
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
17
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
18
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
19
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 
20
# THE SOFTWARE.
 
21
### END LICENSE
 
22
 
 
23
# THIS IS MyFsCli CONFIGURATION FILE
 
24
# YOU CAN PUT THERE SOME GLOBAL VALUE
 
25
# Do not touch unless you know what you're doing.
 
26
# you're warned :)
 
27
 
 
28
__all__ = [
 
29
    'project_path_not_found',
 
30
    'get_data_file',
 
31
    'get_data_path',
 
32
    ]
 
33
 
 
34
# Where your project will look for your data (for instance, images and ui
 
35
# files). By default, this is ../data, relative your trunk layout
 
36
__my_fs_cli_data_directory__ = '../data/'
 
37
__license__ = 'MIT'
 
38
__version__ = 'VERSION'
 
39
 
 
40
import os
 
41
 
 
42
import gettext
 
43
from gettext import gettext as _
 
44
gettext.textdomain('my-fs-cli')
 
45
 
 
46
class project_path_not_found(Exception):
 
47
    """Raised when we can't find the project directory."""
 
48
 
 
49
 
 
50
def get_data_file(*path_segments):
 
51
    """Get the full path to a data file.
 
52
 
 
53
    Returns the path to a file underneath the data directory (as defined by
 
54
    `get_data_path`). Equivalent to os.path.join(get_data_path(),
 
55
    *path_segments).
 
56
    """
 
57
    return os.path.join(get_data_path(), *path_segments)
 
58
 
 
59
 
 
60
def get_data_path():
 
61
    """Retrieve my-fs-cli data path
 
62
 
 
63
    This path is by default <my_fs_cli_lib_path>/../data/ in trunk
 
64
    and /usr/share/my-fs-cli in an installed version but this path
 
65
    is specified at installation time.
 
66
    """
 
67
 
 
68
    # Get pathname absolute or relative.
 
69
    path = os.path.join(
 
70
        os.path.dirname(__file__), __my_fs_cli_data_directory__)
 
71
 
 
72
    abs_data_path = os.path.abspath(path)
 
73
    if not os.path.exists(abs_data_path):
 
74
        raise project_path_not_found
 
75
 
 
76
    return abs_data_path