[gnome-music] Implement a simple logging for the application
- From: Vadim Rutkovsky <vrutkovsky src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music] Implement a simple logging for the application
- Date: Tue, 1 Apr 2014 13:03:44 +0000 (UTC)
commit 57bc174aec61202ff11651d5936949d6a15794b0
Author: Vadim Rutkovsky <vrutkovs redhat com>
Date: Tue Apr 1 13:28:24 2014 +0200
Implement a simple logging for the application
gnome-music.in | 29 ++++++++++++++++++++++++++---
gnomemusic/application.py | 10 ++++++++++
2 files changed, 36 insertions(+), 3 deletions(-)
---
diff --git a/gnome-music.in b/gnome-music.in
index 0e9b5f4..ea51e7d 100644
--- a/gnome-music.in
+++ b/gnome-music.in
@@ -1,16 +1,22 @@
#!/usr/bin/env python3
-import sys, signal, os, locale, gettext
+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 gi.repository import Gio, Gtk
+from optparse import OptionParser
+import logging
+from gi.repository import Gio
import gnomemusic
-localedir='@localedir@'
+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')
@@ -31,10 +37,12 @@ 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():
@@ -45,6 +53,21 @@ def install_excepthook():
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)
+
locale.bindtextdomain('gnome-music', localedir)
locale.textdomain('gnome-music')
gettext.bindtextdomain('gnome-music', localedir)
diff --git a/gnomemusic/application.py b/gnomemusic/application.py
index 9ddf1f4..146feed 100644
--- a/gnomemusic/application.py
+++ b/gnomemusic/application.py
@@ -36,10 +36,12 @@ from gettext import gettext as _
from gnomemusic.window import Window
from gnomemusic.mpris import MediaPlayer2Service
from gnomemusic.notification import NotificationManager
+import logging
class Application(Gtk.Application):
def __init__(self):
+ logging.debug("Creating app")
Gtk.Application.__init__(self,
application_id='org.gnome.Music',
flags=Gio.ApplicationFlags.FLAGS_NONE)
@@ -56,6 +58,7 @@ class Application(Gtk.Application):
self._window = None
def build_app_menu(self):
+ logging.debug("building app menu")
builder = Gtk.Builder()
builder.add_from_resource('/org/gnome/Music/app-menu.ui')
@@ -80,12 +83,15 @@ class Application(Gtk.Application):
self.add_action(quitAction)
def new_playlist(self, action, param):
+ logging.debug("TODO: New playlist action")
pass
def help(self, action, param):
+ logging.debug("Open Help action")
Gtk.show_uri(None, "help:gnome-music", Gdk.CURRENT_TIME)
def about(self, action, param):
+ logging.debug("About action")
builder = Gtk.Builder()
builder.add_from_resource('/org/gnome/Music/AboutDialog.ui')
about = builder.get_object('about_dialog')
@@ -94,9 +100,11 @@ class Application(Gtk.Application):
about.show()
def about_response(self, dialog, response):
+ logging.debug("Close about")
dialog.destroy()
def do_startup(self):
+ logging.debug("app is starting up")
Gtk.Application.do_startup(self)
Notify.init(_("Music"))
@@ -104,9 +112,11 @@ class Application(Gtk.Application):
self.build_app_menu()
def quit(self, action=None, param=None):
+ logging.debug("Help action")
self._window.destroy()
def do_activate(self):
+ logging.debug("App is activated")
if not self._window:
self._window = Window(self)
self.service = MediaPlayer2Service(self)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]