# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- ### BEGIN LICENSE # Copyright (C) 2019, Wolf Vollprecht # This program is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License version 3, as published # by the Free Software Foundation. # # 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 . ### END LICENSE ### DO NOT EDIT THIS FILE ### __all__ = [ 'project_path_not_found', 'get_data_file', 'get_data_path', ] # Where your project will look for your data (for instance, images and ui # files). By default, this is ../data, relative your trunk layout __apostrophe_data_directory__ = '../data/' __license__ = 'GPL-3' __version__ = 'VERSION' import os class ProjectPathNotFound(Exception): """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 apostrophe data path This path is by default /../data/ in trunk and /opt/apostrophe/data in an installed version but this path is specified at installation time. """ # Get pathname absolute or relative. if os.path.isfile("/.flatpak-info"): return '/app/share/apostrophe/' path = os.path.join( os.path.dirname(__file__), __apostrophe_data_directory__) # We try first if the data exists in the local folder and then # in the system installation path abs_data_path = os.path.abspath(path) if not os.path.exists(abs_data_path): abs_data_path = '/usr/share/apostrophe/' elif not os.path.exists(abs_data_path): raise ProjectPathNotFound return abs_data_path def get_version(): return __version__