Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@member.fsf.org>2009-02-24 15:13:30 (GMT)
committer Aleksey Lim <alsroot@member.fsf.org>2009-03-02 06:28:37 (GMT)
commita8b8c38d288d61cdc48ca0c164663a4873fa7591 (patch)
tree804b84a218374ebd2d26feab20d629163b7740a6
parent361eca31504fcac8163f1285f785b86333b6a668 (diff)
Replace print() by logging
-rw-r--r--GUI_Components/Compound_Widgets/Gallery_View.py16
-rw-r--r--GUI_Components/Compound_Widgets/Library_View.py27
-rw-r--r--GUI_Components/Compound_Widgets/Reading_View.py10
-rw-r--r--GUI_Components/Edit_Pane.py10
-rw-r--r--GUI_Components/Image_Pane.py21
-rw-r--r--Infoslicer_GUI.py26
-rw-r--r--Processing/Article/Article.py3
-rw-r--r--Processing/Article/Paragraph.py10
-rw-r--r--Processing/Article/Section.py5
-rw-r--r--Processing/Article_Builder.py9
-rw-r--r--Processing/IO_Manager.py80
-rw-r--r--Processing/MediaWiki_Helper.py11
-rw-r--r--sugaractivity.py24
13 files changed, 157 insertions, 95 deletions
diff --git a/GUI_Components/Compound_Widgets/Gallery_View.py b/GUI_Components/Compound_Widgets/Gallery_View.py
index 6cd8b10..b505169 100644
--- a/GUI_Components/Compound_Widgets/Gallery_View.py
+++ b/GUI_Components/Compound_Widgets/Gallery_View.py
@@ -7,6 +7,9 @@ from Processing.IO_Manager import IO_Manager
from GUI_Components.Compound_Widgets.Base_Widgets.Editable_Textbox import Editable_Textbox
from Processing.Article.Article_Data import *
from Processing.Article.Article import Article
+import logging
+
+logger = logging.getLogger('infoslicer')
class Gallery_View( gtk.HBox ):
"""
@@ -137,20 +140,21 @@ class Gallery_View( gtk.HBox ):
self.imagebuf = gtk.gdk.pixbuf_new_from_file(self.image_list[self.current_index][0])
self.image.set_from_pixbuf(self.imagebuf)
self.caption.set_text("\n" + self.image_list[self.current_index][1])
- print "setting text to:"
- print "(%d / %d)\n" % (self.current_index+1, len(self.image_list))
+ logger.debug("setting text to:")
+ logger.debug("(%d / %d)\n" %
+ (self.current_index+1, len(self.image_list)))
self.imagenumberlabel.set_text("(%d / %d)\n" % (self.current_index+1, len(self.image_list)))
def set_image_list(self, image_list):
- print "validagting image list"
+ logger.debug("validagting image list")
self.image_list = IO_Manager().validate_image_list(image_list)
- print self.image_list
+ logger.debug(self.image_list)
def source_selected(self, combobox, param):
if combobox.get_active_text() == None :
return
if self.theme == None:
- print "no theme set, defaulting to Wikipedia Articles"
+ logger.debug("no theme set, defaulting to Wikipedia Articles")
self.theme = "Wikipedia Articles"
if self._source_article.article_title == combobox.get_active_text():
return
@@ -163,7 +167,7 @@ class Gallery_View( gtk.HBox ):
self.imagebox.drag_source_set_icon_pixbuf(self.imagebuf)
def drag_data_get_event(self, widget, context, selection_data, info, timestamp, data):
- print "getting data"
+ logger.debug("getting data")
atom = gtk.gdk.atom_intern("section")
imagedata = Picture_Data(self.source_article_id, self.image_list[self.current_index][0])
captiondata = Sentence_Data(0, self.source_article_id, 0, 0, 0, self.image_list[self.current_index][1])
diff --git a/GUI_Components/Compound_Widgets/Library_View.py b/GUI_Components/Compound_Widgets/Library_View.py
index f28220d..b990231 100644
--- a/GUI_Components/Compound_Widgets/Library_View.py
+++ b/GUI_Components/Compound_Widgets/Library_View.py
@@ -10,6 +10,10 @@ from Processing.IO_Manager import *
from Processing.Article.Article import Article
from Processing.Article.Article_Data import *
from GUI_Components.Compound_Widgets.Base_Widgets.Readonly_Textbox import Readonly_Textbox
+import logging
+
+logger = logging.getLogger('infoslicer')
+elogger = logging.getLogger('infoslicer::except')
theme_xpm = [
"16 16 4 1",
@@ -655,11 +659,11 @@ class Library_View( gtk.HBox ):
source = self.sourcetext.get_article()
edit = self.edittext.get_article()
if source and source.article_title == title and source.article_theme == sourcetheme:
- print "setting source title"
+ logger.debug("setting source title")
source.article_title = newtext
self.sourcepanelabel.set_markup("<b>Copy from: </b> %s\n "%(newtext, ))
if edit and edit.article_title == title and edit.article_theme == sourcetheme:
- print "setting edit title"
+ logger.debug("setting edit title")
edit.article_title = newtext
self.editpanelabel.set_markup("<span size='medium'><b>Theme: </b> %s \n<b>Article to edit: </b> %s</span>"%(sourcetheme, newtext))
@@ -686,10 +690,10 @@ class Library_View( gtk.HBox ):
source = self.sourcetext.get_article()
edit = self.edittext.get_article()
if source and source.article_theme == title:
- print "setting source theme"
+ logger.debug("setting source theme")
source.article_theme = newtext
if edit and edit.article_theme == title:
- print "setting edit theme"
+ logger.debug("setting edit theme")
edit.article_theme = newtext
self.editpanelabel.set_markup("<span size='medium'><b>Theme: </b> %s \n<b>Article to edit: </b> %s</span>"%(edit.article_theme, edit.article_title))
@@ -755,7 +759,8 @@ class Library_View( gtk.HBox ):
themeiter = model.append(None, ["<b>%s</b>" % (newtext, ), self.themeicon, "theme", newtext, True])
model.append(themeiter, ["<i>Create new article</i>", self.newarticleicon, "newarticle", "aaaaaaaaaaaaaaaaaaaa", True])
- except theme_exists_error:
+ except theme_exists_error, e:
+ elogger.debug('name_changed: %s' % e)
# If the theme already exists, then we proceed to just highlight it.
self.highlight_theme(newtext)
return
@@ -837,7 +842,7 @@ class Library_View( gtk.HBox ):
source = self.sourcetext.get_article()
edit = self.edittext.get_article()
if edit != None and edit.article_title == title and edit.article_theme == sourcetheme:
- print "setting edit title"
+ logger.debug("setting edit title")
edit.article_theme = desttheme
self.editpanelabel.set_markup("<span size='medium'><b>Theme: </b> %s \n<b>Article to edit: </b> %s</span>"%(desttheme, title))
@@ -1019,9 +1024,11 @@ class Library_View( gtk.HBox ):
statuslabel.set_label("Downloading %s..."%(title,))
IO_Manager().download_wiki_article(title=title, theme=theme, wiki = wiki, statuslabel=statuslabel)
except PageNotFoundError, e:
+ elogger.debug('download_and_add: %s' % e)
statuslabel.set_label("%s could not be found."%(title, ))
return
- except:
+ except Exception, e:
+ elogger.debug('download_and_add: %s' % e)
statuslabel.set_label("Error downloading %s. Check your connection."%(title, ))
return
@@ -1081,7 +1088,7 @@ class Library_View( gtk.HBox ):
buf = article.getBuffer()
text = buf.get_slice(buf.get_start_iter(), buf.get_end_iter())
if text:
- print "article has text"
+ logger.debug("article has text")
if not theme:
theme = "My Articles"
if not title:
@@ -1135,7 +1142,7 @@ class Library_View( gtk.HBox ):
while title in articles:
i = i + 1
title = "New Article %d" % (i, )
- print title
+ logger.debug(title)
article.article_title = title
- return article \ No newline at end of file
+ return article
diff --git a/GUI_Components/Compound_Widgets/Reading_View.py b/GUI_Components/Compound_Widgets/Reading_View.py
index f044982..9480be6 100644
--- a/GUI_Components/Compound_Widgets/Reading_View.py
+++ b/GUI_Components/Compound_Widgets/Reading_View.py
@@ -4,6 +4,10 @@ pygtk.require('2.0')
import gtk
from GUI_Components.Compound_Widgets.Base_Widgets.Readonly_Textbox import Readonly_Textbox
from Processing.IO_Manager import IO_Manager
+import logging
+
+logger = logging.getLogger('infoslicer')
+elogger = logging.getLogger('infoslicer::except')
class Reading_View( gtk.VBox ):
"""
@@ -45,7 +49,7 @@ class Reading_View( gtk.VBox ):
model = combo.get_model()
firstiter = model.get_iter_first()
firstvalue = model.get_value(firstiter, 0)
- print firstvalue
+ logger.debug(firstvalue)
if firstvalue == "Select a source article from this menu":
combo.remove_text(0)
@@ -55,7 +59,7 @@ class Reading_View( gtk.VBox ):
newarticle = IO_Manager().load_article(title, theme)
self.textbox.set_article(newarticle)
except Exception, e:
- pass
+ elogger.debug('source_selected: %s' % e)
def set_sentence_selection_mode(self):
self.textbox.set_mode(0)
@@ -71,4 +75,4 @@ class Reading_View( gtk.VBox ):
def clear_contents(self):
self.textbox.clear()
- \ No newline at end of file
+
diff --git a/GUI_Components/Edit_Pane.py b/GUI_Components/Edit_Pane.py
index 8a890c7..36ea739 100644
--- a/GUI_Components/Edit_Pane.py
+++ b/GUI_Components/Edit_Pane.py
@@ -7,8 +7,10 @@ from GUI_Components.Compound_Widgets.Reading_View import Reading_View
from GUI_Components.Compound_Widgets.Editing_View import Editing_View
from GUI_Components.Compound_Widgets.Library_View import Library_View
from Processing.Article.Article import Article
-from Processing.IO_Manager import IO_Manager
-from gettext import gettext as _
+from Processing.IO_Manager import IO_Manager
+import logging
+
+logger = logging.getLogger('infoslicer')
class Edit_Pane(Pane):
"""
@@ -89,7 +91,7 @@ class Edit_Pane(Pane):
elif current_selection == _("Sections"):
self.readarticle.set_section_selection_mode()
self.editarticle.set_section_selection_mode()
- #print current_selection
+ #logger.debug(current_selection)
def get_source_article(self):
return self.readarticle.textbox.get_article()
@@ -144,4 +146,4 @@ class Edit_Pane(Pane):
self.editarticle.textbox.set_article(article)
self.editarticle.article_theme = _("Wikipedia Articles")
-
+
diff --git a/GUI_Components/Image_Pane.py b/GUI_Components/Image_Pane.py
index 71d244d..b5a458e 100644
--- a/GUI_Components/Image_Pane.py
+++ b/GUI_Components/Image_Pane.py
@@ -7,7 +7,9 @@ from GUI_Components.Compound_Widgets.Editing_View import Editing_View
from GUI_Components.Compound_Widgets.Gallery_View import Gallery_View
from Processing.Article.Article import Article
from Processing.IO_Manager import IO_Manager
-from gettext import gettext as _
+import logging
+
+logger = logging.getLogger('infoslicer')
class Image_Pane(Pane):
"""
@@ -69,24 +71,25 @@ class Image_Pane(Pane):
def set_source_article(self, source):
- print "source received. title: %s, theme: %s" % (source.article_title, source.article_theme)
+ logger.debug("source received. title: %s, theme: %s" %
+ (source.article_title, source.article_theme))
current = self.gallery._source_article
self.gallery._source_article = source
if source and source.article_title:
source.article_theme = _("Wikipedia Articles")
if current:
if current.article_title == source.article_title and current.article_theme == source.article_theme:
- print "same"
+ logger.debug("same")
return
self.gallery.current_index = 0
if source.image_list != []:
- print "setting images"
+ logger.debug("setting images")
self.gallery.set_image_list(source.image_list)
self.gallery.get_first_item()
self.gallery.theme = _("Wikipedia Articles")
self.gallery.source_article_id = source.source_article_id
- print source.image_list
+ logger.debug(source.image_list)
else:
self.gallery.imagenumberlabel.set_label("")
self.gallery.image.clear()
@@ -104,9 +107,9 @@ class Image_Pane(Pane):
return article
def set_working_article(self, article):
- print "working received, title %s theme %s " % (article.article_title, article.article_theme)
- self.editarticle.articletitle.set_markup("<span size='medium'><b> %s </b> %s \n<b> %s </b> %s</span>"% \
- (_("Theme:"), article.article_theme, _("Article:"), article.article_title))
+ logger.debug("working received, title %s theme %s " %
+ (article.article_title, article.article_theme))
+ self.editarticle.articletitle.set_markup("<span size='medium'><b>Theme:</b> %s \n<b>Article:</b> %s</span>"%(article.article_theme, article.article_title))
if article == None:
article = Article()
self.editarticle.textbox.set_article(article)
@@ -124,4 +127,4 @@ class Image_Pane(Pane):
self.gallery.articlemenu.set_active(count)
-
+
diff --git a/Infoslicer_GUI.py b/Infoslicer_GUI.py
index e40c0e6..897c1a5 100644
--- a/Infoslicer_GUI.py
+++ b/Infoslicer_GUI.py
@@ -13,7 +13,9 @@ from GUI_Components.Image_Pane import Image_Pane
from GUI_Components.Publish_Pane import Publish_Pane
from Processing.Article.Article import Article
from Processing.IO_Manager import IO_Manager
-from gettext import gettext as _
+import logging
+
+logger = logging.getLogger('infoslicer')
class Infoslicer_GUI:
"""
@@ -25,16 +27,16 @@ class Infoslicer_GUI:
"""
def __init__(self):
- print "InfoSlicer version 0.1, Copyright (C) 2008 IBM Corporation\
+ logger.info("InfoSlicer version 0.1, Copyright (C) 2008 IBM Corporation\
\nInfoSlicer comes with ABSOLUTELY NO WARRANTY; for details run the program with the `-warranty' argument.\
- \nThis is free software, and you are welcome to redistribute it under certain conditions; type `-conditions' for details."
+ \nThis is free software, and you are welcome to redistribute it under certain conditions; type `-conditions' for details.")
self._parse_args()
self.__set_up_GUI()
def _parse_args(self):
for arg in sys.argv:
if arg == "-warranty" or arg == "-conditions":
- print "GNU GENERAL PUBLIC LICENSE \
+ logger.info("GNU GENERAL PUBLIC LICENSE \
\nTERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION \
\n \
0. This License applies to any program or other work which contains\n\
@@ -314,7 +316,7 @@ proprietary programs. If your program is a subroutine library, you may\n\
consider it more useful to permit linking proprietary applications with the\n\
library. If this is what you want to do, use the GNU Lesser General\n\
Public License instead of this License.\n\
-"
+")
return
def setpanel(self, panel):
@@ -396,8 +398,10 @@ Public License instead of this License.\n\
if article in wikiarticle:
self.source = IO_Manager().load_article(wikiarticle, _("Wikipedia Articles"))
self.working = IO_Manager().load_article(article, theme)
- print "loading source %s from %s" % (wikiarticle, _("Wikipedia Articles"))
- print "loading edit %s from %s" % (article, theme)
+ logger.debug("loading source %s from %s" %
+ (wikiarticle, "Wikipedia Articles"))
+ logger.debug("loading edit %s from %s" %
+ (article, theme))
ignore = True
self.currentpane = None
@@ -418,19 +422,19 @@ Public License instead of this License.\n\
def go_arrange_mode(self, widget, event, data):
key = event.keyval
if key == gtk.keysyms.F1:
- print "f1"
+ logger.debug("f1")
self.switch_page(0)
if key == gtk.keysyms.F2:
- print "f2"
+ logger.debug("f2")
self.switch_page(1)
if key == gtk.keysyms.F3:
- print "f3"
+ logger.debug("f3")
self.switch_page(2)
"""
Save and quit current article
"""
def do_quit_event(self):
- print "quitting"
+ logger.debug("quitting")
article = self.currentpane.get_working_article()
IO_Manager().save_article(article)
diff --git a/Processing/Article/Article.py b/Processing/Article/Article.py
index 6580a45..54613fa 100644
--- a/Processing/Article/Article.py
+++ b/Processing/Article/Article.py
@@ -6,6 +6,9 @@ import gtk
from random import Random
from Article_Data import *
from Processing.Article.Section import *
+import logging
+
+logger = logging.getLogger('infoslicer')
arrow_xpm = [
"15 11 4 1",
diff --git a/Processing/Article/Paragraph.py b/Processing/Article/Paragraph.py
index ac578b5..57bb771 100644
--- a/Processing/Article/Paragraph.py
+++ b/Processing/Article/Paragraph.py
@@ -1,6 +1,9 @@
# Copyright (C) IBM Corporation 2008
from Processing.Article.Sentence import *
+import logging
+
+logger = logging.getLogger('infoslicer')
"""
Created by Jonathan Mace
@@ -39,7 +42,7 @@ class RawParagraph:
elif sentence_data.type == "picture":
sentence = Picture(sentence_data, self.buf, insertioniter)
else:
- print "WARNING, WEIRD SENTENCES: %s" % (sentence_data.type, )
+ logger.debug("WARNING, WEIRD SENTENCES: %s" % (sentence_data.type))
self.sentences.insert(insertionindex, sentence)
def deleteSentence(self, lociter):
@@ -232,7 +235,8 @@ class Paragraph( RawParagraph ):
elif sentence_data.type == "picture":
sentence = Picture(sentence_data, buf, insertioniter)
else:
- print "WARNING, WEIRD SENTENCES: %s" % (sentence_data.type, )
+ logger.debug("WARNING, WEIRD SENTENCES: %s" %
+ (sentence_data.type))
sentences.append(sentence)
insertioniter = buf.get_iter_at_mark(insertionmark)
@@ -251,4 +255,4 @@ class dummyParagraph( Paragraph ):
self.source_section_id = -1
self.source_paragraph_id = -1
self.buf = buf
- self.sentences = [ dummySentence(buf, insertioniter, leftgravity) ] \ No newline at end of file
+ self.sentences = [ dummySentence(buf, insertioniter, leftgravity) ]
diff --git a/Processing/Article/Section.py b/Processing/Article/Section.py
index aecae66..90fae37 100644
--- a/Processing/Article/Section.py
+++ b/Processing/Article/Section.py
@@ -1,6 +1,9 @@
# Copyright (C) IBM Corporation 2008
from Processing.Article.Paragraph import *
+import logging
+
+logger = logging.getLogger('infoslicer')
"""
Created by Jonathan Mace
@@ -259,7 +262,7 @@ class RawSection:
if paragraph.getStart().compare(nextparagraph.getStart()) == -1:
text = self.buf.get_slice(paragraph.getStart(), nextparagraph.getStart())
if len(text) > 0 and text[-1] != "\n":
- print "concatenating paragraphs"
+ logger.debug("concatenating paragraphs")
nextparagraph.sentences = paragraph.sentences + nextparagraph.sentences
else:
paragraphs.extend(paragraph.checkIntegrity(nextparagraph.getStart()))
diff --git a/Processing/Article_Builder.py b/Processing/Article_Builder.py
index 2b83c18..276be4c 100644
--- a/Processing/Article_Builder.py
+++ b/Processing/Article_Builder.py
@@ -5,6 +5,9 @@ from NewtifulSoup import NewtifulStoneSoup as BeautifulStoneSoup
from Processing.Article.Article_Data import *
import re
import IO_Manager
+import logging
+
+logger = logging.getLogger('infoslicer')
class Article_Builder:
"""
@@ -44,7 +47,7 @@ class Article_Builder:
source_article_id = article_id
text = ph.renderContents().replace("\n", "").replace("&amp;#160;", "").strip() + " "
if text[0:5] == "Satur":
- print unicode(text)
+ logger.debug(unicode(text))
sentence_data = Sentence_Data(id, source_article_id, source_section_id, source_paragraph_id, source_sentence_id, text)
sentence_data_list.append(sentence_data)
paragraph_data.append(Paragraph_Data("shortdesc", article_id, "shortdesc", "shortdesc", sentence_data_list))
@@ -203,7 +206,7 @@ class Article_Builder:
image_tag = self.tag_generator(output, "image", attrs=[("href", sentence.text.replace(workingDir, ".."))])
paragraph_tag.append(image_tag)
else:
- print sentence.type
+ logger.ebiug(sentence.type)
section_tag.append(paragraph_tag)
current_ref.append(section_tag)
@@ -231,4 +234,4 @@ class Article_Builder:
if contents != None:
new_tag.insert(0, contents)
return new_tag
- \ No newline at end of file
+
diff --git a/Processing/IO_Manager.py b/Processing/IO_Manager.py
index 7cffced..9ffcb3f 100644
--- a/Processing/IO_Manager.py
+++ b/Processing/IO_Manager.py
@@ -10,6 +10,10 @@ from MediaWiki_Helper import MediaWiki_Helper, PageNotFoundError
from MediaWiki_Parser import MediaWiki_Parser
import shutil
import re
+import logging
+
+logger = logging.getLogger('infoslicer')
+elogger = logging.getLogger('infoslicer::except')
class theme_not_found_error(Exception):
def __init__(self, value):
@@ -48,8 +52,9 @@ class IO_Manager:
from sugar.activity import activity
# On Sugar, save to the data subfolder of the app directory
self.workingDir = os.path.join(activity.get_activity_root(), "data")
- print "Activity root is: %s" % str(activity.get_activity_root())
- print "Data folder is: %s" % self.workingDir
+ logger.debug("Activity root is: %s" %
+ str(activity.get_activity_root()))
+ logger.debug("Data folder is: %s" % self.workingDir)
else:
# On Linux, save to a .slicedata subdir of the user's homedir
self.workingDir = os.path.join(os.getenv("HOME"), ".slicedata")
@@ -59,7 +64,7 @@ class IO_Manager:
proxy_file_handle = open(proxy_file, "r")
for line in proxy_file_handle.readlines():
parts = line.split(':', 1)
- #print "setting " + parts[0] + " proxy to " + parts[1]
+ #logger.debug("setting " + parts[0] + " proxy to " + parts[1])
self.proxies[parts[0].strip()] = parts[1].strip()
proxy_file_handle.close()
if self.proxies == {}:
@@ -69,9 +74,9 @@ class IO_Manager:
"""
removes non-alphanumeric chars from titles and lowercases it
"""
- print "Cleaning: " + title
+ logger.debug("Cleaning: " + title)
output = re.sub(re.compile('\W'), "_", title).lower()
- print "Output: " + output
+ logger.debug("Output: " + output)
return output
def install_library(self):
@@ -79,17 +84,18 @@ class IO_Manager:
file_list = [('Lion (from en.wikipedia.org)', os.path.join(os.path.split(__file__)[0], "demolibrary", "lion-wikipedia.dita"), 'Wikipedia Articles'), ('Tiger (from en.wikipedia.org)', os.path.join(os.path.split(__file__)[0], "demolibrary", "tiger-wikipedia.dita"), 'Wikipedia Articles'), ('Giraffe (from en.wikipedia.org)', os.path.join(os.path.split(__file__)[0], "demolibrary", "giraffe-wikipedia.dita"), 'Wikipedia Articles'), ('Giraffe', os.path.join(os.path.split(__file__)[0], "demolibrary", "giraffe-blank.dita"), 'My Articles'), ('Zebra (from en.wikipedia.org)', os.path.join(os.path.split(__file__)[0], "demolibrary", "zebra-wikipedia.dita"), 'Wikipedia Articles')]
for file in file_list:
if file[2] not in self.get_themes():
- print "install library: creating theme %s" % file[2]
+ logger.debug("install library: creating theme %s" %
+ file[2])
self.add_theme_to_library(file[2])
- print "install library: opening %s" % file[1]
+ logger.debug("install library: opening %s" % file[1])
open_file = open(file[1], "r")
contents = open_file.read()
open_file.close()
if contents:
- print "install library: content read sucessfully"
- print "install library: saving page %s" % file[0]
+ logger.debug("install library: content read sucessfully")
+ logger.debug("install library: saving page %s" % file[0])
self.save_page(file[0], contents, file[2], get_images=True)
- print "install library: save successful"
+ logger.debug("install library: save successful")
def __add_page_to_library(self, title, path, theme="My Articles"):
"""
@@ -108,7 +114,8 @@ class IO_Manager:
existing_entry.extract()
map.map.append(Tag(map, "topicref", [("href", path), ("navtitle", title)]))
self.save_map(theme, map)
- except Exception:
+ except Exception, e:
+ elogger.debug('__add_page_to_library: %s' % e)
self.add_theme_to_library(theme)
self.__add_page_to_library(title, path, theme)
@@ -129,7 +136,8 @@ class IO_Manager:
else:
raise theme_exists_error("Theme already exists")
self.save_map("Library", map)
- except theme_not_found_error:
+ except theme_not_found_error, e:
+ elogger.debug('add_theme_to_library: %s' % e)
# this error is caused by failing to open the library, so create the library and try again
self.__create_map("Library")
self.add_theme_to_library(theme)
@@ -191,7 +199,8 @@ class IO_Manager:
"""
try:
map = self.load_map(theme)
- except Exception:
+ except Exception, e:
+ elogger.debug('get_pages_in_theme: %s' % e)
return []
output = []
for page in map.map.findAll("topicref"):
@@ -211,7 +220,8 @@ class IO_Manager:
output.append(theme["navtitle"])
output.sort()
return output
- except Exception:
+ except Exception, e:
+ elogger.debug('get_themes: %s' % e)
return []
def get_unique_article_ID(self):
@@ -228,7 +238,7 @@ class IO_Manager:
id += len(item[2])
# Multiply by 1000 to prevent any problems caused by deleting files
id = id * 1000
- print "ID FILE NOT FOUND, setting ID to " + str(id)
+ logger.debug("ID FILE NOT FOUND, setting ID to " + str(id))
id_file = open(os.path.join(self.workingDir, "idfile"), "w")
id_file.write(str(id))
id_file.close()
@@ -253,7 +263,7 @@ class IO_Manager:
"""
document = BeautifulStoneSoup(document)
dir_path = os.path.join(self.workingDir, self.clean_title(title), "images")
- print dir_path
+ logger.debug(dir_path)
if not os.path.exists(dir_path):
os.makedirs(dir_path, 0777)
if statuslabel != None:
@@ -275,7 +285,7 @@ class IO_Manager:
path = document.source['href'].rsplit("/", 1)[0] + path
else:
path = document.source['href'].rsplit("/", 1)[0] + "/" + path
- print "Retrieving image: " + path
+ logger.debug("Retrieving image: " + path)
file = open(os.path.join(dir_path, image_title), 'wb')
image_contents = self.__open_URL(path)
if image_contents == None:
@@ -313,7 +323,7 @@ class IO_Manager:
@return: Contents of page.
"""
theme_map = self.load_map(theme)
- print title + theme
+ logger.debug(title + theme)
page_location = theme_map.find("topicref", attrs={ "navtitle" : title })
if page_location != None:
page_location = page_location['href']
@@ -340,7 +350,8 @@ class IO_Manager:
@param from_theme: Source theme.
@param to_theme: Destination theme.
"""
- print "COPY PAGE %s FROM %s TO %s" % (title, fromtheme, totheme)
+ logger.debug("COPY PAGE %s FROM %s TO %s" %
+ (title, fromtheme, totheme))
article = self.load_raw_page(title, fromtheme)
self.save_page(title, article, totheme, overwrite=False)
@@ -376,7 +387,8 @@ class IO_Manager:
for page in pages:
page.extract()
self.save_map(from_theme, from_map)
- except Exception:
+ except Exception, e:
+ elogger.debug('move_page: %s' % e)
# Shouldn't ever happen
pass
@@ -386,15 +398,15 @@ class IO_Manager:
"""
urllib._urlopener = self.New_URL_Opener()
try:
- print "opening " + url
- print "proxies: " + str(self.proxies)
+ logger.debug("opening " + url)
+ logger.debug("proxies: " + str(self.proxies))
doc = urllib.urlopen(url, proxies=self.proxies)
output = doc.read()
doc.close()
- print "url opened succesfully"
+ logger.debug("url opened succesfully")
return output
except IOError, e:
- print e
+ elogger.debug('__open_URL: %s' % e)
def page_exists(self, title, theme):
"""
@@ -406,7 +418,8 @@ class IO_Manager:
return True
else:
return False
- except Exception:
+ except Exception, e:
+ elogger.debug('page_exists: %s' % e)
return False
def theme_exists(self, theme):
@@ -431,8 +444,8 @@ class IO_Manager:
entry = theme_map.find("topicref", attrs={"navtitle" : page})
try:
os.remove(entry['href'])
- except Exception:
- pass
+ except Exception, e:
+ elogger.debug('remove_page: %s' % e)
entry.extract()
self.save_map(theme, theme_map)
@@ -450,9 +463,9 @@ class IO_Manager:
os.remove(os.path.join(self.workingDir, entry['href']))
entry.extract()
self.save_map("Library", library)
- except Exception:
+ except Exception, e:
# Trying to remove a theme that doesn't exist, so pretend it worked.
- pass
+ elogger.debug('remove_theme: %s' % e)
def rename_page(self, theme, old_title, new_title):
"""
@@ -464,8 +477,8 @@ class IO_Manager:
if page != None:
page['navtitle'] = new_title
self.save_map(theme, map)
- except Exception:
- pass
+ except Exception, e:
+ elogger.debug('rename_page: %s' % e)
def rename_theme(self, old_name, new_name):
"""
@@ -528,7 +541,8 @@ class IO_Manager:
file.write(contents)
file.close()
self.__add_page_to_library(title, os.path.join(directory, "%s.dita" % new_title), theme)
- print "Page saved to - " + os.path.join(directory, "%s.dita" % new_title)
+ logger.debug("Page saved to - " + os.path.join(directory, "%s.dita" %
+ new_title))
return os.path.join(directory, "%s.dita" % new_title)
def validate_image_list(self, image_list):
@@ -549,4 +563,4 @@ class IO_Manager:
return image_list
class New_URL_Opener(urllib.FancyURLopener):
- version = "Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11" \ No newline at end of file
+ version = "Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11"
diff --git a/Processing/MediaWiki_Helper.py b/Processing/MediaWiki_Helper.py
index 3a328f3..1264afc 100644
--- a/Processing/MediaWiki_Helper.py
+++ b/Processing/MediaWiki_Helper.py
@@ -3,6 +3,9 @@
import urllib
import IO_Manager
from xml.dom import minidom
+import logging
+
+logger = logging.getLogger('infoslicer')
"""
Extend urllib class to spoof user-agent
@@ -181,12 +184,12 @@ class MediaWiki_Helper:
@return: page contents
@rtype: string"""
urllib._urlopener = NewURLopener()
- print "opening " + path
- print "proxies: " + str(self.proxies)
+ logger.debiug("opening " + path)
+ logger.debiug("proxies: " + str(self.proxies))
doc = urllib.urlopen(path, proxies=self.proxies)
output = doc.read()
doc.close()
- print "url opened successfully"
+ logger.debiug("url opened successfully")
return output
def stripTags(self, input, tag):
@@ -260,4 +263,4 @@ class MediaWiki_Helper:
if (len(resultList) > 0):
return stripTags(resultList[0].getElementsByTagName("Text")[0].toxml(), "Text")
else:
- raise noResultsError("No results found for '%s' on wiki: %s" % (search, wiki))""" \ No newline at end of file
+ raise noResultsError("No results found for '%s' on wiki: %s" % (search, wiki))"""
diff --git a/sugaractivity.py b/sugaractivity.py
index fe03eb2..116412c 100644
--- a/sugaractivity.py
+++ b/sugaractivity.py
@@ -5,6 +5,10 @@ from Infoslicer_GUI import Infoslicer_GUI
from sugar.activity import activity
from gettext import gettext as _
from Processing.IO_Manager import IO_Manager
+from Processing.Article.Article import Article
+import logging
+
+logger = logging.getLogger('infoslicer')
class sugaractivity( activity.Activity, Infoslicer_GUI ):
"""
@@ -35,14 +39,14 @@ class sugaractivity( activity.Activity, Infoslicer_GUI ):
self.show_all()
self.toolbox.set_current_toolbar(2)
- print "dictionary:"
- print handle.get_dict()
+ logger.debug("dictionary:")
+ logger.debug(handle.get_dict())
"""
Operating system specific file reading and writing methods are below
"""
def read_file(self, file_path):
- print "reading the file"
+ logger.debug("reading the file")
"""
At the moment, the format of a saved file will just be:
sourcetitle
@@ -62,8 +66,11 @@ class sugaractivity( activity.Activity, Infoslicer_GUI ):
workingtheme = lines[2]
currentindex = int(lines[3])
- print "file read"
- print "sourcetitle: %s, workingtitle: %s, workingtheme: %s, currentindex: %s" % (sourcetitle, workingtitle, workingtheme, currentindex)
+ logger.debug("file read")
+ logger.debug("sourcetitle: %s, workingtitle: %s," \
+ "workingtheme: %s, currentindex: %s" %
+ (sourcetitle, workingtitle, workingtheme, currentindex))
+
iomanager = IO_Manager()
if iomanager.page_exists(sourcetitle, _("Wikipedia Articles")):
sourcearticle = iomanager.load_article(sourcetitle, _("Wikipedia Articles"))
@@ -84,7 +91,7 @@ class sugaractivity( activity.Activity, Infoslicer_GUI ):
self.currentpane.set_working_article(workingarticle)
def write_file(self, file_path):
- print "writing the file to %s" % file_path
+ logger.debug("writing the file to %s" % file_path)
sourcearticle = self.currentpane.get_source_article()
workingarticle = self.currentpane.get_working_article()
@@ -100,7 +107,8 @@ class sugaractivity( activity.Activity, Infoslicer_GUI ):
currentindex = self.currentindex
file = open(file_path, 'w')
- print "writing source: %s, working: %s, theme: %s" % (sourcetitle, workingtitle, workingtheme)
+ logger.debug("writing source: %s, working: %s, theme: %s" %
+ (sourcetitle, workingtitle, workingtheme))
file.write("%s\n%s\n%s\n%s" % (sourcetitle, workingtitle, workingtheme, str(currentindex)))
file.close()
@@ -119,7 +127,7 @@ class sugaractivity( activity.Activity, Infoslicer_GUI ):
def page_switched(self, widget, page_num, data):
- print "page_switched to %s" % (page_num, )
+ logger.debug("page_switched to %s" % (page_num))
if page_num > 0:
self.mode_switched(page_num - 1)