← Back to team overview

openlp-core team mailing list archive

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

 

Ken Roberts has proposed merging lp:~alisonken1/openlp/strings-common into lp:openlp.

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

Requested reviews:
  OpenLP Core (openlp-core)

For more details, see:
https://code.launchpad.net/~alisonken1/openlp/strings-common/+merge/294739

- 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/

-- 
Your team OpenLP Core is requested to review the proposed merge of lp:~alisonken1/openlp/strings-common into lp:openlp.
=== modified file 'openlp/core/common/actions.py'
--- openlp/core/common/actions.py	2016-03-31 16:34:22 +0000
+++ openlp/core/common/actions.py	2016-05-15 20:11:40 +0000
@@ -114,7 +114,7 @@
             if item[1] == action:
                 self.actions.remove(item)
                 return
-        raise ValueError('Action "%s" does not exist.' % action)
+        raise ValueError('Action "{action}" does not exist.'.format(action=action))
 
 
 class CategoryList(object):
@@ -138,7 +138,7 @@
         for category in self.categories:
             if category.name == key:
                 return category
-        raise KeyError('Category "%s" does not exist.' % key)
+        raise KeyError('Category "{keY}" does not exist.'.format(key=key))
 
     def __len__(self):
         """
@@ -203,7 +203,7 @@
             if category.name == name:
                 self.categories.remove(category)
                 return
-        raise ValueError('Category "%s" does not exist.' % name)
+        raise ValueError('Category "{name}" does not exist.'.format(name=name))
 
 
 class ActionList(object):
@@ -272,8 +272,9 @@
                 actions.append(action)
                 ActionList.shortcut_map[shortcuts[1]] = actions
             else:
-                log.warning('Shortcut "%s" is removed from "%s" because another action already uses this shortcut.' %
-                            (shortcuts[1], action.objectName()))
+                log.warning('Shortcut "{shortcut}" is removed from "{action}" because another '
+                            'action already uses this shortcut.'.format(shortcut=shortcuts[1],
+                                                                        action=action.objectName()))
                 shortcuts.remove(shortcuts[1])
         # Check the primary shortcut.
         existing_actions = ActionList.shortcut_map.get(shortcuts[0], [])
@@ -283,8 +284,9 @@
             actions.append(action)
             ActionList.shortcut_map[shortcuts[0]] = actions
         else:
-            log.warning('Shortcut "%s" is removed from "%s" because another action already uses this shortcut.' %
-                        (shortcuts[0], action.objectName()))
+            log.warning('Shortcut "{shortcut}" is removed from "{action}" '
+                        'because another action already uses this shortcut.'.format(shortcut=shortcuts[0],
+                                                                                    action=action.objectName()))
             shortcuts.remove(shortcuts[0])
         action.setShortcuts([QtGui.QKeySequence(shortcut) for shortcut in shortcuts])
 

=== modified file 'openlp/core/common/languagemanager.py'
--- openlp/core/common/languagemanager.py	2016-04-05 17:30:20 +0000
+++ openlp/core/common/languagemanager.py	2016-05-15 20:11:40 +0000
@@ -68,7 +68,7 @@
         """
         Find all available language files in this OpenLP install
         """
-        log.debug('Translation files: %s', AppLocation.get_directory(AppLocation.LanguageDir))
+        log.debug('Translation files: {files}'.format(files=AppLocation.get_directory(AppLocation.LanguageDir)))
         trans_dir = QtCore.QDir(AppLocation.get_directory(AppLocation.LanguageDir))
         file_names = trans_dir.entryList(['*.qm'], QtCore.QDir.Files, QtCore.QDir.Name)
         # Remove qm files from the list which start with "qt_".
@@ -93,7 +93,7 @@
         """
         language = Settings().value('core/language')
         language = str(language)
-        log.info('Language file: \'%s\' Loaded from conf file' % language)
+        log.info("Language file: '{language}' Loaded from conf file".format(language=language))
         if re.match(r'[[].*[]]', language):
             LanguageManager.auto_language = True
             language = re.sub(r'[\[\]]', '', language)
@@ -117,9 +117,9 @@
                 qm_list = LanguageManager.get_qm_list()
                 language = str(qm_list[action_name])
         if LanguageManager.auto_language:
-            language = '[%s]' % language
+            language = '[{language}]'.format(language=language)
         Settings().setValue('core/language', language)
-        log.info('Language file: \'%s\' written to conf file' % language)
+        log.info("Language file: '{language}' written to conf file".format(language=language))
         if message:
             QtWidgets.QMessageBox.information(None,
                                               translate('OpenLP.LanguageManager', 'Language'),
@@ -136,7 +136,8 @@
         for counter, qmf in enumerate(qm_files):
             reg_ex = QtCore.QRegExp("^.*i18n/(.*).qm")
             if reg_ex.exactMatch(qmf):
-                name = '%s' % reg_ex.cap(1)
+                name = '{regex}'.format(regex=reg_ex.cap(1))
+                # TODO: Test before converting to python3 string format
                 LanguageManager.__qm_list__['%#2i %s' % (counter + 1, LanguageManager.language_name(qmf))] = name
 
     @staticmethod

=== modified file 'openlp/core/common/openlpmixin.py'
--- openlp/core/common/openlpmixin.py	2015-12-31 22:46:06 +0000
+++ openlp/core/common/openlpmixin.py	2016-05-15 20:11:40 +0000
@@ -49,12 +49,13 @@
         Code to added debug wrapper to work on called functions within a decorated class.
         """
         def wrapped(*args, **kwargs):
-            parent.logger.debug("Entering %s" % func.__name__)
+            parent.logger.debug("Entering {function}".format(function=func.__name__))
             try:
                 return func(*args, **kwargs)
             except Exception as e:
                 if parent.logger.getEffectiveLevel() <= logging.ERROR:
-                    parent.logger.error('Exception in %s : %s' % (func.__name__, e))
+                    parent.logger.error('Exception in {function} : {error}'.format(function=func.__name__,
+                                                                                   error=e))
                 raise e
         return wrapped
 

=== modified file 'openlp/core/common/registry.py'
--- openlp/core/common/registry.py	2015-12-31 22:46:06 +0000
+++ openlp/core/common/registry.py	2016-05-15 20:11:40 +0000
@@ -71,8 +71,8 @@
         else:
             if not self.initialising:
                 trace_error_handler(log)
-                log.error('Service %s not found in list' % key)
-                raise KeyError('Service %s not found in list' % key)
+                log.error('Service {key} not found in list'.format(key=key))
+                raise KeyError('Service {key} not found in list'.format(key=key))
 
     def register(self, key, reference):
         """
@@ -83,8 +83,8 @@
         """
         if key in self.service_list:
             trace_error_handler(log)
-            log.error('Duplicate service exception %s' % key)
-            raise KeyError('Duplicate service exception %s' % key)
+            log.error('Duplicate service exception {key}'.format(key=key))
+            raise KeyError('Duplicate service exception {key}'.format(key=key))
         else:
             self.service_list[key] = reference
 
@@ -140,8 +140,8 @@
                 except TypeError:
                     # Who has called me can help in debugging
                     trace_error_handler(log)
-                    log.exception('Exception for function %s', function)
+                    log.exception('Exception for function {function}'.format(function=function))
         else:
             trace_error_handler(log)
-            log.error("Event %s called but not registered" % event)
+            log.error("Event {event} called but not registered".format(event=event))
         return results

=== modified file 'openlp/core/common/settings.py'
--- openlp/core/common/settings.py	2016-04-21 21:16:24 +0000
+++ openlp/core/common/settings.py	2016-05-15 20:11:40 +0000
@@ -487,16 +487,16 @@
         # Do NOT do this anywhere else!
         settings = QtCore.QSettings(self.fileName(), Settings.IniFormat)
         settings.beginGroup(plugin.settings_section)
-        if settings.contains('%s count' % plugin.name):
+        if settings.contains('{name} count'.format(name=plugin.name)):
             # Get the count.
-            list_count = int(settings.value('%s count' % plugin.name, 0))
+            list_count = int(settings.value('{name} count'.format(name=plugin.name), 0))
             if list_count:
                 for counter in range(list_count):
                     # The keys were named e. g.: "image 0"
-                    item = settings.value('%s %d' % (plugin.name, counter), '')
+                    item = settings.value('{name} {counter:d}'.format(name=plugin.name, counter=counter), '')
                     if item:
                         files_list.append(item)
-                    settings.remove('%s %d' % (plugin.name, counter))
-            settings.remove('%s count' % plugin.name)
+                    settings.remove('{name} {counter:d}'.format(name=plugin.name, counter=counter))
+            settings.remove('{name} count'.format(name=plugin.name))
         settings.endGroup()
         return files_list

=== modified file 'openlp/core/common/uistrings.py'
--- openlp/core/common/uistrings.py	2016-04-30 15:40:23 +0000
+++ openlp/core/common/uistrings.py	2016-05-15 20:11:40 +0000
@@ -80,6 +80,7 @@
         self.Export = translate('OpenLP.Ui', 'Export')
         self.File = translate('OpenLP.Ui', 'File')
         self.FileNotFound = translate('OpenLP.Ui', 'File Not Found')
+        # TODO: Check before converting to python3 string
         self.FileNotFoundMessage = translate('OpenLP.Ui', 'File %s not found.\nPlease try selecting it individually.')
         self.FontSizePtUnit = translate('OpenLP.Ui', 'pt', 'Abbreviated font pointsize unit')
         self.Help = translate('OpenLP.Ui', 'Help')
@@ -110,8 +111,8 @@
         self.NISs = translate('OpenLP.Ui', 'No Item Selected', 'Singular')
         self.NISp = translate('OpenLP.Ui', 'No Items Selected', 'Plural')
         self.OLP = translate('OpenLP.Ui', 'OpenLP')
-        self.OLPV2 = "%s %s" % (self.OLP, "2")
-        self.OLPV2x = "%s %s" % (self.OLP, "2.4")
+        self.OLPV2 = "{name} {version}".format(name=self.OLP, version="2")
+        self.OLPV2x = "{name} {version}".format(name=self.OLP, version="2.4")
         self.OpenLPStart = translate('OpenLP.Ui', 'OpenLP is already running. Do you wish to continue?')
         self.OpenService = translate('OpenLP.Ui', 'Open service.')
         self.PlaySlidesInLoop = translate('OpenLP.Ui', 'Play Slides in Loop')
@@ -139,6 +140,7 @@
         self.Split = translate('OpenLP.Ui', 'Optional &Split')
         self.SplitToolTip = translate('OpenLP.Ui',
                                       'Split a slide into two only if it does not fit on the screen as one slide.')
+        # TODO: Check before converting to python3 string
         self.StartTimeCode = translate('OpenLP.Ui', 'Start %s')
         self.StopPlaySlidesInLoop = translate('OpenLP.Ui', 'Stop Play Slides in Loop')
         self.StopPlaySlidesToEnd = translate('OpenLP.Ui', 'Stop Play Slides to End')

=== modified file 'openlp/core/common/versionchecker.py'
--- openlp/core/common/versionchecker.py	2016-04-05 20:07:57 +0000
+++ openlp/core/common/versionchecker.py	2016-05-15 20:11:40 +0000
@@ -44,9 +44,10 @@
         log.debug('Version thread - run')
         app_version = get_application_version()
         version = check_latest_version(app_version)
-        log.debug("Versions %s and %s " % (LooseVersion(str(version)), LooseVersion(str(app_version['full']))))
+        log.debug("Versions {version1} and {version2} ".format(version1=LooseVersion(str(version)),
+                                                               version2=LooseVersion(str(app_version['full']))))
         if LooseVersion(str(version)) > LooseVersion(str(app_version['full'])):
-            self.main_window.openlp_version_check.emit('%s' % version)
+            self.main_window.openlp_version_check.emit('{version}'.format(version=version))
 
 
 def get_application_version():
@@ -91,7 +92,7 @@
         if tree_revision == tag_revision:
             full_version = tag_version.strip()
         else:
-            full_version = '%s-bzr%s' % (tag_version.strip(), tree_revision.strip())
+            full_version = '{tag}-bzr{tree}'.format(tag=tag_version.strip(), tree=tree_revision.strip())
     else:
         # We're not running the development version, let's use the file.
         file_path = AppLocation.get_directory(AppLocation.VersionDir)
@@ -113,9 +114,10 @@
         'build': bits[1] if len(bits) > 1 else None
     }
     if APPLICATION_VERSION['build']:
-        log.info('Openlp version %s build %s', APPLICATION_VERSION['version'], APPLICATION_VERSION['build'])
+        log.info('Openlp version {version} build {build}'.format(version=APPLICATION_VERSION['version'],
+                                                                 build=APPLICATION_VERSION['build']))
     else:
-        log.info('Openlp version %s' % APPLICATION_VERSION['version'])
+        log.info('Openlp version {version}'.format(version=APPLICATION_VERSION['version']))
     return APPLICATION_VERSION
 
 
@@ -149,8 +151,9 @@
                 req = urllib.request.Request('http://www.openlp.org/files/dev_version.txt')
             else:
                 req = urllib.request.Request('http://www.openlp.org/files/version.txt')
-        req.add_header('User-Agent', 'OpenLP/%s %s/%s; ' % (current_version['full'], platform.system(),
-                                                            platform.release()))
+        req.add_header('User-Agent', 'OpenLP/{version} {system}/{release}; '.format(version=current_version['full'],
+                                                                                    system=platform.system(),
+                                                                                    release=platform.release()))
         remote_version = None
         retries = 0
         while True:

=== modified file 'tests/functional/openlp_core_lib/test_projectordb.py'
--- tests/functional/openlp_core_lib/test_projectordb.py	2016-04-29 20:25:12 +0000
+++ tests/functional/openlp_core_lib/test_projectordb.py	2016-05-15 20:11:40 +0000
@@ -206,3 +206,17 @@
         # THEN: __repr__ should return a proper string
         self.assertEqual(str(manufacturer), '<Manufacturer(name="OpenLP Test")>',
                          'Manufacturer.__repr__() should have returned a proper representation string')
+
+    def model_repr_test(self):
+        """
+        Test model class __repr__ text
+        """
+        # GIVEN: Test object
+        model = Model()
+
+        # WHEN: Name is set
+        model.name = 'OpenLP Test'
+
+        # THEN: __repr__ should return a proper string
+        self.assertEqual(str(model), '<Model(name='"OpenLP Test"')>',
+                         'Model.__repr__() should have returned a proper representation string')


Follow ups