gnome-music.in 2.83 KB
Newer Older
Vadim Rutkovsky's avatar
Vadim Rutkovsky committed
1
#!/usr/bin/env python3
Guillaume Quintard's avatar
Guillaume Quintard committed
2

3 4 5 6 7
import sys
import signal
import os
import locale
import gettext
8 9

# Make sure we'll find the pygobject module, even in JHBuild
10
sys.path.insert(1, '@pyexecdir@')
11 12
# Make sure we'll find the gnomemusic module, even in JHBuild
sys.path.insert(1, '@pythondir@')
13

14
import argparse
15
import logging
16
import gi
17
from gi.repository import Gio
18 19
import gnomemusic

20
localedir = '@localedir@'
21 22 23
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')
24
    pkgdatadir = os.path.join(srcdir, 'data')
25 26
    libgd_libdir = os.path.join(srcdir, 'libgd', '.libs')
    libgd_typelibdir = os.path.join(srcdir, 'libgd')
27 28
    if not os.environ.get('GSETTINGS_SCHEMA_DIR'):
        os.environ['GSETTINGS_SCHEMA_DIR'] = pkgdatadir
29
else:
30
    pkgdatadir = '@pkgdatadir@'
31 32 33 34
    libgd_libdir = '@pkglibdir@'
    libgd_typelibdir = '@pkglibdir@/girepository-1.0'

# We use our own libgd.so, so let gi.repository find it
35
gi.require_version('GIRepository', '2.0')
36 37 38
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
39

40

41 42
def install_excepthook():
    """ Make sure we exit when an unhandled exception occurs. """
43
    gi.require_version('Gtk', '3.0')
44
    from gi.repository import Gtk
45
    old_hook = sys.excepthook
46

47 48 49 50 51 52 53
    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
54
if __name__ == "__main__":
55 56
    install_excepthook()

57 58 59 60
    parser = argparse.ArgumentParser()
    parser.add_argument('-d', "--debug", action="store_true", default=False, dest="debug")
    args = parser.parse_args()
    if args.debug:
61
        logging.basicConfig(level=logging.DEBUG,
62
                            format='%(asctime)s %(levelname)s\t%(message)s',
63 64 65 66 67 68 69
                            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:
70
        logging.basicConfig(level=logging.WARN,
71
                            format='%(asctime)s %(levelname)s\t%(message)s',
72
                            datefmt='%H:%M:%S')
73

Arnel A. Borja's avatar
Arnel A. Borja committed
74 75 76 77 78
    locale.bindtextdomain('gnome-music', localedir)
    locale.textdomain('gnome-music')
    gettext.bindtextdomain('gnome-music', localedir)
    gettext.textdomain('gnome-music')

79
    resource = Gio.resource_load(os.path.join(pkgdatadir, 'gnome-music.gresource'))
80 81
    Gio.Resource._register(resource)

82 83
    from gnomemusic.application import Application

84
    app = Application()
Vadim Rutkovsky's avatar
Vadim Rutkovsky committed
85
    signal.signal(signal.SIGINT, signal.SIG_DFL)
86 87
    exit_status = app.run(sys.argv)
    sys.exit(exit_status)