2014-01-25 23:13:56 +00:00
|
|
|
#!/usr/bin/python3
|
2013-07-12 17:56:24 +00:00
|
|
|
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
|
2014-01-25 23:13:56 +00:00
|
|
|
# Mugshot - Lightweight user configuration utility
|
2019-06-02 09:20:37 +00:00
|
|
|
# Copyright (C) 2013-2019 Sean Davis <sean@bluesabre.org>
|
2014-01-25 22:21:53 +00:00
|
|
|
#
|
2014-01-25 23:13:56 +00:00
|
|
|
# This program is free software: you can redistribute it and/or modify it
|
2014-07-28 00:07:47 +00:00
|
|
|
# under the terms of the GNU General Public License as published by
|
2014-08-24 16:14:29 +00:00
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
2014-07-28 00:07:47 +00:00
|
|
|
# (at your option) any later version.
|
2014-01-25 22:21:53 +00:00
|
|
|
#
|
2014-01-25 23:13:56 +00:00
|
|
|
# This program is distributed in the hope that it will be useful, but
|
|
|
|
# WITHOUT ANY WARRANTY; without even the implied warranties of
|
|
|
|
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
|
|
|
|
# PURPOSE. See the GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
2013-07-12 17:56:24 +00:00
|
|
|
|
2016-10-18 10:34:57 +00:00
|
|
|
import os
|
|
|
|
|
2013-07-12 17:56:24 +00:00
|
|
|
__all__ = [
|
|
|
|
'project_path_not_found',
|
|
|
|
'get_data_file',
|
|
|
|
'get_data_path',
|
2015-09-01 02:31:02 +00:00
|
|
|
]
|
2013-07-12 17:56:24 +00:00
|
|
|
|
|
|
|
# Where your project will look for your data (for instance, images and ui
|
|
|
|
# files). By default, this is ../data, relative your trunk layout
|
|
|
|
__mugshot_data_directory__ = '../data/'
|
2014-07-28 00:14:45 +00:00
|
|
|
__license__ = 'GPL-3+'
|
2019-07-28 18:49:17 +00:00
|
|
|
__version__ = '0.4.2'
|
2013-07-12 17:56:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
class project_path_not_found(Exception):
|
2015-09-01 02:31:02 +00:00
|
|
|
|
2013-07-12 17:56:24 +00:00
|
|
|
"""Raised when we can't find the project directory."""
|
|
|
|
|
|
|
|
|
|
|
|
def get_data_file(*path_segments):
|
|
|
|
"""Get the full path to a data file.
|
|
|
|
|
|
|
|
Returns the path to a file underneath the data directory (as defined by
|
|
|
|
`get_data_path`). Equivalent to os.path.join(get_data_path(),
|
|
|
|
*path_segments).
|
|
|
|
"""
|
|
|
|
return os.path.join(get_data_path(), *path_segments)
|
|
|
|
|
|
|
|
|
|
|
|
def get_data_path():
|
|
|
|
"""Retrieve mugshot data path
|
|
|
|
|
|
|
|
This path is by default <mugshot_lib_path>/../data/ in trunk
|
|
|
|
and /usr/share/mugshot in an installed version but this path
|
|
|
|
is specified at installation time.
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Get pathname absolute or relative.
|
|
|
|
path = os.path.join(
|
|
|
|
os.path.dirname(__file__), __mugshot_data_directory__)
|
|
|
|
|
|
|
|
abs_data_path = os.path.abspath(path)
|
|
|
|
if not os.path.exists(abs_data_path):
|
|
|
|
raise project_path_not_found
|
|
|
|
|
|
|
|
return abs_data_path
|
|
|
|
|
|
|
|
|
|
|
|
def get_version():
|
2014-01-25 22:21:53 +00:00
|
|
|
"""Return the program version."""
|
2013-07-12 17:56:24 +00:00
|
|
|
return __version__
|