forked from openlp/openlp
Convert strings to python3 in __init__ files
This commit is contained in:
parent
f0d75a29c2
commit
c1222dc2bb
@ -222,10 +222,11 @@ class OpenLP(OpenLPMixin, QtWidgets.QApplication):
|
|||||||
QtWidgets.QMessageBox.warning(None, translate('OpenLP', 'Backup'),
|
QtWidgets.QMessageBox.warning(None, translate('OpenLP', 'Backup'),
|
||||||
translate('OpenLP', 'Backup of the data folder failed!'))
|
translate('OpenLP', 'Backup of the data folder failed!'))
|
||||||
return
|
return
|
||||||
QtWidgets.QMessageBox.information(None, translate('OpenLP', 'Backup'),
|
message = translate('OpenLP',
|
||||||
translate('OpenLP',
|
'A backup of the data folder has been created'
|
||||||
'A backup of the data folder has been created at %s')
|
'at {text}'.format(text=data_folder_backup_path))
|
||||||
% data_folder_backup_path)
|
QtWidgets.QMessageBox.information(None, translate('OpenLP', 'Backup'), message)
|
||||||
|
|
||||||
# Update the version in the settings
|
# Update the version in the settings
|
||||||
Settings().setValue('core/application version', openlp_version)
|
Settings().setValue('core/application version', openlp_version)
|
||||||
|
|
||||||
@ -257,7 +258,7 @@ class OpenLP(OpenLPMixin, QtWidgets.QApplication):
|
|||||||
"""
|
"""
|
||||||
if event.type() == QtCore.QEvent.FileOpen:
|
if event.type() == QtCore.QEvent.FileOpen:
|
||||||
file_name = event.file()
|
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)
|
self.args.insert(0, file_name)
|
||||||
return True
|
return True
|
||||||
# Mac OS X should restore app window when user clicked on the OpenLP icon
|
# Mac OS X should restore app window when user clicked on the OpenLP icon
|
||||||
@ -311,7 +312,7 @@ def set_up_logging(log_path):
|
|||||||
logfile.setFormatter(logging.Formatter('%(asctime)s %(name)-55s %(levelname)-8s %(message)s'))
|
logfile.setFormatter(logging.Formatter('%(asctime)s %(name)-55s %(levelname)-8s %(message)s'))
|
||||||
log.addHandler(logfile)
|
log.addHandler(logfile)
|
||||||
if log.isEnabledFor(logging.DEBUG):
|
if log.isEnabledFor(logging.DEBUG):
|
||||||
print('Logging to: %s' % filename)
|
print('Logging to: {name}'.format(name=filename))
|
||||||
|
|
||||||
|
|
||||||
def main(args=None):
|
def main(args=None):
|
||||||
@ -351,12 +352,12 @@ def main(args=None):
|
|||||||
log.info('Running portable')
|
log.info('Running portable')
|
||||||
portable_settings_file = os.path.abspath(os.path.join(application_path, '..', '..', 'Data', 'OpenLP.ini'))
|
portable_settings_file = os.path.abspath(os.path.join(application_path, '..', '..', 'Data', 'OpenLP.ini'))
|
||||||
# Make this our settings file
|
# 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)
|
Settings.set_filename(portable_settings_file)
|
||||||
portable_settings = Settings()
|
portable_settings = Settings()
|
||||||
# Set our data path
|
# Set our data path
|
||||||
data_path = os.path.abspath(os.path.join(application_path, '..', '..', 'Data',))
|
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
|
# Point to our data path
|
||||||
portable_settings.setValue('advanced/data path', data_path)
|
portable_settings.setValue('advanced/data path', data_path)
|
||||||
portable_settings.setValue('advanced/is portable', True)
|
portable_settings.setValue('advanced/is portable', True)
|
||||||
|
@ -53,7 +53,10 @@ def trace_error_handler(logger):
|
|||||||
"""
|
"""
|
||||||
log_string = "OpenLP Error trace"
|
log_string = "OpenLP Error trace"
|
||||||
for tb in traceback.extract_stack():
|
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 = '{text}\n File {file} at line {line} \n\t called {data}'.format(text=log_string,
|
||||||
|
file=tb[0],
|
||||||
|
line=tb[1],
|
||||||
|
data=tb[3])
|
||||||
logger.error(log_string)
|
logger.error(log_string)
|
||||||
|
|
||||||
|
|
||||||
@ -65,7 +68,7 @@ def check_directory_exists(directory, do_not_log=False):
|
|||||||
:param do_not_log: To not log anything. This is need for the start up, when the log isn't ready.
|
: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:
|
if not do_not_log:
|
||||||
log.debug('check_directory_exists %s' % directory)
|
log.debug('check_directory_exists {text}'.format(text=directory))
|
||||||
try:
|
try:
|
||||||
if not os.path.exists(directory):
|
if not os.path.exists(directory):
|
||||||
os.makedirs(directory)
|
os.makedirs(directory)
|
||||||
@ -200,13 +203,13 @@ def md5_hash(salt, data=None):
|
|||||||
:param data: OPTIONAL Data to hash
|
:param data: OPTIONAL Data to hash
|
||||||
:returns: str
|
: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 = hashlib.new('md5')
|
||||||
hash_obj.update(salt)
|
hash_obj.update(salt)
|
||||||
if data:
|
if data:
|
||||||
hash_obj.update(data)
|
hash_obj.update(data)
|
||||||
hash_value = hash_obj.hexdigest()
|
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
|
return hash_value
|
||||||
|
|
||||||
|
|
||||||
@ -219,12 +222,12 @@ def qmd5_hash(salt, data=None):
|
|||||||
:param data: OPTIONAL Data to hash
|
:param data: OPTIONAL Data to hash
|
||||||
:returns: str
|
: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 = QHash(QHash.Md5)
|
||||||
hash_obj.addData(salt)
|
hash_obj.addData(salt)
|
||||||
hash_obj.addData(data)
|
hash_obj.addData(data)
|
||||||
hash_value = hash_obj.result().toHex()
|
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()
|
return hash_value.data()
|
||||||
|
|
||||||
|
|
||||||
@ -340,9 +343,11 @@ def get_images_filter():
|
|||||||
if not IMAGES_FILTER:
|
if not IMAGES_FILTER:
|
||||||
log.debug('Generating images filter.')
|
log.debug('Generating images filter.')
|
||||||
formats = list(map(bytes.decode, list(map(bytes, QtGui.QImageReader.supportedImageFormats()))))
|
formats = list(map(bytes.decode, list(map(bytes, QtGui.QImageReader.supportedImageFormats()))))
|
||||||
visible_formats = '(*.%s)' % '; *.'.join(formats)
|
visible_formats = '(*.{text})'.format(text='; *.'.join(formats))
|
||||||
actual_formats = '(*.%s)' % ' *.'.join(formats)
|
actual_formats = '(*.{text})'.format(text=' *.'.join(formats))
|
||||||
IMAGES_FILTER = '%s %s %s' % (translate('OpenLP', 'Image Files'), visible_formats, actual_formats)
|
IMAGES_FILTER = '{text} {visible} {actual}'.format(text=translate('OpenLP', 'Image Files'),
|
||||||
|
visible=visible_formats,
|
||||||
|
actual=actual_formats)
|
||||||
return IMAGES_FILTER
|
return IMAGES_FILTER
|
||||||
|
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ def get_text_file_string(text_file):
|
|||||||
file_handle.seek(0)
|
file_handle.seek(0)
|
||||||
content = file_handle.read()
|
content = file_handle.read()
|
||||||
except (IOError, UnicodeError):
|
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:
|
finally:
|
||||||
if file_handle:
|
if file_handle:
|
||||||
file_handle.close()
|
file_handle.close()
|
||||||
@ -300,6 +300,8 @@ def create_separated_list(string_list):
|
|||||||
return ''
|
return ''
|
||||||
elif len(string_list) == 1:
|
elif len(string_list) == 1:
|
||||||
return string_list[0]
|
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:
|
elif len(string_list) == 2:
|
||||||
return translate('OpenLP.core.lib', '%s and %s',
|
return translate('OpenLP.core.lib', '%s and %s',
|
||||||
'Locale list separator: 2 items') % (string_list[0], string_list[1])
|
'Locale list separator: 2 items') % (string_list[0], string_list[1])
|
||||||
|
@ -83,7 +83,7 @@ def get_media_players():
|
|||||||
reg_ex = QtCore.QRegExp(".*\[(.*)\].*")
|
reg_ex = QtCore.QRegExp(".*\[(.*)\].*")
|
||||||
if Settings().value('media/override player') == QtCore.Qt.Checked:
|
if Settings().value('media/override player') == QtCore.Qt.Checked:
|
||||||
if reg_ex.exactMatch(saved_players):
|
if reg_ex.exactMatch(saved_players):
|
||||||
overridden_player = '%s' % reg_ex.cap(1)
|
overridden_player = '{text}'.format(text=reg_ex.cap(1))
|
||||||
else:
|
else:
|
||||||
overridden_player = 'auto'
|
overridden_player = 'auto'
|
||||||
else:
|
else:
|
||||||
@ -102,7 +102,7 @@ def set_media_players(players_list, overridden_player='auto'):
|
|||||||
log.debug('set_media_players')
|
log.debug('set_media_players')
|
||||||
players = ','.join(players_list)
|
players = ','.join(players_list)
|
||||||
if Settings().value('media/override player') == QtCore.Qt.Checked and overridden_player != 'auto':
|
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)
|
Settings().setValue('media/players', players)
|
||||||
|
|
||||||
|
|
||||||
@ -113,7 +113,7 @@ def parse_optical_path(input_string):
|
|||||||
:param input_string: The string to parse
|
:param input_string: The string to parse
|
||||||
:return: The elements extracted from the string: filename, title, audio_track, subtitle_track, start, end
|
: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=':')
|
clip_info = input_string.split(sep=':')
|
||||||
title = int(clip_info[1])
|
title = int(clip_info[1])
|
||||||
audio_track = int(clip_info[2])
|
audio_track = int(clip_info[2])
|
||||||
@ -137,7 +137,10 @@ def format_milliseconds(milliseconds):
|
|||||||
seconds, millis = divmod(milliseconds, 1000)
|
seconds, millis = divmod(milliseconds, 1000)
|
||||||
minutes, seconds = divmod(seconds, 60)
|
minutes, seconds = divmod(seconds, 60)
|
||||||
hours, minutes = divmod(minutes, 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 .mediacontroller import MediaController
|
||||||
from .playertab import PlayerTab
|
from .playertab import PlayerTab
|
||||||
|
@ -211,22 +211,24 @@ def update_reference_separators():
|
|||||||
while '||' in source_string:
|
while '||' in source_string:
|
||||||
source_string = source_string.replace('||', '|')
|
source_string = source_string.replace('||', '|')
|
||||||
if role != 'e':
|
if role != 'e':
|
||||||
REFERENCE_SEPARATORS['sep_%s_display' % role] = source_string.split('|')[0]
|
REFERENCE_SEPARATORS['sep_{text}_display'.format(text=role)] = source_string.split('|')[0]
|
||||||
# escape reserved characters
|
# escape reserved characters
|
||||||
for character in '\\.^$*+?{}[]()':
|
for character in '\\.^$*+?{}[]()':
|
||||||
source_string = source_string.replace(character, '\\' + character)
|
source_string = source_string.replace(character, '\\' + character)
|
||||||
# add various unicode alternatives
|
# add various unicode alternatives
|
||||||
source_string = source_string.replace('-', '(?:[-\u00AD\u2010\u2011\u2012\u2014\u2014\u2212\uFE63\uFF0D])')
|
source_string = source_string.replace('-', '(?:[-\u00AD\u2010\u2011\u2012\u2014\u2014\u2212\uFE63\uFF0D])')
|
||||||
source_string = source_string.replace(',', '(?:[,\u201A])')
|
source_string = source_string.replace(',', '(?:[,\u201A])')
|
||||||
REFERENCE_SEPARATORS['sep_%s' % role] = '\s*(?:%s)\s*' % source_string
|
REFERENCE_SEPARATORS['sep_{text}'.format(text=role)] = '\s*(?:{text})\s*'.format(text=source_string)
|
||||||
REFERENCE_SEPARATORS['sep_%s_default' % role] = default_separators[index]
|
REFERENCE_SEPARATORS['sep_{text}_default'.format(text=role)] = default_separators[index]
|
||||||
# verse range match: (<chapter>:)?<verse>(-((<chapter>:)?<verse>|end)?)?
|
# verse range match: (<chapter>:)?<verse>(-((<chapter>:)?<verse>|end)?)?
|
||||||
range_regex = '(?:(?P<from_chapter>[0-9]+)%(sep_v)s)?' \
|
range_regex = '(?:(?P<from_chapter>[0-9]+){sep_v})?' \
|
||||||
'(?P<from_verse>[0-9]+)(?P<range_to>%(sep_r)s(?:(?:(?P<to_chapter>' \
|
'(?P<from_verse>[0-9]+)(?P<range_to>{sep_r}(?:(?:(?P<to_chapter>' \
|
||||||
'[0-9]+)%(sep_v)s)?(?P<to_verse>[0-9]+)|%(sep_e)s)?)?' % REFERENCE_SEPARATORS
|
'[0-9]+){sep_v})?(?P<to_verse>[0-9]+)|{sep_e})?)?'.format(**REFERENCE_SEPARATORS)
|
||||||
REFERENCE_MATCHES['range'] = re.compile('^\s*%s\s*$' % range_regex, re.UNICODE)
|
REFERENCE_MATCHES['range'] = re.compile('^\s*{text}\s*$'.format(text=range_regex), re.UNICODE)
|
||||||
REFERENCE_MATCHES['range_separator'] = re.compile(REFERENCE_SEPARATORS['sep_l'], re.UNICODE)
|
REFERENCE_MATCHES['range_separator'] = re.compile(REFERENCE_SEPARATORS['sep_l'], re.UNICODE)
|
||||||
# full reference match: <book>(<range>(,(?!$)|(?=$)))+
|
# full reference match: <book>(<range>(,(?!$)|(?=$)))+
|
||||||
|
# NOTE:
|
||||||
|
# Need to research a little more before converting this to python3 string format
|
||||||
REFERENCE_MATCHES['full'] = \
|
REFERENCE_MATCHES['full'] = \
|
||||||
re.compile('^\s*(?!\s)(?P<book>[\d]*[^\d]+)(?<!\s)\s*'
|
re.compile('^\s*(?!\s)(?P<book>[\d]*[^\d]+)(?<!\s)\s*'
|
||||||
'(?P<ranges>(?:%(range_regex)s(?:%(sep_l)s(?!\s*$)|(?=\s*$)))+)\s*$'
|
'(?P<ranges>(?:%(range_regex)s(?:%(sep_l)s(?!\s*$)|(?=\s*$)))+)\s*$'
|
||||||
@ -331,10 +333,12 @@ def parse_reference(reference, bible, language_selection, book_ref_id=False):
|
|||||||
separator.
|
separator.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
# TODO:
|
||||||
|
# Verify convertsion here before committing format change
|
||||||
log.debug('parse_reference("%s")', reference)
|
log.debug('parse_reference("%s")', reference)
|
||||||
match = get_reference_match('full').match(reference)
|
match = get_reference_match('full').match(reference)
|
||||||
if match:
|
if match:
|
||||||
log.debug('Matched reference %s' % reference)
|
log.debug('Matched reference {text}'.format(text=reference))
|
||||||
book = match.group('book')
|
book = match.group('book')
|
||||||
if not book_ref_id:
|
if not book_ref_id:
|
||||||
book_ref_id = bible.get_book_ref_id_by_localised_name(book, language_selection)
|
book_ref_id = bible.get_book_ref_id_by_localised_name(book, language_selection)
|
||||||
@ -400,7 +404,7 @@ def parse_reference(reference, bible, language_selection, book_ref_id=False):
|
|||||||
ref_list.append((book_ref_id, from_chapter, 1, -1))
|
ref_list.append((book_ref_id, from_chapter, 1, -1))
|
||||||
return ref_list
|
return ref_list
|
||||||
else:
|
else:
|
||||||
log.debug('Invalid reference: %s' % reference)
|
log.warn('Invalid reference: {text}'.format(text=reference))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ import json
|
|||||||
def assert_length(expected, iterable, msg=None):
|
def assert_length(expected, iterable, msg=None):
|
||||||
if len(iterable) != expected:
|
if len(iterable) != expected:
|
||||||
if not msg:
|
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)
|
raise AssertionError(msg)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user