Merge lp:~alisonken1/openlp/strings-common into lp:openlp

Proposed by Ken Roberts
Status: Merged
Approved by: Raoul Snyman
Approved revision: 2661
Merged at revision: 2660
Proposed branch: lp:~alisonken1/openlp/strings-common
Merge into: lp:openlp
Diff against target: 285 lines (+57/-34)
8 files modified
openlp/core/common/actions.py (+9/-7)
openlp/core/common/languagemanager.py (+6/-5)
openlp/core/common/openlpmixin.py (+3/-2)
openlp/core/common/registry.py (+6/-6)
openlp/core/common/settings.py (+5/-5)
openlp/core/common/uistrings.py (+4/-2)
openlp/core/common/versionchecker.py (+10/-7)
tests/functional/openlp_core_lib/test_projectordb.py (+14/-0)
To merge this branch: bzr merge lp:~alisonken1/openlp/strings-common
Reviewer Review Type Date Requested Status
Raoul Snyman Approve
Tim Bentley Approve
Review via email: mp+294739@code.launchpad.net

Commit message

openlp/core/common/*.py convert strings from python2 to python3 format

Description of the change

- Convert strings from python2 to python3 in openlp/core/common files
- Added another projector db test

python2: "%s inline" % 'text1'
python2: "%s inline %s" % ('text1', text2')
python3: "{text1} inline {text2}".format(text1="text1", text2="text2")

--------------------------------
lp:~alisonken1/openlp/strings-common (revision 2661)
[SUCCESS] https://ci.openlp.io/job/Branch-01-Pull/1550/
[SUCCESS] https://ci.openlp.io/job/Branch-02-Functional-Tests/1461/
[SUCCESS] https://ci.openlp.io/job/Branch-03-Interface-Tests/1399/
[SUCCESS] https://ci.openlp.io/job/Branch-04a-Windows_Functional_Tests/1181/
[SUCCESS] https://ci.openlp.io/job/Branch-04b-Windows_Interface_Tests/771/
[SUCCESS] https://ci.openlp.io/job/Branch-05a-Code_Analysis/839/
[SUCCESS] https://ci.openlp.io/job/Branch-05b-Test_Coverage/707/

To post a comment you must log in.
Revision history for this message
Tim Bentley (trb143) :
review: Approve
Revision history for this message
Raoul Snyman (raoul-snyman) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openlp/core/common/actions.py'
2--- openlp/core/common/actions.py 2016-03-31 16:34:22 +0000
3+++ openlp/core/common/actions.py 2016-05-15 20:11:40 +0000
4@@ -114,7 +114,7 @@
5 if item[1] == action:
6 self.actions.remove(item)
7 return
8- raise ValueError('Action "%s" does not exist.' % action)
9+ raise ValueError('Action "{action}" does not exist.'.format(action=action))
10
11
12 class CategoryList(object):
13@@ -138,7 +138,7 @@
14 for category in self.categories:
15 if category.name == key:
16 return category
17- raise KeyError('Category "%s" does not exist.' % key)
18+ raise KeyError('Category "{keY}" does not exist.'.format(key=key))
19
20 def __len__(self):
21 """
22@@ -203,7 +203,7 @@
23 if category.name == name:
24 self.categories.remove(category)
25 return
26- raise ValueError('Category "%s" does not exist.' % name)
27+ raise ValueError('Category "{name}" does not exist.'.format(name=name))
28
29
30 class ActionList(object):
31@@ -272,8 +272,9 @@
32 actions.append(action)
33 ActionList.shortcut_map[shortcuts[1]] = actions
34 else:
35- log.warning('Shortcut "%s" is removed from "%s" because another action already uses this shortcut.' %
36- (shortcuts[1], action.objectName()))
37+ log.warning('Shortcut "{shortcut}" is removed from "{action}" because another '
38+ 'action already uses this shortcut.'.format(shortcut=shortcuts[1],
39+ action=action.objectName()))
40 shortcuts.remove(shortcuts[1])
41 # Check the primary shortcut.
42 existing_actions = ActionList.shortcut_map.get(shortcuts[0], [])
43@@ -283,8 +284,9 @@
44 actions.append(action)
45 ActionList.shortcut_map[shortcuts[0]] = actions
46 else:
47- log.warning('Shortcut "%s" is removed from "%s" because another action already uses this shortcut.' %
48- (shortcuts[0], action.objectName()))
49+ log.warning('Shortcut "{shortcut}" is removed from "{action}" '
50+ 'because another action already uses this shortcut.'.format(shortcut=shortcuts[0],
51+ action=action.objectName()))
52 shortcuts.remove(shortcuts[0])
53 action.setShortcuts([QtGui.QKeySequence(shortcut) for shortcut in shortcuts])
54
55
56=== modified file 'openlp/core/common/languagemanager.py'
57--- openlp/core/common/languagemanager.py 2016-04-05 17:30:20 +0000
58+++ openlp/core/common/languagemanager.py 2016-05-15 20:11:40 +0000
59@@ -68,7 +68,7 @@
60 """
61 Find all available language files in this OpenLP install
62 """
63- log.debug('Translation files: %s', AppLocation.get_directory(AppLocation.LanguageDir))
64+ log.debug('Translation files: {files}'.format(files=AppLocation.get_directory(AppLocation.LanguageDir)))
65 trans_dir = QtCore.QDir(AppLocation.get_directory(AppLocation.LanguageDir))
66 file_names = trans_dir.entryList(['*.qm'], QtCore.QDir.Files, QtCore.QDir.Name)
67 # Remove qm files from the list which start with "qt_".
68@@ -93,7 +93,7 @@
69 """
70 language = Settings().value('core/language')
71 language = str(language)
72- log.info('Language file: \'%s\' Loaded from conf file' % language)
73+ log.info("Language file: '{language}' Loaded from conf file".format(language=language))
74 if re.match(r'[[].*[]]', language):
75 LanguageManager.auto_language = True
76 language = re.sub(r'[\[\]]', '', language)
77@@ -117,9 +117,9 @@
78 qm_list = LanguageManager.get_qm_list()
79 language = str(qm_list[action_name])
80 if LanguageManager.auto_language:
81- language = '[%s]' % language
82+ language = '[{language}]'.format(language=language)
83 Settings().setValue('core/language', language)
84- log.info('Language file: \'%s\' written to conf file' % language)
85+ log.info("Language file: '{language}' written to conf file".format(language=language))
86 if message:
87 QtWidgets.QMessageBox.information(None,
88 translate('OpenLP.LanguageManager', 'Language'),
89@@ -136,7 +136,8 @@
90 for counter, qmf in enumerate(qm_files):
91 reg_ex = QtCore.QRegExp("^.*i18n/(.*).qm")
92 if reg_ex.exactMatch(qmf):
93- name = '%s' % reg_ex.cap(1)
94+ name = '{regex}'.format(regex=reg_ex.cap(1))
95+ # TODO: Test before converting to python3 string format
96 LanguageManager.__qm_list__['%#2i %s' % (counter + 1, LanguageManager.language_name(qmf))] = name
97
98 @staticmethod
99
100=== modified file 'openlp/core/common/openlpmixin.py'
101--- openlp/core/common/openlpmixin.py 2015-12-31 22:46:06 +0000
102+++ openlp/core/common/openlpmixin.py 2016-05-15 20:11:40 +0000
103@@ -49,12 +49,13 @@
104 Code to added debug wrapper to work on called functions within a decorated class.
105 """
106 def wrapped(*args, **kwargs):
107- parent.logger.debug("Entering %s" % func.__name__)
108+ parent.logger.debug("Entering {function}".format(function=func.__name__))
109 try:
110 return func(*args, **kwargs)
111 except Exception as e:
112 if parent.logger.getEffectiveLevel() <= logging.ERROR:
113- parent.logger.error('Exception in %s : %s' % (func.__name__, e))
114+ parent.logger.error('Exception in {function} : {error}'.format(function=func.__name__,
115+ error=e))
116 raise e
117 return wrapped
118
119
120=== modified file 'openlp/core/common/registry.py'
121--- openlp/core/common/registry.py 2015-12-31 22:46:06 +0000
122+++ openlp/core/common/registry.py 2016-05-15 20:11:40 +0000
123@@ -71,8 +71,8 @@
124 else:
125 if not self.initialising:
126 trace_error_handler(log)
127- log.error('Service %s not found in list' % key)
128- raise KeyError('Service %s not found in list' % key)
129+ log.error('Service {key} not found in list'.format(key=key))
130+ raise KeyError('Service {key} not found in list'.format(key=key))
131
132 def register(self, key, reference):
133 """
134@@ -83,8 +83,8 @@
135 """
136 if key in self.service_list:
137 trace_error_handler(log)
138- log.error('Duplicate service exception %s' % key)
139- raise KeyError('Duplicate service exception %s' % key)
140+ log.error('Duplicate service exception {key}'.format(key=key))
141+ raise KeyError('Duplicate service exception {key}'.format(key=key))
142 else:
143 self.service_list[key] = reference
144
145@@ -140,8 +140,8 @@
146 except TypeError:
147 # Who has called me can help in debugging
148 trace_error_handler(log)
149- log.exception('Exception for function %s', function)
150+ log.exception('Exception for function {function}'.format(function=function))
151 else:
152 trace_error_handler(log)
153- log.error("Event %s called but not registered" % event)
154+ log.error("Event {event} called but not registered".format(event=event))
155 return results
156
157=== modified file 'openlp/core/common/settings.py'
158--- openlp/core/common/settings.py 2016-04-21 21:16:24 +0000
159+++ openlp/core/common/settings.py 2016-05-15 20:11:40 +0000
160@@ -487,16 +487,16 @@
161 # Do NOT do this anywhere else!
162 settings = QtCore.QSettings(self.fileName(), Settings.IniFormat)
163 settings.beginGroup(plugin.settings_section)
164- if settings.contains('%s count' % plugin.name):
165+ if settings.contains('{name} count'.format(name=plugin.name)):
166 # Get the count.
167- list_count = int(settings.value('%s count' % plugin.name, 0))
168+ list_count = int(settings.value('{name} count'.format(name=plugin.name), 0))
169 if list_count:
170 for counter in range(list_count):
171 # The keys were named e. g.: "image 0"
172- item = settings.value('%s %d' % (plugin.name, counter), '')
173+ item = settings.value('{name} {counter:d}'.format(name=plugin.name, counter=counter), '')
174 if item:
175 files_list.append(item)
176- settings.remove('%s %d' % (plugin.name, counter))
177- settings.remove('%s count' % plugin.name)
178+ settings.remove('{name} {counter:d}'.format(name=plugin.name, counter=counter))
179+ settings.remove('{name} count'.format(name=plugin.name))
180 settings.endGroup()
181 return files_list
182
183=== modified file 'openlp/core/common/uistrings.py'
184--- openlp/core/common/uistrings.py 2016-04-30 15:40:23 +0000
185+++ openlp/core/common/uistrings.py 2016-05-15 20:11:40 +0000
186@@ -80,6 +80,7 @@
187 self.Export = translate('OpenLP.Ui', 'Export')
188 self.File = translate('OpenLP.Ui', 'File')
189 self.FileNotFound = translate('OpenLP.Ui', 'File Not Found')
190+ # TODO: Check before converting to python3 string
191 self.FileNotFoundMessage = translate('OpenLP.Ui', 'File %s not found.\nPlease try selecting it individually.')
192 self.FontSizePtUnit = translate('OpenLP.Ui', 'pt', 'Abbreviated font pointsize unit')
193 self.Help = translate('OpenLP.Ui', 'Help')
194@@ -110,8 +111,8 @@
195 self.NISs = translate('OpenLP.Ui', 'No Item Selected', 'Singular')
196 self.NISp = translate('OpenLP.Ui', 'No Items Selected', 'Plural')
197 self.OLP = translate('OpenLP.Ui', 'OpenLP')
198- self.OLPV2 = "%s %s" % (self.OLP, "2")
199- self.OLPV2x = "%s %s" % (self.OLP, "2.4")
200+ self.OLPV2 = "{name} {version}".format(name=self.OLP, version="2")
201+ self.OLPV2x = "{name} {version}".format(name=self.OLP, version="2.4")
202 self.OpenLPStart = translate('OpenLP.Ui', 'OpenLP is already running. Do you wish to continue?')
203 self.OpenService = translate('OpenLP.Ui', 'Open service.')
204 self.PlaySlidesInLoop = translate('OpenLP.Ui', 'Play Slides in Loop')
205@@ -139,6 +140,7 @@
206 self.Split = translate('OpenLP.Ui', 'Optional &Split')
207 self.SplitToolTip = translate('OpenLP.Ui',
208 'Split a slide into two only if it does not fit on the screen as one slide.')
209+ # TODO: Check before converting to python3 string
210 self.StartTimeCode = translate('OpenLP.Ui', 'Start %s')
211 self.StopPlaySlidesInLoop = translate('OpenLP.Ui', 'Stop Play Slides in Loop')
212 self.StopPlaySlidesToEnd = translate('OpenLP.Ui', 'Stop Play Slides to End')
213
214=== modified file 'openlp/core/common/versionchecker.py'
215--- openlp/core/common/versionchecker.py 2016-04-05 20:07:57 +0000
216+++ openlp/core/common/versionchecker.py 2016-05-15 20:11:40 +0000
217@@ -44,9 +44,10 @@
218 log.debug('Version thread - run')
219 app_version = get_application_version()
220 version = check_latest_version(app_version)
221- log.debug("Versions %s and %s " % (LooseVersion(str(version)), LooseVersion(str(app_version['full']))))
222+ log.debug("Versions {version1} and {version2} ".format(version1=LooseVersion(str(version)),
223+ version2=LooseVersion(str(app_version['full']))))
224 if LooseVersion(str(version)) > LooseVersion(str(app_version['full'])):
225- self.main_window.openlp_version_check.emit('%s' % version)
226+ self.main_window.openlp_version_check.emit('{version}'.format(version=version))
227
228
229 def get_application_version():
230@@ -91,7 +92,7 @@
231 if tree_revision == tag_revision:
232 full_version = tag_version.strip()
233 else:
234- full_version = '%s-bzr%s' % (tag_version.strip(), tree_revision.strip())
235+ full_version = '{tag}-bzr{tree}'.format(tag=tag_version.strip(), tree=tree_revision.strip())
236 else:
237 # We're not running the development version, let's use the file.
238 file_path = AppLocation.get_directory(AppLocation.VersionDir)
239@@ -113,9 +114,10 @@
240 'build': bits[1] if len(bits) > 1 else None
241 }
242 if APPLICATION_VERSION['build']:
243- log.info('Openlp version %s build %s', APPLICATION_VERSION['version'], APPLICATION_VERSION['build'])
244+ log.info('Openlp version {version} build {build}'.format(version=APPLICATION_VERSION['version'],
245+ build=APPLICATION_VERSION['build']))
246 else:
247- log.info('Openlp version %s' % APPLICATION_VERSION['version'])
248+ log.info('Openlp version {version}'.format(version=APPLICATION_VERSION['version']))
249 return APPLICATION_VERSION
250
251
252@@ -149,8 +151,9 @@
253 req = urllib.request.Request('http://www.openlp.org/files/dev_version.txt')
254 else:
255 req = urllib.request.Request('http://www.openlp.org/files/version.txt')
256- req.add_header('User-Agent', 'OpenLP/%s %s/%s; ' % (current_version['full'], platform.system(),
257- platform.release()))
258+ req.add_header('User-Agent', 'OpenLP/{version} {system}/{release}; '.format(version=current_version['full'],
259+ system=platform.system(),
260+ release=platform.release()))
261 remote_version = None
262 retries = 0
263 while True:
264
265=== modified file 'tests/functional/openlp_core_lib/test_projectordb.py'
266--- tests/functional/openlp_core_lib/test_projectordb.py 2016-04-29 20:25:12 +0000
267+++ tests/functional/openlp_core_lib/test_projectordb.py 2016-05-15 20:11:40 +0000
268@@ -206,3 +206,17 @@
269 # THEN: __repr__ should return a proper string
270 self.assertEqual(str(manufacturer), '<Manufacturer(name="OpenLP Test")>',
271 'Manufacturer.__repr__() should have returned a proper representation string')
272+
273+ def model_repr_test(self):
274+ """
275+ Test model class __repr__ text
276+ """
277+ # GIVEN: Test object
278+ model = Model()
279+
280+ # WHEN: Name is set
281+ model.name = 'OpenLP Test'
282+
283+ # THEN: __repr__ should return a proper string
284+ self.assertEqual(str(model), '<Model(name='"OpenLP Test"')>',
285+ 'Model.__repr__() should have returned a proper representation string')