Skip to content

Commit

Permalink
Merge pull request #150 from ascmitc/dev/fix-creator-info
Browse files Browse the repository at this point in the history
Fix author info to conform to structure in spec
  • Loading branch information
ptrpfn authored Aug 23, 2024
2 parents bcabf38 + 14223b6 commit ac0188f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion ascmhl/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1434,7 +1434,7 @@ def commit_session(session, author_name, author_email, author_phone, author_role
creator_info.host_name = platform.node()
creator_info.location = location
creator_info.comment = comment
if author_name is not None:
if author_name is not None or author_email is not None or author_role is not None or author_phone is not None:
author_object = MHLAuthor(author_name, author_email, author_phone, author_role)
creator_info.authors.append(author_object)

Expand Down
35 changes: 23 additions & 12 deletions ascmhl/hashlist_xml_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,17 @@ def parse(file_path):
current_object = None

# author
elif tag == "author":
if current_object.authors[-1].name == "-":
current_object.authors[-1].name = element.text
if current_object.authors[-1].role == None:
current_object.authors[-1].role = element.attrib.get("role")
if current_object.authors[-1].email == None:
current_object.authors[-1].email = element.attrib.get("email")
if current_object.authors[-1].phone == None:
current_object.authors[-1].phone = element.attrib.get("phone")

# author (not as spec says, only here for backwards compatibility)
elif tag == "name":
current_object.authors[-1].name = element.text
elif tag == "role":
Expand Down Expand Up @@ -348,24 +359,24 @@ def _creator_info_xml_element(hash_list: MHLHashList):
E.hostname(creator_info.host_name),
E.tool(creator_info.tool.name, version=creator_info.tool.version),
)
for author in creator_info.authors:
author_element = E.author()
if author.role != None:
author_element.attrib["role"] = author.role
if author.email != None:
author_element.attrib["email"] = author.email
if author.phone != None:
author_element.attrib["phone"] = author.phone
if author.name != None and author.name != "-":
author_element.text = author.name
info_element.append(author_element)

if creator_info.location is not None:
info_element.append(E.location(creator_info.location))

if creator_info.comment is not None:
info_element.append(E.comment(creator_info.comment))

for author in creator_info.authors:
author_element = E.author()
if author.name is not None:
author_element.append(E.name(author.name))
if author.role is not None:
author_element.append(E.role(author.role))
if author.email is not None:
author_element.append(E.email(author.email))
if author.phone is not None:
author_element.append(E.phone(author.phone))
info_element.append(author_element)

return info_element


Expand Down

0 comments on commit ac0188f

Please sign in to comment.