|
38 | 38 | # define namespace |
39 | 39 | RDF_NS = {"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#"} |
40 | 40 |
|
| 41 | +# define licenses |
| 42 | +LICENSES = { |
| 43 | + "cc-by": { |
| 44 | + "url": "https://creativecommons.org/licenses/by/4.0/", |
| 45 | + "text": "This file is licensed under the terms of the Creative-Commons-License CC-BY 4.0.", |
| 46 | + }, |
| 47 | + "cc0": { |
| 48 | + "url": "https://creativecommons.org/publicdomain/zero/1.0/", |
| 49 | + "text": "This file has been marked as dedicated to the public domain.", |
| 50 | + }, |
| 51 | +} |
| 52 | + |
41 | 53 | # define arguments |
42 | 54 | parser = argparse.ArgumentParser(description="convert tables of letters to CMI") |
43 | 55 | parser.add_argument("filename", help="input file (.csv)") |
44 | 56 | parser.add_argument("-a", "--all", help="include unedited letters", action="store_true") |
45 | 57 | parser.add_argument("-n", "--notes", help="transfer notes", action="store_true") |
46 | 58 | parser.add_argument("-o", "--output", metavar="FILE", help="output file name") |
47 | 59 | parser.add_argument("-v", "--verbose", help="increase output verbosity", action="store_true") |
| 60 | +parser.add_argument("--cc0", help="mark as public domain", action="store_true") |
48 | 61 | parser.add_argument("--line-numbers", help="add line numbers", action="store_true") |
49 | 62 | parser.add_argument("--version", action="version", version="%(prog)s " + __version__) |
50 | 63 | parser.add_argument("--extra-delimiter", help="delimiter for different values within cells") |
@@ -121,45 +134,43 @@ def __str__(self) -> str: |
121 | 134 | def create_file_desc(self, project: configparser) -> None: |
122 | 135 | """Create a TEI file description from config file.""" |
123 | 136 | # title statement |
124 | | - title_stmt = self.file_desc.find("titleStmt") |
125 | | - title = SubElement(title_stmt, "title") |
126 | | - title.text = project.get("Project", "title", fallback="untitled letters project") |
127 | | - random.seed(title.text) |
128 | | - title.set("xml:id", self.generate_id("title")) |
| 137 | + tei_title_stmt = self.file_desc.find("titleStmt") |
| 138 | + tei_title = SubElement(tei_title_stmt, "title") |
| 139 | + tei_title.text = project.get("Project", "title", fallback="untitled letters project") |
| 140 | + random.seed(tei_title.text) |
| 141 | + tei_title.set("xml:id", self.generate_id("title")) |
129 | 142 | editors = [""] |
130 | 143 | editors = project.get("Project", "editor").splitlines() |
131 | 144 | for entity in editors: |
132 | 145 | mailbox = parseaddr(entity) |
133 | 146 | if "@" in entity and any(mailbox): |
134 | | - editor = SubElement(title_stmt, "editor") |
| 147 | + tei_editor = SubElement(tei_title_stmt, "editor") |
135 | 148 | if mailbox[0]: |
136 | | - editor.text = mailbox[0] |
| 149 | + tei_editor.text = mailbox[0] |
137 | 150 | if mailbox[-1]: |
138 | | - SubElement(editor, "email").text = mailbox[-1] |
| 151 | + SubElement(tei_editor, "email").text = mailbox[-1] |
139 | 152 | else: |
140 | | - SubElement(title_stmt, "editor").text = entity |
141 | | - if len(list(title_stmt)) == 1: |
| 153 | + SubElement(tei_title_stmt, "editor").text = entity |
| 154 | + if len(list(tei_title_stmt)) == 1: |
142 | 155 | logging.warning("Editor missing") |
143 | | - SubElement(title_stmt, "editor") |
| 156 | + SubElement(tei_title_stmt, "editor") |
144 | 157 | # publication statement |
145 | | - publication_stmt = self.file_desc.find("publicationStmt") |
| 158 | + tei_publication_stmt = self.file_desc.find("publicationStmt") |
146 | 159 | publishers = project.get("Project", "publisher").splitlines() |
147 | 160 | for entity in publishers: |
148 | | - SubElement(publication_stmt, "publisher").text = entity |
149 | | - if not list(publication_stmt): |
150 | | - for editor in title_stmt.findall("editor"): |
151 | | - SubElement(publication_stmt, "publisher").text = editor.text |
152 | | - idno = SubElement(publication_stmt, "idno") |
153 | | - idno.set("type", "url") |
154 | | - idno.text = project.get("Project", "fileURL") |
155 | | - SubElement(publication_stmt, "date").set("when", str(datetime.now().isoformat())) |
156 | | - availability = SubElement(publication_stmt, "availability") |
157 | | - licence = SubElement(availability, "licence") |
158 | | - licence.set("target", "https://creativecommons.org/licenses/by/4.0/") |
159 | | - licence.text = "This file is licensed under the terms of the Creative-Commons-License CC-BY 4.0" |
160 | | - # The CC-BY licence may not apply to the final CMI file |
161 | | - # licence.set('target', 'https://creativecommons.org/publicdomain/zero/1.0/') |
162 | | - # licence.text = 'This file is licensed under a Creative Commons Zero 1.0 License.' |
| 161 | + SubElement(tei_publication_stmt, "publisher").text = entity |
| 162 | + if not list(tei_publication_stmt): |
| 163 | + for editor in tei_title_stmt.findall("editor"): |
| 164 | + SubElement(tei_publication_stmt, "publisher").text = editor.text |
| 165 | + tei_idno = SubElement(tei_publication_stmt, "idno") |
| 166 | + tei_idno.set("type", "url") |
| 167 | + tei_idno.text = project.get("Project", "fileURL") |
| 168 | + SubElement(tei_publication_stmt, "date").set("when", str(datetime.now().isoformat())) |
| 169 | + availability = SubElement(tei_publication_stmt, "availability") |
| 170 | + tei_licence = SubElement(availability, "licence") |
| 171 | + chosen_license = LICENSES.get(project.get("Project", "license")) |
| 172 | + tei_licence.set("target", chosen_license.get("url")) |
| 173 | + tei_licence.text = chosen_license["text"] |
163 | 174 |
|
164 | 175 | def add_edition(self, bibl_text: str, bibl_type: str, bibl_id: str) -> None: |
165 | 176 | """Create a new bibliographic entry.""" |
@@ -531,7 +542,9 @@ def save_to_file(self, file_name: Path) -> None: |
531 | 542 | # read config file |
532 | 543 | config = configparser.ConfigParser() |
533 | 544 | # set default values |
534 | | - config["Project"] = {"editor": "", "publisher": "", "fileURL": letters_csv.with_suffix(".xml")} |
| 545 | + config["Project"] = {"editor": "", "publisher": "", "fileURL": letters_csv.with_suffix(".xml"), "license": "cc-by"} |
| 546 | + if args.cc0: |
| 547 | + config["Project"]["license"] = "cc0" |
535 | 548 |
|
536 | 549 | INI_FILE = "csv2cmi.ini" |
537 | 550 | try: |
|
0 commit comments