Skip to content

Commit

Permalink
chore: tidy up a little bit
Browse files Browse the repository at this point in the history
  • Loading branch information
hutcheb committed Jul 11, 2024
1 parent 4ce7df6 commit 75b9595
Show file tree
Hide file tree
Showing 13 changed files with 48,030 additions and 33 deletions.
2 changes: 1 addition & 1 deletion acd/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class DumpCompsRecordsToFile(ExportProject):
def extract(self):
export = ExportL5x(self.filename)
with open(
os.path.join(self.output_directory, export.project.target_name + ".log"),
os.path.join(self.output_directory, "output.log"),
"w",
) as log_file:
DumpCompsRecords(export._cur, 0).dump(log_file=log_file)
4 changes: 0 additions & 4 deletions acd/generated/comps/rx_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ def _read(self):
RxGeneric.AttributeRecord(self._io, self, self._root)
)

self.last_extended_record = RxGeneric.LastAttributeRecord(
self._io, self, self._root
)

class Unknown(KaitaiStruct):
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
Expand Down
3 changes: 2 additions & 1 deletion acd/generated/sbregion/fafa_sbregions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild

import kaitaistruct
from kaitaistruct import KaitaiStruct, KaitaiStream
from kaitaistruct import KaitaiStruct, KaitaiStream, BytesIO


if getattr(kaitaistruct, "API_VERSION", (0, 9)) < (0, 9):
raise Exception(
Expand Down
24 changes: 5 additions & 19 deletions acd/l5x/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ def external_access_enum(i: int) -> str:
default = "Read/Write"
if i == 0:
return default
if i == 1:
return "Read Only"
if i == 2:
return "Read Only"
if i == 3:
return "None"
return default

Expand All @@ -216,9 +216,6 @@ def build(self) -> Member:
extended_records: Dict[int, List[int]] = {}
for extended_record in r.extended_records:
extended_records[extended_record.attribute_id] = extended_record.value
extended_records[
r.last_extended_record.attribute_id
] = r.last_extended_record.value

cip_data_typoe = struct.unpack_from("<I", self.record, 0x78)[0]
dimension = struct.unpack_from("<I", self.record, 0x5C)[0]
Expand Down Expand Up @@ -260,9 +257,6 @@ def build(self) -> DataType:
extended_records[extended_record.attribute_id] = bytes(
extended_record.value
)
extended_records[r.last_extended_record.attribute_id] = bytes(
r.last_extended_record.value
)

string_family_int = struct.unpack("<I", extended_records[0x6C])[0]
string_family = "StringFamily" if string_family_int == 1 else "NoFamily"
Expand All @@ -275,7 +269,7 @@ def build(self) -> DataType:
class_type = "IO"
if built_in > 0:
class_type = "ProductDefined"
if len(extended_records[0x64]) == 0x04:
if 0x64 in extended_records and len(extended_records[0x64]) == 0x04:
member_count = struct.unpack("<I", extended_records[0x64])[0]
else:
member_count = 0
Expand Down Expand Up @@ -334,9 +328,6 @@ def build(self) -> MapDevice:
extended_records[extended_record.attribute_id] = bytes(
extended_record.value
)
extended_records[r.last_extended_record.attribute_id] = bytes(
r.last_extended_record.value
)

vendor_id = struct.unpack("<H", extended_records[0x01][2:4])[0]
product_type = struct.unpack("<H", extended_records[0x01][4:6])[0]
Expand Down Expand Up @@ -399,15 +390,13 @@ def build(self) -> Tag:
extended_records[extended_record.attribute_id] = bytes(
extended_record.value
)
extended_records[r.last_extended_record.attribute_id] = bytes(
r.last_extended_record.value
)

name_length = struct.unpack("<H", extended_records[0x01][0:2])[0]
name = bytes(extended_records[0x01][2 : name_length + 2]).decode("utf-8")

radix = radix_enum(r.main_record.radix)
external_access = external_access_enum(r.main_record.external_access)
name_length_raw = struct.unpack_from("<H", extended_records[0x01], 0x21E)[0]
external_access = external_access_enum(name_length_raw)

if r.main_record.dimension_1 != 0:
data_type = data_type + "[" + str(r.main_record.dimension_1) + "]"
Expand Down Expand Up @@ -619,9 +608,6 @@ def build(self) -> Controller:
extended_records[extended_record.attribute_id] = bytes(
extended_record.value
)
extended_records[r.last_extended_record.attribute_id] = bytes(
r.last_extended_record.value
)

comm_path = bytes(extended_records[0x6A][:-2]).decode("utf-16")
sfc_execution_control = bytes(extended_records[0x6F][:-2]).decode("utf-16")
Expand Down
9 changes: 4 additions & 5 deletions acd/record/comps.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ def __post_init__(self):
else:
return

query: str = f"DELETE FROM comps WHERE object_id={r.header.object_id}"
self._cur.execute(query)

query: str = "INSERT INTO comps VALUES (?, ?, ?, ?, ?, ?)"
delete_query: str = f"DELETE FROM comps WHERE object_id={r.header.object_id}"
self._cur.execute(delete_query)

insert_query: str = "INSERT INTO comps VALUES (?, ?, ?, ?, ?, ?)"
entry: tuple = (
r.header.object_id,
r.header.parent_id,
Expand All @@ -48,4 +47,4 @@ def __post_init__(self):
r.header.record_type,
r.record_buffer,
)
self._cur.execute(query, entry)
self._cur.execute(insert_query, entry)
Loading

0 comments on commit 75b9595

Please sign in to comment.