-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgnome-news.in
91 lines (79 loc) · 2.74 KB
/
gnome-news.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
85
86
87
88
89
90
91
#!/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 gnomenews module, even in JHBuild
sys.path.insert(1, "@pythondir@")
import argparse
import logging
try:
import gi
except ImportError:
sys.exit("Missing pygobject")
try:
gi.require_version('GLib', '2.0')
gi.require_version('Gio', '2.0')
gi.require_version('GObject', '2.0')
gi.require_version('Gtk', '3.0')
gi.require_version('Gdk', '3.0')
gi.require_version('Tracker', '1.0')
gi.require_version('WebKit2', '4.0')
except ValueError as e:
sys.exit("Missing dependency: {}".format(e))
from gi.repository import Gio
import gnomenews
localedir = "@localedir@"
srcdir = os.path.abspath(os.path.join(os.path.dirname(gnomenews.__file__), ".."))
if os.path.exists(os.path.join(srcdir, "gnome-news.doap")):
print("Running from source tree, using local files")
pkgdatadir = os.path.join(srcdir, "data")
if not os.environ.get("GSETTINGS_SCHEMA_DIR"):
os.environ["GSETTINGS_SCHEMA_DIR"] = pkgdatadir
else:
pkgdatadir = "@pkgdatadir@"
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 = argparse.ArgumentParser()
parser.add_argument("-d", "--debug", action="store_true", default=False, dest="debug")
args = parser.parse_args()
if args.debug:
logging.basicConfig(
level=logging.DEBUG,
format="%(asctime)s %(levelname)s\t%(message)s",
datefmt="%H:%M:%S")
os.environ["TRACKER_VERBOSITY"] = "3"
# 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%(message)s",
datefmt="%H:%M:%S")
locale.bindtextdomain("gnome-news", localedir)
locale.textdomain("gnome-news")
gettext.bindtextdomain("gnome-news", localedir)
gettext.textdomain("gnome-news")
resource = Gio.resource_load(os.path.join(pkgdatadir, "gnome-news.gresource"))
Gio.Resource._register(resource)
from gnomenews.application import Application
app = Application()
signal.signal(signal.SIGINT, signal.SIG_DFL)
exit_status = app.run(sys.argv)
sys.exit(exit_status)