Code cleanup.
This commit is contained in:
parent
2612993760
commit
d54ff5eb75
12
convert.py
12
convert.py
@ -32,18 +32,6 @@ opif = onepif.OnepifReader("{}/data.1pif".format(args.inpath))
|
|||||||
print("Output file: {}".format(args.outfile))
|
print("Output file: {}".format(args.outfile))
|
||||||
kp = kpwriter.KpWriter(args.outfile, "test")
|
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
|
# Load record mappings from Yaml file
|
||||||
RECORD_MAP = yaml.load(open("mappings.yml", "rt"), Loader=yaml.SafeLoader)
|
RECORD_MAP = yaml.load(open("mappings.yml", "rt"), Loader=yaml.SafeLoader)
|
||||||
|
|
||||||
|
@ -71,6 +71,9 @@ class OnepifEntry():
|
|||||||
while tmp_key in prop_dict:
|
while tmp_key in prop_dict:
|
||||||
suffix_ctr += 1
|
suffix_ctr += 1
|
||||||
tmp_key = "{}_{}".format(new_key, suffix_ctr)
|
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
|
prop_dict[tmp_key] = new_value
|
||||||
|
|
||||||
def convert_section_field_to_string(self, field_data: dict) -> str:
|
def convert_section_field_to_string(self, field_data: dict) -> str:
|
||||||
@ -133,9 +136,6 @@ class OnepifEntry():
|
|||||||
else:
|
else:
|
||||||
propname = f["name"]
|
propname = f["name"]
|
||||||
propval = f["value"]
|
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"]:
|
if f["type"] not in ["T", "P", "E"]:
|
||||||
raise Exception("Unknown field type discovered: {}".format(f["type"]))
|
raise Exception("Unknown field type discovered: {}".format(f["type"]))
|
||||||
self.add_with_unique_key(target_dict, propname, propval)
|
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
|
# For some reason this differs from the "fields" in a section
|
||||||
self.parse_fields_into_dict(props, v2)
|
self.parse_fields_into_dict(props, v2)
|
||||||
continue
|
continue
|
||||||
new_key2 = k2
|
# Handle all other values (most probably string or int)
|
||||||
suffix_ctr2 = 0
|
self.add_with_unique_key(props, k2, v2)
|
||||||
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
|
|
||||||
continue
|
continue
|
||||||
new_key = k
|
# Handle all other values
|
||||||
suffix_ctr = 0
|
self.add_with_unique_key(props, k, v)
|
||||||
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
|
|
||||||
# TODO: Maybe walk all keys and see if there's (xxx_dd), xxx_mm, xxx_yy and turn them into a date
|
# TODO: Maybe walk all keys and see if there's (xxx_dd), xxx_mm, xxx_yy and turn them into a date
|
||||||
return props
|
return props
|
||||||
|
Loading…
x
Reference in New Issue
Block a user