Skip to content

Commit

Permalink
Simplify code in ini and tmx conversors
Browse files Browse the repository at this point in the history
  • Loading branch information
jordimas committed Aug 3, 2024
1 parent 36d502f commit 4dbbd9e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 30 deletions.
8 changes: 1 addition & 7 deletions src/builder/bazaarfileset.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,7 @@ class BazaarFileSet(FileSet):
def _has_filename(self):
"""Used to identify if the file contains a path (/ and then .)"""
filename = self.url.split("/")[-1]

if len(filename) > 0:
rslt = self.filename.find(".")
if rslt != -1:
return True

return False
return "." in filename

def do(self):
if self._has_filename():
Expand Down
2 changes: 1 addition & 1 deletion src/builder/compressedfileset.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def uncompress(filename, report_error, temp_dir):
cmd = "tar -Jxf {0} -C {1}".format(filename, temp_dir)
os.system(cmd)
else:
if report_error is True:
if report_error:
msg = "Unsupported file extension for filename: {0}"
logging.error(msg.format(filename))

Expand Down
29 changes: 7 additions & 22 deletions src/builder/convertini.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,19 @@ def __init__(self, source_file, target_file, output_file):
self.output_file = output_file

def _parse_line(self, line):
key = None
value = None

if "=" not in line:
return key, value

values = line.split("=", 1)
if len(values) != 2:
return key, value
return None, None

key = values[0]
value = values[1]
value = value.replace('"', "")
return key.strip(), value.strip()
key, value = line.split("=", 1)
return key.strip(), value.strip().replace('"', "")

def _read_source(self):
lines = []
strings = []
with open(self.source_file) as f:
lines = f.readlines()

for line in lines:
key, value = self._parse_line(line)
if key is None:
continue

pair = (key.strip(), value.strip())
strings.append(pair)
for line in f:
key, value = self._parse_line(line)
if key:
strings.append((key, value))

return strings

Expand Down

0 comments on commit 4dbbd9e

Please sign in to comment.