-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcli_copyright.py
43 lines (34 loc) · 1.35 KB
/
cli_copyright.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# -------------------------------------------------------------------------------
# (c) 2019-2023 Siemens AG
# All Rights Reserved.
# Author: [email protected]
#
# Licensed under the MIT license.
# SPDX-License-Identifier: MIT
# -------------------------------------------------------------------------------
import xml.etree.ElementTree as ET
from typing import List
from .cli_file_item_base import CliFileItemBase
class CliCopyright(CliFileItemBase):
"""Encapsulates a copyright statement."""
CONTENT_TAG = "Content"
def __init__(self) -> None:
CliFileItemBase.__init__(self)
self.text: str = ""
self.files: List[str] = []
self.hashes: List[str] = []
def _read_from_element(self, element: ET.Element) -> None:
"""Read copyright from XML element."""
self._read_files_from_element(element)
for elem in element:
if elem.tag == self.CONTENT_TAG and elem.text:
if elem.text is not None:
self.text = elem.text.strip()
continue
def _append_to_xml(self, parent: ET.Element) -> None:
"""Write copyright to XML element."""
cr = ET.SubElement(parent, "Copyright")
node = ET.SubElement(cr, "Content")
cdata = self.CDATA(self.text)
node.append(cdata)
CliFileItemBase._append_to_xml(self, cr)