|
Packit Service |
db4263 |
# vim:et sts=4 sw=4
|
|
Packit Service |
db4263 |
#
|
|
Packit Service |
db4263 |
# ibus-table - The Tables engine for IBus
|
|
Packit Service |
db4263 |
#
|
|
Packit Service |
db4263 |
# Copyright (c) 2015 Mike FABIAN <mfabian@redhat.com>
|
|
Packit Service |
db4263 |
#
|
|
Packit Service |
db4263 |
# This library is free software; you can redistribute it and/or
|
|
Packit Service |
db4263 |
# modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
db4263 |
# License as published by the Free Software Foundation; either
|
|
Packit Service |
db4263 |
# version 2.1 of the License, or (at your option) any later version.
|
|
Packit Service |
db4263 |
#
|
|
Packit Service |
db4263 |
# This library is distributed in the hope that it will be useful,
|
|
Packit Service |
db4263 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
db4263 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
db4263 |
# Lesser General Public License for more details.
|
|
Packit Service |
db4263 |
#
|
|
Packit Service |
db4263 |
# You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
db4263 |
# License along with this library; if not, write to the Free Software
|
|
Packit Service |
db4263 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
Packit Service |
db4263 |
#
|
|
Packit Service |
db4263 |
|
|
Packit Service |
db4263 |
'''
|
|
Packit Service |
db4263 |
Get locations where ibus-table stores stuff.
|
|
Packit Service |
db4263 |
|
|
Packit Service |
db4263 |
The directories used are according to the
|
|
Packit Service |
db4263 |
“XDG Base Directory Specification”,
|
|
Packit Service |
db4263 |
see: http://standards.freedesktop.org/basedir-spec/latest/index.html
|
|
Packit Service |
db4263 |
'''
|
|
Packit Service |
db4263 |
|
|
Packit Service |
db4263 |
import os
|
|
Packit Service |
db4263 |
|
|
Packit Service |
db4263 |
ibus_table_location = {
|
|
Packit Service |
db4263 |
'data': '',
|
|
Packit Service |
db4263 |
'lib': '',
|
|
Packit Service |
db4263 |
'data_home': '',
|
|
Packit Service |
db4263 |
'cache_home': '',
|
|
Packit Service |
db4263 |
}
|
|
Packit Service |
db4263 |
|
|
Packit Service |
db4263 |
def data():
|
|
Packit Service |
db4263 |
return ibus_table_location['data']
|
|
Packit Service |
db4263 |
|
|
Packit Service |
db4263 |
def lib():
|
|
Packit Service |
db4263 |
return ibus_table_location['lib']
|
|
Packit Service |
db4263 |
|
|
Packit Service |
db4263 |
def data_home():
|
|
Packit Service |
db4263 |
return ibus_table_location['data_home']
|
|
Packit Service |
db4263 |
|
|
Packit Service |
db4263 |
def cache_home():
|
|
Packit Service |
db4263 |
return ibus_table_location['cache_home']
|
|
Packit Service |
db4263 |
|
|
Packit Service |
db4263 |
def _init():
|
|
Packit Service |
db4263 |
ibus_table_location['data'] = os.getenv('IBUS_TABLE_LOCATION')
|
|
Packit Service |
db4263 |
if (not ibus_table_location['data']
|
|
Packit Service |
db4263 |
or not os.path.exists(ibus_table_location['data'])):
|
|
Packit Service |
db4263 |
ibus_table_location['data'] = "/usr/share/ibus-table/"
|
|
Packit Service |
db4263 |
|
|
Packit Service |
db4263 |
ibus_table_location['lib'] = os.getenv('IBUS_TABLE_LIB_LOCATION')
|
|
Packit Service |
db4263 |
if (not ibus_table_location['lib']
|
|
Packit Service |
db4263 |
or not os.path.exists(ibus_table_location['lib'])):
|
|
Packit Service |
db4263 |
ibus_table_location['lib'] = "/usr/libexec"
|
|
Packit Service |
db4263 |
|
|
Packit Service |
db4263 |
# $XDG_DATA_HOME defines the base directory relative to which user
|
|
Packit Service |
db4263 |
# specific data files should be stored. If $XDG_DATA_HOME is either
|
|
Packit Service |
db4263 |
# not set or empty, a default equal to $HOME/.local/share should be
|
|
Packit Service |
db4263 |
# used.
|
|
Packit Service |
db4263 |
ibus_table_location['data_home'] = os.getenv('IBUS_TABLE_DATA_HOME')
|
|
Packit Service |
db4263 |
if (not ibus_table_location['data_home']
|
|
Packit Service |
db4263 |
or not os.path.exists(ibus_table_location['data_home'])):
|
|
Packit Service |
db4263 |
ibus_table_location['data_home'] = os.getenv('XDG_DATA_HOME')
|
|
Packit Service |
db4263 |
if (not ibus_table_location['data_home']
|
|
Packit Service |
db4263 |
or not os.path.exists(ibus_table_location['data_home'])):
|
|
Packit Service |
db4263 |
ibus_table_location['data_home'] = os.path.expanduser('~/.local/share')
|
|
Packit Service |
db4263 |
ibus_table_location['data_home'] = os.path.join(
|
|
Packit Service |
db4263 |
ibus_table_location['data_home'], 'ibus-table')
|
|
Packit Service |
db4263 |
if not os.access(ibus_table_location['data_home'], os.F_OK):
|
|
Packit Service |
db4263 |
os.makedirs(ibus_table_location['data_home'])
|
|
Packit Service |
db4263 |
|
|
Packit Service |
db4263 |
# $XDG_CACHE_HOME defines the base directory relative to which user
|
|
Packit Service |
db4263 |
# specific non-essential data files should be stored. If
|
|
Packit Service |
db4263 |
# $XDG_CACHE_HOME is either not set or empty, a default equal to
|
|
Packit Service |
db4263 |
# $HOME/.cache should be used.
|
|
Packit Service |
db4263 |
ibus_table_location['cache_home'] = os.getenv('IBUS_TABLE_CACHE_HOME')
|
|
Packit Service |
db4263 |
if (not ibus_table_location['cache_home']
|
|
Packit Service |
db4263 |
or not os.path.exists(ibus_table_location['cache_home'])):
|
|
Packit Service |
db4263 |
ibus_table_location['cache_home'] = os.getenv('XDG_CACHE_HOME')
|
|
Packit Service |
db4263 |
if (not ibus_table_location['cache_home']
|
|
Packit Service |
db4263 |
or not os.path.exists(ibus_table_location['cache_home'])):
|
|
Packit Service |
db4263 |
ibus_table_location['cache_home'] = os.path.expanduser('~/.cache')
|
|
Packit Service |
db4263 |
ibus_table_location['cache_home'] = os.path.join(
|
|
Packit Service |
db4263 |
ibus_table_location['cache_home'], 'ibus-table')
|
|
Packit Service |
db4263 |
if not os.access(ibus_table_location['cache_home'], os.F_OK):
|
|
Packit Service |
db4263 |
os.makedirs(ibus_table_location['cache_home'])
|
|
Packit Service |
db4263 |
|
|
Packit Service |
db4263 |
class __ModuleInitializer:
|
|
Packit Service |
db4263 |
def __init__(self):
|
|
Packit Service |
db4263 |
_init()
|
|
Packit Service |
db4263 |
return
|
|
Packit Service |
db4263 |
|
|
Packit Service |
db4263 |
def __del__(self):
|
|
Packit Service |
db4263 |
return
|
|
Packit Service |
db4263 |
|
|
Packit Service |
db4263 |
__module_init = __ModuleInitializer()
|
|
Packit Service |
db4263 |
|