Fixed bug #1160506 - use download settings exlusively from download.cfg.

This commit is contained in:
Martin Zibricky 2013-04-05 23:31:23 +02:00
parent 9a543d395a
commit caf1290a16

View File

@ -57,6 +57,9 @@ class ThemeScreenshotThread(QtCore.QThread):
def run(self): def run(self):
themes = self.parent().config.get(u'themes', u'files') themes = self.parent().config.get(u'themes', u'files')
themes = themes.split(u',') themes = themes.split(u',')
themes_dir = self.parent().config.get(u'themes', u'directory')
tmp_dir = os.path.join(unicode(gettempdir(), get_filesystem_encoding()),
u'openlp')
config = self.parent().config config = self.parent().config
for theme in themes: for theme in themes:
# Stop if the wizard has been cancelled. # Stop if the wizard has been cancelled.
@ -65,9 +68,8 @@ class ThemeScreenshotThread(QtCore.QThread):
title = config.get(u'theme_%s' % theme, u'title') title = config.get(u'theme_%s' % theme, u'title')
filename = config.get(u'theme_%s' % theme, u'filename') filename = config.get(u'theme_%s' % theme, u'filename')
screenshot = config.get(u'theme_%s' % theme, u'screenshot') screenshot = config.get(u'theme_%s' % theme, u'screenshot')
urllib.urlretrieve(u'%s%s' % (self.parent().web, screenshot), urllib.urlretrieve(u'%s%s' % (self.parent().baseurl, themes_dir + '/' + screenshot),
os.path.join(unicode(gettempdir(), get_filesystem_encoding()), os.path.join(tmp_dir, screenshot))
u'openlp', screenshot))
item = QtGui.QListWidgetItem(title, self.parent().themesListWidget) item = QtGui.QListWidgetItem(title, self.parent().themesListWidget)
item.setData(QtCore.Qt.UserRole, QtCore.QVariant(filename)) item.setData(QtCore.Qt.UserRole, QtCore.QVariant(filename))
item.setCheckState(QtCore.Qt.Unchecked) item.setCheckState(QtCore.Qt.Unchecked)
@ -85,13 +87,25 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
QtGui.QWizard.__init__(self, parent) QtGui.QWizard.__init__(self, parent)
self.setupUi(self) self.setupUi(self)
self.screens = screens self.screens = screens
# check to see if we have web access
self.web = u'http://openlp.org/files/frw/'
self.config = SafeConfigParser() self.config = SafeConfigParser()
# The following url should contain 'download.cfg' or redirect OpenLP
# to the right url of 'download.cfg' file.
# 'download.cfg' file contains definitions for everything that is
# available for download into OpenLP in FirstTimeWizard.
self.web = u'http://openlp.org/files/frw/'
# Base url for dowloading resource files (songs, themes, bibles).
# These files could be hosted on different places and thus the base
# url is defined in 'download.cfg' file.
self.baseurl = None
# Check to see if we have web access
self.webAccess = get_web_page(u'%s%s' % (self.web, u'download.cfg')) self.webAccess = get_web_page(u'%s%s' % (self.web, u'download.cfg'))
if self.webAccess: if self.webAccess:
files = self.webAccess.read() files = self.webAccess.read()
self.config.readfp(io.BytesIO(files)) self.config.readfp(io.BytesIO(files))
self.baseurl = self.config.get(u'general', u'base url')
# Ensure url ends with '/'.
if not self.baseurl.endswith('/'):
self.baseurl += '/'
self.updateScreenListCombo() self.updateScreenListCombo()
self.downloadCancelled = False self.downloadCancelled = False
self.downloading = unicode(translate('OpenLP.FirstTimeWizard', self.downloading = unicode(translate('OpenLP.FirstTimeWizard',
@ -123,7 +137,7 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
# Check if this is a re-run of the wizard. # Check if this is a re-run of the wizard.
self.hasRunWizard = Settings().value( self.hasRunWizard = Settings().value(
u'general/has run wizard', QtCore.QVariant(False)).toBool() u'general/has run wizard', QtCore.QVariant(False)).toBool()
# Sort out internet access for downloads # Sort out internet access for downloads.
if self.webAccess: if self.webAccess:
songs = self.config.get(u'songs', u'languages') songs = self.config.get(u'songs', u'languages')
songs = songs.split(u',') songs = songs.split(u',')
@ -280,6 +294,7 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
Download a file given a URL. The file is retrieved in chunks, giving Download a file given a URL. The file is retrieved in chunks, giving
the ability to cancel the download at any point. the ability to cancel the download at any point.
""" """
log.debug(u'Downloading %s' % url)
block_count = 0 block_count = 0
block_size = 4096 block_size = 4096
urlfile = urllib2.urlopen(url) urlfile = urllib2.urlopen(url)
@ -348,13 +363,18 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
self.max_progress = 0 self.max_progress = 0
self.finishButton.setVisible(False) self.finishButton.setVisible(False)
Receiver.send_message(u'openlp_process_events') Receiver.send_message(u'openlp_process_events')
# Directory name appended to base download url as the name
# is found in download.cfg file.
songs_dir = unicode(self.config.get(u'songs', u'directory'), u'utf8')
bibles_dir = unicode(self.config.get(u'bibles', u'directory'), u'utf8')
themes_dir = unicode(self.config.get(u'themes', u'directory'), u'utf8')
# Loop through the songs list and increase for each selected item # Loop through the songs list and increase for each selected item
for i in xrange(self.songsListWidget.count()): for i in xrange(self.songsListWidget.count()):
Receiver.send_message(u'openlp_process_events') Receiver.send_message(u'openlp_process_events')
item = self.songsListWidget.item(i) item = self.songsListWidget.item(i)
if item.checkState() == QtCore.Qt.Checked: if item.checkState() == QtCore.Qt.Checked:
filename = item.data(QtCore.Qt.UserRole).toString() filename = item.data(QtCore.Qt.UserRole).toString()
size = self._getFileSize(u'%s%s' % (self.web, filename)) size = self._getFileSize(u'%s%s/%s' % (self.baseurl, songs_dir, filename))
self.max_progress += size self.max_progress += size
# Loop through the Bibles list and increase for each selected item # Loop through the Bibles list and increase for each selected item
iterator = QtGui.QTreeWidgetItemIterator(self.biblesTreeWidget) iterator = QtGui.QTreeWidgetItemIterator(self.biblesTreeWidget)
@ -363,7 +383,7 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
item = iterator.value() item = iterator.value()
if item.parent() and item.checkState(0) == QtCore.Qt.Checked: if item.parent() and item.checkState(0) == QtCore.Qt.Checked:
filename = item.data(0, QtCore.Qt.UserRole).toString() filename = item.data(0, QtCore.Qt.UserRole).toString()
size = self._getFileSize(u'%s%s' % (self.web, filename)) size = self._getFileSize(u'%s%s/%s' % (self.baseurl, bibles_dir, filename))
self.max_progress += size self.max_progress += size
iterator += 1 iterator += 1
# Loop through the themes list and increase for each selected item # Loop through the themes list and increase for each selected item
@ -372,7 +392,7 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
item = self.themesListWidget.item(i) item = self.themesListWidget.item(i)
if item.checkState() == QtCore.Qt.Checked: if item.checkState() == QtCore.Qt.Checked:
filename = item.data(QtCore.Qt.UserRole).toString() filename = item.data(QtCore.Qt.UserRole).toString()
size = self._getFileSize(u'%s%s' % (self.web, filename)) size = self._getFileSize(u'%s%s/%s' % (self.baseurl, themes_dir, filename))
self.max_progress += size self.max_progress += size
if self.max_progress: if self.max_progress:
# Add on 2 for plugins status setting plus a "finished" point. # Add on 2 for plugins status setting plus a "finished" point.
@ -448,6 +468,11 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
unicode(gettempdir(), get_filesystem_encoding()), u'openlp') unicode(gettempdir(), get_filesystem_encoding()), u'openlp')
bibles_destination = AppLocation.get_section_data_path(u'bibles') bibles_destination = AppLocation.get_section_data_path(u'bibles')
themes_destination = AppLocation.get_section_data_path(u'themes') themes_destination = AppLocation.get_section_data_path(u'themes')
# Directory name appended to base download url as the name
# is found in download.cfg file.
songs_dir = unicode(self.config.get(u'songs', u'directory'), u'utf8')
bibles_dir = unicode(self.config.get(u'bibles', u'directory'), u'utf8')
themes_dir = unicode(self.config.get(u'themes', u'directory'), u'utf8')
# Download songs # Download songs
for i in xrange(self.songsListWidget.count()): for i in xrange(self.songsListWidget.count()):
item = self.songsListWidget.item(i) item = self.songsListWidget.item(i)
@ -457,7 +482,7 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
self.previous_size = 0 self.previous_size = 0
destination = os.path.join(songs_destination, destination = os.path.join(songs_destination,
unicode(filename)) unicode(filename))
self.urlGetFile(u'%s%s' % (self.web, filename), destination) self.urlGetFile(u'%s%s/%s' % (self.baseurl, songs_dir, filename), destination)
# Download Bibles # Download Bibles
bibles_iterator = QtGui.QTreeWidgetItemIterator( bibles_iterator = QtGui.QTreeWidgetItemIterator(
self.biblesTreeWidget) self.biblesTreeWidget)
@ -467,7 +492,7 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
bible = unicode(item.data(0, QtCore.Qt.UserRole).toString()) bible = unicode(item.data(0, QtCore.Qt.UserRole).toString())
self._incrementProgressBar(self.downloading % bible, 0) self._incrementProgressBar(self.downloading % bible, 0)
self.previous_size = 0 self.previous_size = 0
self.urlGetFile(u'%s%s' % (self.web, bible), self.urlGetFile(u'%s%s/%s' % (self.baseurl, bibles_dir, bible),
os.path.join(bibles_destination, bible)) os.path.join(bibles_destination, bible))
bibles_iterator += 1 bibles_iterator += 1
# Download themes # Download themes
@ -477,7 +502,7 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
theme = unicode(item.data(QtCore.Qt.UserRole).toString()) theme = unicode(item.data(QtCore.Qt.UserRole).toString())
self._incrementProgressBar(self.downloading % theme, 0) self._incrementProgressBar(self.downloading % theme, 0)
self.previous_size = 0 self.previous_size = 0
self.urlGetFile(u'%s%s' % (self.web, theme), self.urlGetFile(u'%s%s/%s' % (self.baseurl, themes_dir, theme),
os.path.join(themes_destination, theme)) os.path.join(themes_destination, theme))
# Set Default Display # Set Default Display
if self.displayComboBox.currentIndex() != -1: if self.displayComboBox.currentIndex() != -1: