Code cleanup.

This commit is contained in:
Markus Birth 2021-08-29 17:51:28 +02:00
parent 2612993760
commit d54ff5eb75
Signed by: mbirth
GPG Key ID: A9928D7A098C3A9A
2 changed files with 7 additions and 33 deletions

View File

@ -32,18 +32,6 @@ opif = onepif.OnepifReader("{}/data.1pif".format(args.inpath))
print("Output file: {}".format(args.outfile))
kp = kpwriter.KpWriter(args.outfile, "test")
def getField(item, designation):
secure = item["secureContents"]
if "fields" in secure:
for field in secure["fields"]:
d = field.get("designation")
if d == designation:
return field["value"]
return None
# Load record mappings from Yaml file
RECORD_MAP = yaml.load(open("mappings.yml", "rt"), Loader=yaml.SafeLoader)

View File

@ -71,6 +71,9 @@ class OnepifEntry():
while tmp_key in prop_dict:
suffix_ctr += 1
tmp_key = "{}_{}".format(new_key, suffix_ctr)
if type(new_value) is str:
# For some reason 1P sometimes exports 0x10 character for empty strings
new_value = new_value.replace("\x10", "")
prop_dict[tmp_key] = new_value
def convert_section_field_to_string(self, field_data: dict) -> str:
@ -133,9 +136,6 @@ class OnepifEntry():
else:
propname = f["name"]
propval = f["value"]
if type(propval) is str:
# For some reason 1P sometimes exports 0x10 character for empty strings
propval = propval.replace("\x10", "")
if f["type"] not in ["T", "P", "E"]:
raise Exception("Unknown field type discovered: {}".format(f["type"]))
self.add_with_unique_key(target_dict, propname, propval)
@ -163,24 +163,10 @@ class OnepifEntry():
# For some reason this differs from the "fields" in a section
self.parse_fields_into_dict(props, v2)
continue
new_key2 = k2
suffix_ctr2 = 0
while new_key2 in props:
suffix_ctr2 += 1
new_key2 = "{}_{}".format(k2, suffix_ctr2)
if type(v2) is str:
# For some reason 1P sometimes exports 0x10 character for empty strings
v2 = v2.replace("\x10", "")
props[new_key2] = v2
# Handle all other values (most probably string or int)
self.add_with_unique_key(props, k2, v2)
continue
new_key = k
suffix_ctr = 0
while new_key in props:
suffix_ctr += 1
new_key = "{}_{}".format(k, suffix_ctr)
if type(v) is str:
# For some reason 1P sometimes exports 0x10 character for empty strings
v = v.replace("\x10", "")
props[new_key] = v
# Handle all other values
self.add_with_unique_key(props, k, v)
# TODO: Maybe walk all keys and see if there's (xxx_dd), xxx_mm, xxx_yy and turn them into a date
return props