openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #29541
[Merge] lp:~alisonken1/openlp/strings_init into lp:openlp
Ken Roberts has proposed merging lp:~alisonken1/openlp/strings_init into lp:openlp.
Commit message:
Convert __init__.py files string format from python2 to python3
Requested reviews:
Raoul Snyman (raoul-snyman)
Tim Bentley (trb143)
For more details, see:
https://code.launchpad.net/~alisonken1/openlp/strings_init/+merge/293936
Convert __init__.py file strings from python2 to python3 format
Python2 "%s text" % value1
Python2 "%s text %s" % (value1, value2)
Python3 "{var1} text {var2:02d}".format(var1=text, var2=number)
- String conversions in init files
- Added test for projector power state change
- Remove extraneous print() call in mediainfo plugin
- Fix translate() string formatting
- Revert string format for re.compile() until further testing is done
- Skip crosswalk.com test until their server is fixed
-------------------------------
lp:~alisonken1/openlp/strings_init (revision 2658)
[SUCCESS] https://ci.openlp.io/job/Branch-01-Pull/1529/
[SUCCESS] https://ci.openlp.io/job/Branch-02-Functional-Tests/1440/
[SUCCESS] https://ci.openlp.io/job/Branch-03-Interface-Tests/1378/
[SUCCESS] https://ci.openlp.io/job/Branch-04a-Windows_Functional_Tests/1170/
[SUCCESS] https://ci.openlp.io/job/Branch-04b-Windows_Interface_Tests/761/
[SUCCESS] https://ci.openlp.io/job/Branch-05a-Code_Analysis/828/
[SUCCESS] https://ci.openlp.io/job/Branch-05b-Test_Coverage/696/
--
Your team OpenLP Core is subscribed to branch lp:openlp.
=== modified file 'openlp/core/__init__.py'
--- openlp/core/__init__.py 2016-04-04 19:53:54 +0000
+++ openlp/core/__init__.py 2016-05-05 19:46:33 +0000
@@ -222,10 +222,11 @@
QtWidgets.QMessageBox.warning(None, translate('OpenLP', 'Backup'),
translate('OpenLP', 'Backup of the data folder failed!'))
return
- QtWidgets.QMessageBox.information(None, translate('OpenLP', 'Backup'),
- translate('OpenLP',
- 'A backup of the data folder has been created at %s')
- % data_folder_backup_path)
+ message = translate('OpenLP',
+ 'A backup of the data folder has been created'
+ 'at {text}').format(text=data_folder_backup_path)
+ QtWidgets.QMessageBox.information(None, translate('OpenLP', 'Backup'), message)
+
# Update the version in the settings
Settings().setValue('core/application version', openlp_version)
@@ -257,7 +258,7 @@
"""
if event.type() == QtCore.QEvent.FileOpen:
file_name = event.file()
- log.debug('Got open file event for %s!', file_name)
+ log.debug('Got open file event for {name}!'.format(name=file_name))
self.args.insert(0, file_name)
return True
# Mac OS X should restore app window when user clicked on the OpenLP icon
@@ -311,7 +312,7 @@
logfile.setFormatter(logging.Formatter('%(asctime)s %(name)-55s %(levelname)-8s %(message)s'))
log.addHandler(logfile)
if log.isEnabledFor(logging.DEBUG):
- print('Logging to: %s' % filename)
+ print('Logging to: {name}'.format(name=filename))
def main(args=None):
@@ -351,12 +352,12 @@
log.info('Running portable')
portable_settings_file = os.path.abspath(os.path.join(application_path, '..', '..', 'Data', 'OpenLP.ini'))
# Make this our settings file
- log.info('INI file: %s', portable_settings_file)
+ log.info('INI file: {name}'.format(name=portable_settings_file))
Settings.set_filename(portable_settings_file)
portable_settings = Settings()
# Set our data path
data_path = os.path.abspath(os.path.join(application_path, '..', '..', 'Data',))
- log.info('Data path: %s', data_path)
+ log.info('Data path: {name}'.format(name=data_path))
# Point to our data path
portable_settings.setValue('advanced/data path', data_path)
portable_settings.setValue('advanced/is portable', True)
=== modified file 'openlp/core/common/__init__.py'
--- openlp/core/common/__init__.py 2016-04-22 16:37:21 +0000
+++ openlp/core/common/__init__.py 2016-05-05 19:46:33 +0000
@@ -55,7 +55,9 @@
"""
log_string = "OpenLP Error trace"
for tb in traceback.extract_stack():
- log_string = '%s\n File %s at line %d \n\t called %s' % (log_string, tb[0], tb[1], tb[3])
+ log_string += '\n File {file} at line {line} \n\t called {data}'.format(file=tb[0],
+ line=tb[1],
+ data=tb[3])
logger.error(log_string)
@@ -67,7 +69,7 @@
:param do_not_log: To not log anything. This is need for the start up, when the log isn't ready.
"""
if not do_not_log:
- log.debug('check_directory_exists %s' % directory)
+ log.debug('check_directory_exists {text}'.format(text=directory))
try:
if not os.path.exists(directory):
os.makedirs(directory)
@@ -202,13 +204,13 @@
:param data: OPTIONAL Data to hash
:returns: str
"""
- log.debug('md5_hash(salt="%s")' % salt)
+ log.debug('md5_hash(salt="{text}")'.format(text=salt))
hash_obj = hashlib.new('md5')
hash_obj.update(salt)
if data:
hash_obj.update(data)
hash_value = hash_obj.hexdigest()
- log.debug('md5_hash() returning "%s"' % hash_value)
+ log.debug('md5_hash() returning "{text}"'.format(text=hash_value))
return hash_value
@@ -221,12 +223,12 @@
:param data: OPTIONAL Data to hash
:returns: str
"""
- log.debug('qmd5_hash(salt="%s"' % salt)
+ log.debug('qmd5_hash(salt="{text}"'.format(text=salt))
hash_obj = QHash(QHash.Md5)
hash_obj.addData(salt)
hash_obj.addData(data)
hash_value = hash_obj.result().toHex()
- log.debug('qmd5_hash() returning "%s"' % hash_value)
+ log.debug('qmd5_hash() returning "{text}"'.format(text=hash_value))
return hash_value.data()
@@ -283,7 +285,7 @@
CONNECTION = '"--accept=pipe,name=openlp_pipe;urp;"'
else:
CONNECTION = '"--accept=socket,host=localhost,port=2002;urp;"'
- return '%s %s %s' % (command, OPTIONS, CONNECTION)
+ return '{cmd} {opt} {conn}'.format(cmd=command, opt=OPTIONS, conn=CONNECTION)
def get_uno_instance(resolver, connection_type='pipe'):
@@ -333,7 +335,7 @@
os.remove(file_path_name)
return True
except (IOError, OSError):
- log.exception("Unable to delete file %s" % file_path_name)
+ log.exception("Unable to delete file {text}".format(text=file_path_name))
return False
@@ -345,9 +347,11 @@
if not IMAGES_FILTER:
log.debug('Generating images filter.')
formats = list(map(bytes.decode, list(map(bytes, QtGui.QImageReader.supportedImageFormats()))))
- visible_formats = '(*.%s)' % '; *.'.join(formats)
- actual_formats = '(*.%s)' % ' *.'.join(formats)
- IMAGES_FILTER = '%s %s %s' % (translate('OpenLP', 'Image Files'), visible_formats, actual_formats)
+ visible_formats = '(*.{text})'.format(text='; *.'.join(formats))
+ actual_formats = '(*.{text})'.format(text=' *.'.join(formats))
+ IMAGES_FILTER = '{text} {visible} {actual}'.format(text=translate('OpenLP', 'Image Files'),
+ visible=visible_formats,
+ actual=actual_formats)
return IMAGES_FILTER
@@ -385,7 +389,7 @@
:param program_path:The full path to the binary to check.
:return: program output to be parsed
"""
- log.debug('testing program_path: %s', program_path)
+ log.debug('testing program_path: {text}'.format(text=program_path))
try:
# Setup startupinfo options for check_output to avoid console popping up on windows
if is_win():
@@ -399,5 +403,5 @@
except Exception:
trace_error_handler(log)
runlog = ''
- log.debug('check_output returned: %s' % runlog)
+ log.debug('check_output returned: {text}'.format(text=runlog))
return runlog
=== modified file 'openlp/core/lib/__init__.py'
--- openlp/core/lib/__init__.py 2016-04-17 19:32:15 +0000
+++ openlp/core/lib/__init__.py 2016-05-05 19:46:33 +0000
@@ -97,7 +97,7 @@
file_handle.seek(0)
content = file_handle.read()
except (IOError, UnicodeError):
- log.exception('Failed to open text file %s' % text_file)
+ log.exception('Failed to open text file {text}'.format(text=text_file))
finally:
if file_handle:
file_handle.close()
@@ -300,6 +300,8 @@
return ''
elif len(string_list) == 1:
return string_list[0]
+ # TODO:
+ # Cannot convert these strings to python3 yet until I can figure out how to mock translate() with the new format
elif len(string_list) == 2:
return translate('OpenLP.core.lib', '%s and %s',
'Locale list separator: 2 items') % (string_list[0], string_list[1])
=== modified file 'openlp/core/lib/projector/constants.py'
--- openlp/core/lib/projector/constants.py 2015-12-31 22:46:06 +0000
+++ openlp/core/lib/projector/constants.py 2016-05-05 19:46:33 +0000
@@ -297,7 +297,11 @@
PJLINK_POWR_STATUS = {'0': S_STANDBY,
'1': S_ON,
'2': S_COOLDOWN,
- '3': S_WARMUP}
+ '3': S_WARMUP,
+ S_STANDBY: '0',
+ S_ON: '1',
+ S_COOLDOWN: '2',
+ S_WARMUP: '3'}
PJLINK_DEFAULT_SOURCES = {'1': translate('OpenLP.DB', 'RGB'),
'2': translate('OpenLP.DB', 'Video'),
=== modified file 'openlp/core/ui/media/__init__.py'
--- openlp/core/ui/media/__init__.py 2016-04-13 18:38:49 +0000
+++ openlp/core/ui/media/__init__.py 2016-05-05 19:46:33 +0000
@@ -83,7 +83,7 @@
reg_ex = QtCore.QRegExp(".*\[(.*)\].*")
if Settings().value('media/override player') == QtCore.Qt.Checked:
if reg_ex.exactMatch(saved_players):
- overridden_player = '%s' % reg_ex.cap(1)
+ overridden_player = '{text}'.format(text=reg_ex.cap(1))
else:
overridden_player = 'auto'
else:
@@ -102,7 +102,7 @@
log.debug('set_media_players')
players = ','.join(players_list)
if Settings().value('media/override player') == QtCore.Qt.Checked and overridden_player != 'auto':
- players = players.replace(overridden_player, '[%s]' % overridden_player)
+ players = players.replace(overridden_player, '[{text}]'.format(text=overridden_player))
Settings().setValue('media/players', players)
@@ -113,7 +113,7 @@
:param input_string: The string to parse
:return: The elements extracted from the string: filename, title, audio_track, subtitle_track, start, end
"""
- log.debug('parse_optical_path, about to parse: "%s"' % input_string)
+ log.debug('parse_optical_path, about to parse: "{text}"'.format(text=input_string))
clip_info = input_string.split(sep=':')
title = int(clip_info[1])
audio_track = int(clip_info[2])
@@ -137,7 +137,10 @@
seconds, millis = divmod(milliseconds, 1000)
minutes, seconds = divmod(seconds, 60)
hours, minutes = divmod(minutes, 60)
- return "%02d:%02d:%02d,%03d" % (hours, minutes, seconds, millis)
+ return "{hours:02d}:{minutes:02d}:{seconds:02d},{millis:03d}".format(hours=hours,
+ minutes=minutes,
+ seconds=seconds,
+ millis=millis)
from .mediacontroller import MediaController
from .playertab import PlayerTab
=== modified file 'openlp/plugins/bibles/lib/__init__.py'
--- openlp/plugins/bibles/lib/__init__.py 2015-12-31 22:46:06 +0000
+++ openlp/plugins/bibles/lib/__init__.py 2016-05-05 19:46:33 +0000
@@ -211,19 +211,21 @@
while '||' in source_string:
source_string = source_string.replace('||', '|')
if role != 'e':
- REFERENCE_SEPARATORS['sep_%s_display' % role] = source_string.split('|')[0]
+ REFERENCE_SEPARATORS['sep_{role}_display'.format(role=role)] = source_string.split('|')[0]
# escape reserved characters
for character in '\\.^$*+?{}[]()':
source_string = source_string.replace(character, '\\' + character)
# add various unicode alternatives
source_string = source_string.replace('-', '(?:[-\u00AD\u2010\u2011\u2012\u2014\u2014\u2212\uFE63\uFF0D])')
source_string = source_string.replace(',', '(?:[,\u201A])')
- REFERENCE_SEPARATORS['sep_%s' % role] = '\s*(?:%s)\s*' % source_string
- REFERENCE_SEPARATORS['sep_%s_default' % role] = default_separators[index]
+ REFERENCE_SEPARATORS['sep_{role}'.format(role=role)] = '\s*(?:{source})\s*'.format(source=source_string)
+ REFERENCE_SEPARATORS['sep_{role}_default'.format(role=role)] = default_separators[index]
# verse range match: (<chapter>:)?<verse>(-((<chapter>:)?<verse>|end)?)?
+ # TODO: Check before converting this string
range_regex = '(?:(?P<from_chapter>[0-9]+)%(sep_v)s)?' \
'(?P<from_verse>[0-9]+)(?P<range_to>%(sep_r)s(?:(?:(?P<to_chapter>' \
'[0-9]+)%(sep_v)s)?(?P<to_verse>[0-9]+)|%(sep_e)s)?)?' % REFERENCE_SEPARATORS
+ # TODO: Test before converting re.compile strings
REFERENCE_MATCHES['range'] = re.compile('^\s*%s\s*$' % range_regex, re.UNICODE)
REFERENCE_MATCHES['range_separator'] = re.compile(REFERENCE_SEPARATORS['sep_l'], re.UNICODE)
# full reference match: <book>(<range>(,(?!$)|(?=$)))+
@@ -331,10 +333,10 @@
separator.
"""
- log.debug('parse_reference("%s")', reference)
+ log.debug('parse_reference("{text}")'.format(text=reference))
match = get_reference_match('full').match(reference)
if match:
- log.debug('Matched reference %s' % reference)
+ log.debug('Matched reference {text}'.format(text=reference))
book = match.group('book')
if not book_ref_id:
book_ref_id = bible.get_book_ref_id_by_localised_name(book, language_selection)
@@ -400,7 +402,7 @@
ref_list.append((book_ref_id, from_chapter, 1, -1))
return ref_list
else:
- log.debug('Invalid reference: %s' % reference)
+ log.debug('Invalid reference: {text}'.format(text=reference))
return None
=== modified file 'openlp/plugins/media/mediaplugin.py'
--- openlp/plugins/media/mediaplugin.py 2016-04-21 16:26:34 +0000
+++ openlp/plugins/media/mediaplugin.py 2016-05-05 19:46:33 +0000
@@ -160,7 +160,6 @@
"""
program_type = None
runlog = check_binary_exists(program_path)
- print(runlog, type(runlog))
# Analyse the output to see it the program is mediainfo
for line in runlog.splitlines():
decoded_line = line.decode()
=== modified file 'tests/functional/openlp_core_lib/test_projector_pjlink1.py'
--- tests/functional/openlp_core_lib/test_projector_pjlink1.py 2016-04-22 11:41:29 +0000
+++ tests/functional/openlp_core_lib/test_projector_pjlink1.py 2016-05-05 19:46:33 +0000
@@ -26,7 +26,8 @@
from unittest import TestCase
from openlp.core.lib.projector.pjlink1 import PJLink1
-from openlp.core.lib.projector.constants import E_PARAMETER, ERROR_STRING
+from openlp.core.lib.projector.constants import E_PARAMETER, ERROR_STRING, S_OFF, S_STANDBY, S_WARMUP, S_ON, \
+ S_COOLDOWN, PJLINK_POWR_STATUS
from tests.functional import patch
from tests.resources.projector.data import TEST_PIN, TEST_SALT, TEST_CONNECT_AUTHENTICATE
@@ -151,3 +152,33 @@
'Lamp 3 power status should have been set to TRUE')
self.assertEquals(pjlink.lamp[2]['Hours'], 33333,
'Lamp 3 hours should have been set to 33333')
+
+ @patch.object(pjlink_test, 'projectorReceivedData')
+ def projector_process_power_on_test(self, mock_projectorReceivedData):
+ """
+ Test setting power to ON
+ """
+ # GIVEN: Test object and preset
+ pjlink = pjlink_test
+ pjlink.power = S_STANDBY
+
+ # WHEN: Call process_command with turn power on command
+ pjlink.process_command('POWR', PJLINK_POWR_STATUS[S_ON])
+
+ # THEN: Power should be set to ON
+ self.assertEquals(pjlink.power, S_ON, 'Power should have been set to ON')
+
+ @patch.object(pjlink_test, 'projectorReceivedData')
+ def projector_process_power_off_test(self, mock_projectorReceivedData):
+ """
+ Test setting power to STANDBY
+ """
+ # GIVEN: Test object and preset
+ pjlink = pjlink_test
+ pjlink.power = S_ON
+
+ # WHEN: Call process_command with turn power on command
+ pjlink.process_command('POWR', PJLINK_POWR_STATUS[S_STANDBY])
+
+ # THEN: Power should be set to STANDBY
+ self.assertEquals(pjlink.power, S_STANDBY, 'Power should have been set to STANDBY')
=== modified file 'tests/interfaces/openlp_plugins/bibles/test_lib_http.py'
--- tests/interfaces/openlp_plugins/bibles/test_lib_http.py 2016-01-07 21:38:13 +0000
+++ tests/interfaces/openlp_plugins/bibles/test_lib_http.py 2016-05-05 19:46:33 +0000
@@ -22,7 +22,7 @@
"""
Package to test the openlp.plugin.bible.lib.https package.
"""
-from unittest import TestCase
+from unittest import TestCase, skip
from openlp.core.common import Registry
from openlp.plugins.bibles.lib.http import BGExtract, CWExtract, BSExtract
@@ -146,6 +146,7 @@
self.assertIsNotNone(bibles)
self.assertIn(('Holman Christian Standard Bible', 'HCSB', 'en'), bibles)
+ @skip("Waiting for Crosswalk to fix their server")
def crosswalk_get_bibles_test(self):
"""
Test getting list of bibles from Crosswalk.com
=== modified file 'tests/utils/__init__.py'
--- tests/utils/__init__.py 2015-12-31 22:46:06 +0000
+++ tests/utils/__init__.py 2016-05-05 19:46:33 +0000
@@ -26,7 +26,7 @@
def assert_length(expected, iterable, msg=None):
if len(iterable) != expected:
if not msg:
- msg = 'Expected length %s, got %s' % (expected, len(iterable))
+ msg = 'Expected length {expected}, got {got}'.format(expected=expected, got=len(iterable))
raise AssertionError(msg)
Follow ups