gnome-music.in 4.04 KB
Newer Older
Vadim Rutkovsky's avatar
Vadim Rutkovsky committed
1
#!/usr/bin/env python3
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
# Copyright (c) 2016 The GNOME Music Developers
#
# GNOME Music is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# GNOME Music is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY 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 GNOME Music; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# The GNOME Music authors hereby grant permission for non-GPL compatible
# GStreamer plugins to be used and distributed together with GStreamer
# and GNOME Music.  This permission is above and beyond the permissions
# granted by the GPL license by which GNOME Music is covered.  If you
# modify this code, you may extend this exception to your version of the
# code, but you are not obligated to do so.  If you do not wish to do so,
# delete this exception statement from your version.
Guillaume Quintard's avatar
Guillaume Quintard committed
25

26 27 28 29 30
import sys
import signal
import os
import locale
import gettext
31 32

# Make sure we'll find the pygobject module, even in JHBuild
33
sys.path.insert(1, '@pyexecdir@')
34 35
# Make sure we'll find the gnomemusic module, even in JHBuild
sys.path.insert(1, '@pythondir@')
36

37
import argparse
38
import logging
39
import gi
40
from gi.repository import Gio
41 42
import gnomemusic

43
localedir = '@localedir@'
44 45 46
srcdir = os.path.abspath(os.path.join(os.path.dirname(gnomemusic.__file__), '..'))
if os.path.exists(os.path.join(srcdir, 'gnome-music.doap')):
    print('Running from source tree, using local files')
47
    pkgdatadir = os.path.join(srcdir, 'data')
48 49
    libgd_libdir = os.path.join(srcdir, 'libgd', '.libs')
    libgd_typelibdir = os.path.join(srcdir, 'libgd')
50 51
    if not os.environ.get('GSETTINGS_SCHEMA_DIR'):
        os.environ['GSETTINGS_SCHEMA_DIR'] = pkgdatadir
52
else:
53
    pkgdatadir = '@pkgdatadir@'
54 55 56 57
    libgd_libdir = '@pkglibdir@'
    libgd_typelibdir = '@pkglibdir@/girepository-1.0'

# We use our own libgd.so, so let gi.repository find it
58
gi.require_version('GIRepository', '2.0')
59 60 61
from gi.repository import GIRepository
GIRepository.Repository.prepend_search_path(libgd_typelibdir)
GIRepository.Repository.prepend_library_path(libgd_libdir)
Guillaume Quintard's avatar
Guillaume Quintard committed
62

63

64 65
def install_excepthook():
    """ Make sure we exit when an unhandled exception occurs. """
66
    gi.require_version('Gtk', '3.0')
67
    from gi.repository import Gtk
68
    old_hook = sys.excepthook
69

70 71 72 73 74 75 76
    def new_hook(etype, evalue, etb):
        old_hook(etype, evalue, etb)
        while Gtk.main_level():
            Gtk.main_quit()
        sys.exit()
    sys.excepthook = new_hook

Guillaume Quintard's avatar
Guillaume Quintard committed
77
if __name__ == "__main__":
78 79
    install_excepthook()

80 81 82 83
    parser = argparse.ArgumentParser()
    parser.add_argument('-d', "--debug", action="store_true", default=False, dest="debug")
    args = parser.parse_args()
    if args.debug:
84
        logging.basicConfig(level=logging.DEBUG,
85
                            format='%(asctime)s %(levelname)s\t%(message)s',
86 87 88 89 90 91 92
                            datefmt='%H:%M:%S')
        # Gtk hates "-d" switch, so lets drop it
        if '-d' in sys.argv:
            sys.argv.remove("-d")
        if '--debug' in sys.argv:
            sys.argv.remove("--debug")
    else:
93
        logging.basicConfig(level=logging.WARN,
94
                            format='%(asctime)s %(levelname)s\t%(message)s',
95
                            datefmt='%H:%M:%S')
96

Arnel A. Borja's avatar
Arnel A. Borja committed
97 98 99 100 101
    locale.bindtextdomain('gnome-music', localedir)
    locale.textdomain('gnome-music')
    gettext.bindtextdomain('gnome-music', localedir)
    gettext.textdomain('gnome-music')

102
    resource = Gio.resource_load(os.path.join(pkgdatadir, 'gnome-music.gresource'))
103 104
    Gio.Resource._register(resource)

105 106
    from gnomemusic.application import Application

107
    app = Application()
Vadim Rutkovsky's avatar
Vadim Rutkovsky committed
108
    signal.signal(signal.SIGINT, signal.SIG_DFL)
109 110
    exit_status = app.run(sys.argv)
    sys.exit(exit_status)