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:
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.
``url``
The URL to be downloaded.
``header``
An optional HTTP header to pass in the request to the web server.
``update_openlp``
Tells OpenLP to update itself if the page is successfully downloaded.
Defaults to False.
@ -298,10 +301,13 @@ def get_web_page(url, update_openlp=False):
# http://docs.python.org/library/urllib2.html
if not url:
return None
req = urllib2.Request(url)
if header:
req.add_header(header[0], header[1])
page = None
log.debug(u'Downloading URL = %s' % url)
try:
page = urllib2.urlopen(url)
page = urllib2.urlopen(req)
log.debug(u'Downloaded URL = %s' % page.geturl())
except urllib2.URLError:
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)
chapter_url = u'http://m.bibleserver.com/text/%s/%s%s' % \
(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:
return None
Receiver.send_message(u'openlp_process_events')
@ -496,19 +497,22 @@ class HTTPBible(BibleDB):
"""
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.
``reference_url``
The URL to obtain the soup from.
``header``
An optional HTTP header to pass to the bible web server.
``cleaner``
An optional regex to use during webpage parsing.
"""
if not reference_url:
return None
page = get_web_page(reference_url, True)
page = get_web_page(reference_url, header, True)
if not page:
send_error_message(u'download')
return None

View File

@ -169,7 +169,7 @@ class ImpressController(PresentationController):
try:
return Dispatch(u'com.sun.star.ServiceManager')
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')
return None
@ -257,7 +257,6 @@ class ImpressDocument(PresentationDocument):
except:
log.exception(u'Failed to load presentation %s' % url)
return False
self.presentation = self.document.getPresentation()
self.presentation.Display = \
self.controller.plugin.renderManager.screens.current_display + 1
@ -327,8 +326,7 @@ class ImpressDocument(PresentationDocument):
self.presentation = None
self.document.dispose()
except:
#We tried!
pass
log.exception("Closing presentation failed")
self.document = None
self.controller.remove_doc(self)
@ -339,13 +337,14 @@ class ImpressDocument(PresentationDocument):
log.debug(u'is loaded OpenOffice')
#print "is_loaded "
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
try:
if self.document.getPresentation() is None:
#print "no getPresentation"
log.debug("getPresentation failed to find a presentation")
return False
except:
log.exception("getPresentation failed to find a presentation")
return False
return True

View File

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