[gedit-latex] Logging cleanups



commit 6bb484986528d46a7e79c8b01ef01be82a3e0d3c
Author: John Stowers <john stowers gmail com>
Date:   Sun Sep 11 13:06:48 2011 +1200

    Logging cleanups

 latex/bibtex/completion.py  |    8 ++++----
 latex/bibtex/parser.py      |   10 ----------
 latex/latex/views.py        |   20 +++++++-------------
 latex/preferences/dialog.py |    1 -
 latex/preferences/tools.py  |   40 ++++++++++++++++++++--------------------
 latex/tools/postprocess.py  |    8 ++++----
 latex/tools/util.py         |   10 +++++-----
 latex/tools/views.py        |    9 ++++-----
 8 files changed, 44 insertions(+), 62 deletions(-)
---
diff --git a/latex/bibtex/completion.py b/latex/bibtex/completion.py
index 29dc083..297592d 100644
--- a/latex/bibtex/completion.py
+++ b/latex/bibtex/completion.py
@@ -22,7 +22,8 @@
 bibtex.completion
 """
 
-from logging import getLogger
+import logging
+
 from gi.repository import Gdk, GdkPixbuf
 
 from ..preferences import Preferences
@@ -33,6 +34,7 @@ from ..issues import MockIssueHandler
 from model import BibTeXModel
 from parser import BibTeXParser
 
+LOG = logging.getLogger(__name__)
 
 class BibTeXEntryTypeProposal(Proposal):
     """
@@ -93,8 +95,6 @@ class BibTeXCompletionHandler(ICompletionHandler):
     """
     This implements the BibTeX-specific code completion
     """
-    _log = getLogger("BibTeXCompletionHandler")
-
     trigger_keys = ["@"]
     prefix_delimiters = ["@"]
 
@@ -104,7 +104,7 @@ class BibTeXCompletionHandler(ICompletionHandler):
         self._issue_handler = MockIssueHandler()
 
     def complete(self, prefix):
-        self._log.debug("complete: '%s'" % prefix)
+        LOG.debug("BibTex complete: '%s'" % prefix)
 
         proposals = []
 
diff --git a/latex/bibtex/parser.py b/latex/bibtex/parser.py
index 96d00c0..35da9a8 100644
--- a/latex/bibtex/parser.py
+++ b/latex/bibtex/parser.py
@@ -63,13 +63,6 @@ from xml.sax.saxutils import escape
 from ..issues import Issue, MockIssueHandler
 from ..preferences import Preferences
 
-
-#    import sys
-#    import os
-#
-#    print "======== sys.path=%s, cwd=%s" % (sys.path, os.getcwd())
-
-
 class Token(object):
     """
     A BibTeX token
@@ -417,9 +410,6 @@ class BibTeXParser(object):
 
         return self._document
 
-    #~ def __del__(self):
-        #~ print "properly destroyed %s" % self
-
 #
 # BibTeX object model
 #
diff --git a/latex/latex/views.py b/latex/latex/views.py
index ac3c807..70997b4 100644
--- a/latex/latex/views.py
+++ b/latex/latex/views.py
@@ -24,10 +24,11 @@ latex.views
 LaTeX-specific views
 """
 
+import logging
+import xml.etree.ElementTree as ElementTree
+
 from gi.repository import Gtk, GdkPixbuf
 from gobject import GError
-from logging import getLogger
-import xml.etree.ElementTree as ElementTree
 
 from ..preferences import Preferences
 from ..base import PanelView
@@ -36,15 +37,13 @@ from ..base.templates import Template
 from ..issues import Issue
 from ..gldefs import _
 
+LOG = logging.getLogger(__name__)
 
 class SymbolCollection(object):
     """
     A collection of symbols read from an XML file
     """
 
-    _log = getLogger("SymbolCollection")
-
-
     class Group(object):
         def __init__(self, label):
             """
@@ -81,13 +80,10 @@ class SymbolCollection(object):
 class LaTeXSymbolMapView(PanelView):
     """
     """
-    _log = getLogger("LaTeXSymbolMapView")
 
     def __init__(self, context, editor):
         PanelView.__init__(self, context)
 
-        self._log.debug("init")
-
         self.set_orientation(Gtk.Orientation.VERTICAL)
 
         self._preferences = Preferences()
@@ -124,7 +120,7 @@ class LaTeXSymbolMapView(PanelView):
             try:
                 model.append([GdkPixbuf.Pixbuf.new_from_file(symbol.icon), str(symbol.template), symbol.template])
             except GError, s:
-                print s
+                LOG.error("Could not add symbol group %s to model" % symbol, exc_info=True)
 
         view = Gtk.IconView(model=model)
         view.set_pixbuf_column(0)
@@ -189,8 +185,6 @@ class LaTeXOutlineView(BaseOutlineView):
     A View showing an outline of the edited LaTeX document
     """
 
-    _log = getLogger("LaTeXOutlineView")
-
     def __init__(self, context, editor):
         BaseOutlineView.__init__(self, context, editor)
         self._handlers = {}
@@ -220,7 +214,7 @@ class LaTeXOutlineView(BaseOutlineView):
         """
         Load a new outline model
         """
-        self._log.debug("set_outline")
+        LOG.debug("LatexOutline: set outline")
 
         self._save_state()
 
@@ -268,7 +262,7 @@ class LaTeXOutlineView(BaseOutlineView):
                     break
 
             if not found:
-                self._log.error("File not found: %s" % filename)
+                LOG.error("LatexOutline: File not found: %s" % filename)
                 return
 
             system("gnome-open %s" % f.uri)
diff --git a/latex/preferences/dialog.py b/latex/preferences/dialog.py
index 4810f51..dd272d1 100644
--- a/latex/preferences/dialog.py
+++ b/latex/preferences/dialog.py
@@ -34,7 +34,6 @@ from . import Preferences
 from .tools import ToolPreferences
 
 def _insert_column_with_attributes(view, pos, title, rend, **kwargs):
-    print kwargs
     tv = Gtk.TreeViewColumn(title)
     tv.pack_start(rend, True)
     for k in kwargs:
diff --git a/latex/preferences/tools.py b/latex/preferences/tools.py
index 80a98e6..1ec7b7c 100644
--- a/latex/preferences/tools.py
+++ b/latex/preferences/tools.py
@@ -18,18 +18,20 @@
 # this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
 # Street, Fifth Floor, Boston, MA  02110-1301, USA
 
-from gi.repository import GObject
-
-from logging import getLogger
-from uuid import uuid4
+import logging
+import uuid
 import xml.etree.ElementTree as ElementTree
 import os
 
+from gi.repository import GObject
+
 from ..base.resources import Resources
 from ..tools import Tool, Job
 from ..tools.postprocess import GenericPostProcessor, RubberPostProcessor, LaTeXPostProcessor
 from ..util import singleton
 
+LOG = logging.getLogger(__name__)
+
 def str_to_bool(x):
     """
     Converts a string to a boolean value
@@ -40,9 +42,9 @@ def str_to_bool(x):
         try:
             return {"false" : False, "0" : False, "true" : True, "1" : True}[x.strip().lower()]
         except KeyError:
-            print "str_to_bool: unsupported value %s" % x
+            LOG.error("str_to_bool: unsupported value %s" % x)
     else:
-        print "str_to_bool: unsupported type %s" % str(type(x))
+        LOG.error("str_to_bool: unsupported type %s" % type(x))
 
 @singleton
 class ToolPreferences(GObject.GObject):
@@ -52,8 +54,6 @@ class ToolPreferences(GObject.GObject):
             GObject.SignalFlags.RUN_LAST, None, []),
     }
 
-    _log = getLogger("ToolPreferences")
-
     # maps names to classes
     POST_PROCESSORS = {"GenericPostProcessor" : GenericPostProcessor,
                        "LaTeXPostProcessor" : LaTeXPostProcessor,
@@ -70,7 +70,7 @@ class ToolPreferences(GObject.GObject):
             filename = Resources().get_data_file("tools.xml")
 
         self.__tools = ElementTree.parse(filename).getroot()
-        self._log.debug("Constructed")
+        LOG.debug("ToolPreferences constructed")
 
     def __notify_tools_changed(self):
         self.emit("tools-changed")
@@ -108,7 +108,7 @@ class ToolPreferences(GObject.GObject):
         for element in self.__tools.findall("tool"):
             if element.get("id") == id:
                 return element
-        self._log.warning("<tool id='%s'> not found" % id)
+        LOG.warning("<tool id='%s'> not found" % id)
         return None
 
     def save_or_update_tool(self, tool):
@@ -120,15 +120,15 @@ class ToolPreferences(GObject.GObject):
         tool_element = None
         if tool in self.__tool_ids:
             # find tool tag
-            self._log.debug("Tool element found, updating...")
+            LOG.debug("Tool element found, updating...")
 
             id = self.__tool_ids[tool]
             tool_element = self.__find_tool_element(id)
         else:
             # create new tool tag
-            self._log.debug("Creating new Tool...")
+            LOG.debug("Creating new Tool...")
 
-            id = str(uuid4())
+            id = str(uuit.uuid4())
             self.__tool_ids[tool] = id
 
             tool_element = ElementTree.SubElement(self.__tools, "tool")
@@ -166,10 +166,10 @@ class ToolPreferences(GObject.GObject):
         id_2 = self.__tool_ids[tool_2]
 
         if id_1 == id_2:
-            self._log.warning("Two tools have the same id. Please modify tools.xml to have unique id's.")
+            LOG.warning("Two tools have the same id. Please modify tools.xml to have unique id's.")
             return
 
-        self._log.debug("Tool IDs are {%s: %s, %s, %s}" % (tool_1.label, id_1, tool_2.label, id_2))
+        LOG.debug("Tool IDs are {%s: %s, %s, %s}" % (tool_1.label, id_1, tool_2.label, id_2))
 
         tool_element_1 = None
         tool_element_2 = None
@@ -189,18 +189,18 @@ class ToolPreferences(GObject.GObject):
 
             i += 1
 
-        self._log.debug("Found XML elements, indexes are {%s: %s, %s, %s}" % (tool_1.label, index_1, tool_2.label, index_2))
+        LOG.debug("Found XML elements, indexes are {%s: %s, %s, %s}" % (tool_1.label, index_1, tool_2.label, index_2))
 
         # successively replace each of them by the other in the XML model
         self.__tools.remove(tool_element_1)
         self.__tools.insert(index_1, tool_element_2)
 
-        self._log.debug("Replaced first tool by second in list")
+        LOG.debug("Replaced first tool by second in list")
 
         self.__tools.remove(tool_element_2)
         self.__tools.insert(index_2, tool_element_1)
 
-        self._log.debug("Replaced second tool by first in list")
+        LOG.debug("Replaced second tool by first in list")
 
         # notify changes
         self.__tools_changed = True
@@ -221,7 +221,7 @@ class ToolPreferences(GObject.GObject):
 
             self.__tools_changed = True
         except KeyError, e:
-            self._log.error("delete_tool: %s" % e)
+            LOG.error("delete_tool: %s" % e)
 
         self.__notify_tools_changed()
 
@@ -230,7 +230,7 @@ class ToolPreferences(GObject.GObject):
         Save the preferences to XML
         """
         if self.__tools_changed:
-            self._log.debug("Saving tools...")
+            LOG.debug("Saving tools...")
 
             tree = ElementTree.ElementTree(self.__tools)
             tree.write(Resources().get_user_file("tools.xml"), encoding="utf-8")
diff --git a/latex/tools/postprocess.py b/latex/tools/postprocess.py
index 838fa62..8af4d02 100644
--- a/latex/tools/postprocess.py
+++ b/latex/tools/postprocess.py
@@ -22,7 +22,7 @@
 tools.postprocess
 """
 
-from logging import getLogger
+import logging
 import re
 
 from ..issues import Issue
@@ -70,7 +70,7 @@ class GenericPostProcessor(PostProcessor):
     This just interprets the exit condition of the process
     """
 
-    _log = getLogger("GenericPostProcessor")
+    _log = logging.getLogger(__name__ + ".GenericPostProcessor")
 
     name = "GenericPostProcessor"
 
@@ -102,7 +102,7 @@ class LaTeXPostProcessor(PostProcessor):
     default error format (NOT using "-file-line-error")
     """
 
-    _log = getLogger("LatexPostProcessor")
+    _log = logging.getLogger(__name__ + ".LatexPostProcessor")
 
     name = "LaTeXPostProcessor"
 
@@ -159,7 +159,7 @@ class RubberPostProcessor(PostProcessor):
     This is a post-processor for rubber
     """
 
-    _log = getLogger("RubberPostProcessor")
+    _log = logging.getLogger(__name__ + ".RubberPostProcessor")
 
     name = "RubberPostProcessor"
 
diff --git a/latex/tools/util.py b/latex/tools/util.py
index 5d118ad..e994aa8 100644
--- a/latex/tools/util.py
+++ b/latex/tools/util.py
@@ -22,26 +22,26 @@
 tools.util
 """
 
-from logging import getLogger
+import logging
 import os
 import signal
 import subprocess
 import fcntl
+
 from gi.repository import GObject
 
+LOG = logging.getLogger(__name__)
 
 class Process(object):
     """
     This runs a command in a child process and polls the output
     """
 
-    __log = getLogger("Process")
-
     # intervall of polling stdout of the child process
     __POLL_INTERVAL = 250
 
     def execute(self, command):
-        self.__log.debug("execute: %s" % command)
+        LOG.debug("execute: %s" % command)
 
         # run child process
         self.__process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE,
@@ -69,7 +69,7 @@ class Process(object):
 
                 self._on_abort()
             except OSError, e:
-                self.__log.error("Failed to abort process: %s" % e)
+                LOG.error("Failed to abort process: %s" % e)
 
     def __on_stdout(self):
         try:
diff --git a/latex/tools/views.py b/latex/tools/views.py
index 0c0daa2..d008e35 100644
--- a/latex/tools/views.py
+++ b/latex/tools/views.py
@@ -22,7 +22,7 @@
 base.views
 """
 
-from logging import getLogger
+import logging
 
 from gi.repository import Gtk, GdkPixbuf
 
@@ -31,13 +31,12 @@ from ..base import PanelView
 from ..issues import Issue, IStructuredIssueHandler
 from ..gldefs import _
 
+LOG = logging.getLogger(__name__)
 
 class ToolView(PanelView, IStructuredIssueHandler):
     """
     """
 
-    _log = getLogger("ToolView")
-
     def __init__(self, context, editor):
         PanelView.__init__(self, context)
         self._handlers = {}
@@ -129,7 +128,7 @@ class ToolView(PanelView, IStructuredIssueHandler):
             if self._context.active_editor:
                 self._context.active_editor.select_lines(issue.start)
             else:
-                self._log.error("No Editor object for calling select_lines")
+                LOG.error("No Editor object for calling select_lines")
 
     def clear(self):
         self._store.clear()
@@ -185,7 +184,7 @@ class ToolView(PanelView, IStructuredIssueHandler):
                 icon = self._ICON_ERROR
             self._store.append(partition_id, [icon, issue.message, issue.file.basename, str(issue.start), issue])
 
-            self._log.debug(str(issue))
+            LOG.debug("Issue: %s" % issue)
 
         self._view.expand_all()
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]