mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 23:17:32 -06:00
Use startswith for more pythonic code.
Swap out while True with for line in f.readlines. This will now termitate without having to catch a StopIteration error. CURA-9141
This commit is contained in:
parent
b04f3bd587
commit
63e6b7704c
1 changed files with 40 additions and 47 deletions
|
@ -28,17 +28,15 @@ def parsePOFile(filename: str) -> List[Msg]:
|
||||||
messages = []
|
messages = []
|
||||||
with open(filename) as f:
|
with open(filename) as f:
|
||||||
iterator = iter(f.readlines())
|
iterator = iter(f.readlines())
|
||||||
while True:
|
for line in iterator:
|
||||||
try:
|
if line.startswith("msgctxt"):
|
||||||
line = next(iterator)
|
|
||||||
if line[0:7] == "msgctxt":
|
|
||||||
# Start of a translation item block
|
# Start of a translation item block
|
||||||
msg = Msg()
|
msg = Msg()
|
||||||
msg.msgctxt = line
|
msg.msgctxt = line
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
line = next(iterator)
|
line = next(iterator)
|
||||||
if line[0:5] == "msgid":
|
if line.startswith("msgid"):
|
||||||
msg.msgid = line
|
msg.msgid = line
|
||||||
break
|
break
|
||||||
|
|
||||||
|
@ -47,13 +45,13 @@ def parsePOFile(filename: str) -> List[Msg]:
|
||||||
line = next(iterator)
|
line = next(iterator)
|
||||||
if line == "\n":
|
if line == "\n":
|
||||||
break
|
break
|
||||||
if line[0:6] == "msgstr":
|
if line.startswith("msgstr"):
|
||||||
msg.msgstr = line
|
msg.msgstr = line
|
||||||
else:
|
else:
|
||||||
msg.msgstr += line
|
msg.msgstr += line
|
||||||
|
|
||||||
messages.append(msg)
|
messages.append(msg)
|
||||||
except StopIteration:
|
|
||||||
return messages
|
return messages
|
||||||
|
|
||||||
|
|
||||||
|
@ -75,11 +73,9 @@ def updatePOFile(input_filename: str, output_filename: str, messages: List[Msg])
|
||||||
# Takes a list of changed messages and writes a copy of input file with updated message strings
|
# Takes a list of changed messages and writes a copy of input file with updated message strings
|
||||||
with open(input_filename, "r") as input_file, open(output_filename, "w") as output_file:
|
with open(input_filename, "r") as input_file, open(output_filename, "w") as output_file:
|
||||||
iterator = iter(input_file.readlines())
|
iterator = iter(input_file.readlines())
|
||||||
while True:
|
for line in iterator:
|
||||||
try:
|
|
||||||
line = next(iterator)
|
|
||||||
output_file.write(line)
|
output_file.write(line)
|
||||||
if line[0: 7] == "msgctxt":
|
if line.startswith("msgctxt"):
|
||||||
# Start of translation block
|
# Start of translation block
|
||||||
msgctxt = line
|
msgctxt = line
|
||||||
|
|
||||||
|
@ -99,9 +95,6 @@ def updatePOFile(input_filename: str, output_filename: str, messages: List[Msg])
|
||||||
output_file.write(line)
|
output_file.write(line)
|
||||||
break
|
break
|
||||||
|
|
||||||
except StopIteration:
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print("********************************************************************************************************************")
|
print("********************************************************************************************************************")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue