This commit is contained in:
Tim Bentley 2011-01-12 18:52:33 +00:00
commit 9bf9e46d61
4 changed files with 27 additions and 16 deletions

View File

@ -282,13 +282,16 @@ def split_filename(path):
else: else:
return os.path.split(path) return os.path.split(path)
def get_web_page(url, update_openlp=False): def get_web_page(url, header=None, update_openlp=False):
""" """
Attempts to download the webpage at url and returns that page or None. Attempts to download the webpage at url and returns that page or None.
``url`` ``url``
The URL to be downloaded. The URL to be downloaded.
``header``
An optional HTTP header to pass in the request to the web server.
``update_openlp`` ``update_openlp``
Tells OpenLP to update itself if the page is successfully downloaded. Tells OpenLP to update itself if the page is successfully downloaded.
Defaults to False. Defaults to False.
@ -298,10 +301,13 @@ def get_web_page(url, update_openlp=False):
# http://docs.python.org/library/urllib2.html # http://docs.python.org/library/urllib2.html
if not url: if not url:
return None return None
req = urllib2.Request(url)
if header:
req.add_header(header[0], header[1])
page = None page = None
log.debug(u'Downloading URL = %s' % url) log.debug(u'Downloading URL = %s' % url)
try: try:
page = urllib2.urlopen(url) page = urllib2.urlopen(req)
log.debug(u'Downloaded URL = %s' % page.geturl()) log.debug(u'Downloaded URL = %s' % page.geturl())
except urllib2.URLError: except urllib2.URLError:
log.exception(u'The web page could not be downloaded') log.exception(u'The web page could not be downloaded')

View File

@ -264,7 +264,8 @@ class BSExtract(object):
log.debug(u'get_bible_chapter %s,%s,%s', version, bookname, chapter) log.debug(u'get_bible_chapter %s,%s,%s', version, bookname, chapter)
chapter_url = u'http://m.bibleserver.com/text/%s/%s%s' % \ chapter_url = u'http://m.bibleserver.com/text/%s/%s%s' % \
(version, bookname, chapter) (version, bookname, chapter)
soup = get_soup_for_bible_ref(chapter_url) header = (u'Accept-Language', u'en')
soup = get_soup_for_bible_ref(chapter_url, header)
if not soup: if not soup:
return None return None
Receiver.send_message(u'openlp_process_events') Receiver.send_message(u'openlp_process_events')
@ -496,19 +497,22 @@ class HTTPBible(BibleDB):
""" """
return HTTPBooks.get_verse_count(book, chapter) return HTTPBooks.get_verse_count(book, chapter)
def get_soup_for_bible_ref(reference_url, cleaner=None): def get_soup_for_bible_ref(reference_url, header=None, cleaner=None):
""" """
Gets a webpage and returns a parsed and optionally cleaned soup or None. Gets a webpage and returns a parsed and optionally cleaned soup or None.
``reference_url`` ``reference_url``
The URL to obtain the soup from. The URL to obtain the soup from.
``header``
An optional HTTP header to pass to the bible web server.
``cleaner`` ``cleaner``
An optional regex to use during webpage parsing. An optional regex to use during webpage parsing.
""" """
if not reference_url: if not reference_url:
return None return None
page = get_web_page(reference_url, True) page = get_web_page(reference_url, header, True)
if not page: if not page:
send_error_message(u'download') send_error_message(u'download')
return None return None

View File

@ -169,7 +169,7 @@ class ImpressController(PresentationController):
try: try:
return Dispatch(u'com.sun.star.ServiceManager') return Dispatch(u'com.sun.star.ServiceManager')
except pywintypes.com_error: except pywintypes.com_error:
log.warn(u'Failed to get COM service manager. ' log.exception(u'Failed to get COM service manager. '
u'Impress Controller has been disabled') u'Impress Controller has been disabled')
return None return None
@ -257,7 +257,6 @@ class ImpressDocument(PresentationDocument):
except: except:
log.exception(u'Failed to load presentation %s' % url) log.exception(u'Failed to load presentation %s' % url)
return False return False
self.presentation = self.document.getPresentation() self.presentation = self.document.getPresentation()
self.presentation.Display = \ self.presentation.Display = \
self.controller.plugin.renderManager.screens.current_display + 1 self.controller.plugin.renderManager.screens.current_display + 1
@ -327,8 +326,7 @@ class ImpressDocument(PresentationDocument):
self.presentation = None self.presentation = None
self.document.dispose() self.document.dispose()
except: except:
#We tried! log.exception("Closing presentation failed")
pass
self.document = None self.document = None
self.controller.remove_doc(self) self.controller.remove_doc(self)
@ -339,13 +337,14 @@ class ImpressDocument(PresentationDocument):
log.debug(u'is loaded OpenOffice') log.debug(u'is loaded OpenOffice')
#print "is_loaded " #print "is_loaded "
if self.presentation is None or self.document is None: if self.presentation is None or self.document is None:
#print "no present or document" log.debug("is_loaded: no presentation or document")
return False return False
try: try:
if self.document.getPresentation() is None: if self.document.getPresentation() is None:
#print "no getPresentation" log.debug("getPresentation failed to find a presentation")
return False return False
except: except:
log.exception("getPresentation failed to find a presentation")
return False return False
return True return True

View File

@ -23,7 +23,7 @@
# with this program; if not, write to the Free Software Foundation, Inc., 59 # # with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA # # Temple Place, Suite 330, Boston, MA 02111-1307 USA #
############################################################################### ###############################################################################
import logging
import os import os
from PyQt4 import QtCore from PyQt4 import QtCore
@ -31,6 +31,8 @@ from PyQt4 import QtCore
from openlp.core.lib import Receiver from openlp.core.lib import Receiver
from songimport import SongImport from songimport import SongImport
log = logging.getLogger(__name__)
if os.name == u'nt': if os.name == u'nt':
from win32com.client import Dispatch from win32com.client import Dispatch
PAGE_BEFORE = 4 PAGE_BEFORE = 4
@ -116,7 +118,7 @@ class OooImport(SongImport):
+ u'socket,host=localhost,port=2002;' \ + u'socket,host=localhost,port=2002;' \
+ u'urp;StarOffice.ComponentContext') + u'urp;StarOffice.ComponentContext')
except: except:
pass log.exception("Failed to resolve uno connection")
self.start_ooo_process() self.start_ooo_process()
loop += 1 loop += 1
manager = ctx.ServiceManager manager = ctx.ServiceManager
@ -143,7 +145,7 @@ class OooImport(SongImport):
process.waitForStarted() process.waitForStarted()
self.process_started = True self.process_started = True
except: except:
pass log.exception("start_ooo_process failed")
def open_ooo_file(self, filepath): def open_ooo_file(self, filepath):
""" """
@ -167,7 +169,7 @@ class OooImport(SongImport):
self.import_wizard.incrementProgressBar( self.import_wizard.incrementProgressBar(
u'Processing file ' + filepath, 0) u'Processing file ' + filepath, 0)
except: except:
pass log.exception("open_ooo_file failed")
return return
def close_ooo_file(self): def close_ooo_file(self):
@ -232,4 +234,4 @@ class OooImport(SongImport):
text += paratext + u'\n' text += paratext + u'\n'
songs = SongImport.process_songs_text(self.manager, text) songs = SongImport.process_songs_text(self.manager, text)
for song in songs: for song in songs:
song.finish() song.finish()