Blame gio/gdbus-2.0/codegen/gdbus-codegen.in

Packit 84794d
#!/usr/bin/env @PYTHON@
Packit 84794d
Packit 84794d
# GDBus - GLib D-Bus Library
Packit 84794d
#
Packit 84794d
# Copyright (C) 2008-2011 Red Hat, Inc.
Packit 84794d
#
Packit 84794d
# This library is free software; you can redistribute it and/or
Packit 84794d
# modify it under the terms of the GNU Lesser General Public
Packit 84794d
# License as published by the Free Software Foundation; either
Packit 84794d
# version 2.1 of the License, or (at your option) any later version.
Packit 84794d
#
Packit 84794d
# This library is distributed in the hope that it will be useful,
Packit 84794d
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 84794d
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 84794d
# Lesser General Public License for more details.
Packit 84794d
#
Packit 84794d
# You should have received a copy of the GNU Lesser General
Packit 84794d
# Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
Packit 84794d
#
Packit 84794d
# Author: David Zeuthen <davidz@redhat.com>
Packit 84794d
Packit 84794d
Packit 84794d
import os
Packit 84794d
import sys
Packit 84794d
Packit 84794d
srcdir = os.getenv('UNINSTALLED_GLIB_SRCDIR', None)
Packit 84794d
filedir = os.path.dirname(__file__)
Packit 84794d
Packit 84794d
if srcdir is not None:
Packit 84794d
    path = os.path.join(srcdir, 'gio', 'gdbus-2.0')
Packit 84794d
elif os.path.basename(filedir) == 'bin':
Packit 84794d
    # Make the prefix containing gdbus-codegen 'relocatable' at runtime by
Packit 84794d
    # adding /some/prefix/bin/../share/glib-2.0 to the python path
Packit 84794d
    path = os.path.join(filedir, '..', 'share', 'glib-2.0')
Packit 84794d
else:
Packit 84794d
    # Assume that the modules we need are in the current directory and add the
Packit 84794d
    # parent directory to the python path.
Packit 84794d
    path = os.path.join(filedir, '..')
Packit 84794d
Packit 84794d
# Canonicalize, then do further testing
Packit 84794d
path = os.path.abspath(path)
Packit 84794d
Packit 84794d
# If the above path detection failed, use the hard-coded datadir. This can
Packit 84794d
# happen when, for instance, bindir and datadir are not in the same prefix or
Packit 84794d
# on Windows where we cannot make any guarantees about the directory structure.
Packit 84794d
#
Packit 84794d
# In these cases our installation cannot be relocatable, but at least we should
Packit 84794d
# be able to find the codegen module.
Packit 84794d
if not os.path.isfile(os.path.join(path, 'codegen', 'codegen_main.py')):
Packit 84794d
    path = os.path.join('@DATADIR@', 'glib-2.0')
Packit 84794d
Packit 84794d
sys.path.insert(0, path)
Packit 84794d
from codegen import codegen_main
Packit 84794d
Packit 84794d
sys.exit(codegen_main.codegen_main())