forked from openlp/openlp
Bug #1160506 - wrap url constructions into join_url() function.
This commit is contained in:
parent
caf1290a16
commit
1c4c2e3636
@ -42,7 +42,8 @@ from PyQt4 import QtCore, QtGui
|
|||||||
from openlp.core.lib import translate, PluginStatus, Receiver, build_icon, \
|
from openlp.core.lib import translate, PluginStatus, Receiver, build_icon, \
|
||||||
check_directory_exists
|
check_directory_exists
|
||||||
from openlp.core.lib.settings import Settings
|
from openlp.core.lib.settings import Settings
|
||||||
from openlp.core.utils import get_web_page, AppLocation, get_filesystem_encoding
|
from openlp.core.utils import get_web_page, AppLocation, join_url, \
|
||||||
|
get_filesystem_encoding
|
||||||
from firsttimewizard import Ui_FirstTimeWizard, FirstTimePage
|
from firsttimewizard import Ui_FirstTimeWizard, FirstTimePage
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
@ -68,7 +69,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().baseurl, themes_dir + '/' + screenshot),
|
urllib.urlretrieve(join_url(self.parent().baseurl,
|
||||||
|
themes_dir, screenshot),
|
||||||
os.path.join(tmp_dir, screenshot))
|
os.path.join(tmp_dir, 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))
|
||||||
@ -103,9 +105,6 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
|
|||||||
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')
|
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',
|
||||||
@ -374,7 +373,7 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
|
|||||||
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/%s' % (self.baseurl, songs_dir, filename))
|
size = self._getFileSize(join_url(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)
|
||||||
@ -383,7 +382,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/%s' % (self.baseurl, bibles_dir, filename))
|
size = self._getFileSize(join_url(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
|
||||||
@ -392,7 +391,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/%s' % (self.baseurl, themes_dir, filename))
|
size = self._getFileSize(join_url(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.
|
||||||
@ -482,7 +481,8 @@ 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/%s' % (self.baseurl, songs_dir, filename), destination)
|
self.urlGetFile(join_url(self.baseurl, songs_dir, filename),
|
||||||
|
destination)
|
||||||
# Download Bibles
|
# Download Bibles
|
||||||
bibles_iterator = QtGui.QTreeWidgetItemIterator(
|
bibles_iterator = QtGui.QTreeWidgetItemIterator(
|
||||||
self.biblesTreeWidget)
|
self.biblesTreeWidget)
|
||||||
@ -492,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/%s' % (self.baseurl, bibles_dir, bible),
|
self.urlGetFile(join_url(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
|
||||||
@ -502,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/%s' % (self.baseurl, themes_dir, theme),
|
self.urlGetFile(join_url(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:
|
||||||
|
@ -37,6 +37,7 @@ import re
|
|||||||
from subprocess import Popen, PIPE
|
from subprocess import Popen, PIPE
|
||||||
import sys
|
import sys
|
||||||
import urllib2
|
import urllib2
|
||||||
|
import urlparse
|
||||||
|
|
||||||
from openlp.core.lib.settings import Settings
|
from openlp.core.lib.settings import Settings
|
||||||
|
|
||||||
@ -364,6 +365,25 @@ def get_images_filter():
|
|||||||
return IMAGES_FILTER
|
return IMAGES_FILTER
|
||||||
|
|
||||||
|
|
||||||
|
def join_url(base, *args):
|
||||||
|
"""
|
||||||
|
Join one or more url components with the base url.
|
||||||
|
|
||||||
|
``base``
|
||||||
|
Base url containing top level domain.
|
||||||
|
e.g. http://www.example.org
|
||||||
|
|
||||||
|
``args``
|
||||||
|
url components to be appended to the base url.
|
||||||
|
"""
|
||||||
|
# Remove leading and trailing slash from components.
|
||||||
|
# Also ensure QString is converted to unicode().
|
||||||
|
args = [unicode(x).strip('/') for x in args]
|
||||||
|
url = urlparse.urljoin(base, '/'.join(args))
|
||||||
|
print url
|
||||||
|
return url
|
||||||
|
|
||||||
|
|
||||||
def split_filename(path):
|
def split_filename(path):
|
||||||
"""
|
"""
|
||||||
Return a list of the parts in a given path.
|
Return a list of the parts in a given path.
|
||||||
|
Loading…
Reference in New Issue
Block a user