-
Notifications
You must be signed in to change notification settings - Fork 13
/
gnome-music.in
84 lines (70 loc) · 2.8 KB
/
gnome-music.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python3
import sys
import signal
import os
import locale
import gettext
# Make sure we'll find the pygobject module, even in JHBuild
sys.path.insert(1, '@pyexecdir@')
# Make sure we'll find the gnomemusic module, even in JHBuild
sys.path.insert(1, '@pythondir@')
from optparse import OptionParser
import logging
from gi.repository import Gio
import gnomemusic
localedir = '@localedir@'
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')
pkgdatadir = os.path.join(srcdir, 'data')
libgd_libdir = os.path.join(srcdir, 'libgd', '.libs')
libgd_typelibdir = os.path.join(srcdir, 'libgd')
if not os.environ.get('GSETTINGS_SCHEMA_DIR'):
os.environ['GSETTINGS_SCHEMA_DIR'] = pkgdatadir
else:
pkgdatadir = '@pkgdatadir@'
libgd_libdir = '@pkglibdir@'
libgd_typelibdir = '@pkglibdir@/girepository-1.0'
# We use our own libgd.so, so let gi.repository find it
from gi.repository import GIRepository
GIRepository.Repository.prepend_search_path(libgd_typelibdir)
GIRepository.Repository.prepend_library_path(libgd_libdir)
from gnomemusic.application import Application
def install_excepthook():
""" Make sure we exit when an unhandled exception occurs. """
from gi.repository import Gtk
old_hook = sys.excepthook
def new_hook(etype, evalue, etb):
old_hook(etype, evalue, etb)
while Gtk.main_level():
Gtk.main_quit()
sys.exit()
sys.excepthook = new_hook
if __name__ == "__main__":
install_excepthook()
parser = OptionParser()
parser.add_option('-d', "--debug", action="store_true", default=False, dest="debug")
opts, args = parser.parse_args()
if opts.debug:
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(levelname)s\t%(filename)s:%(lineno)d \t%(message)s',
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:
logging.basicConfig(level=logging.WARN,
format='%(asctime)s %(levelname)s\t%(filename)s:%(lineno)d \t%(message)s',
datefmt='%H:%M:%S')
locale.bindtextdomain('gnome-music', localedir)
locale.textdomain('gnome-music')
gettext.bindtextdomain('gnome-music', localedir)
gettext.textdomain('gnome-music')
resource = Gio.resource_load(os.path.join(pkgdatadir, 'gnome-music.gresource'))
Gio.Resource._register(resource)
app = Application()
signal.signal(signal.SIGINT, signal.SIG_DFL)
exit_status = app.run(sys.argv)
sys.exit(exit_status)