Skip to content

Commit f393cb0

Browse files
committed
feat: enable setting CC0 license
1 parent 0cbb522 commit f393cb0

File tree

1 file changed

+41
-28
lines changed

1 file changed

+41
-28
lines changed

csv2cmi.py

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,26 @@
3838
# define namespace
3939
RDF_NS = {"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#"}
4040

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+
4153
# define arguments
4254
parser = argparse.ArgumentParser(description="convert tables of letters to CMI")
4355
parser.add_argument("filename", help="input file (.csv)")
4456
parser.add_argument("-a", "--all", help="include unedited letters", action="store_true")
4557
parser.add_argument("-n", "--notes", help="transfer notes", action="store_true")
4658
parser.add_argument("-o", "--output", metavar="FILE", help="output file name")
4759
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")
4861
parser.add_argument("--line-numbers", help="add line numbers", action="store_true")
4962
parser.add_argument("--version", action="version", version="%(prog)s " + __version__)
5063
parser.add_argument("--extra-delimiter", help="delimiter for different values within cells")
@@ -121,45 +134,43 @@ def __str__(self) -> str:
121134
def create_file_desc(self, project: configparser) -> None:
122135
"""Create a TEI file description from config file."""
123136
# 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"))
129142
editors = [""]
130143
editors = project.get("Project", "editor").splitlines()
131144
for entity in editors:
132145
mailbox = parseaddr(entity)
133146
if "@" in entity and any(mailbox):
134-
editor = SubElement(title_stmt, "editor")
147+
tei_editor = SubElement(tei_title_stmt, "editor")
135148
if mailbox[0]:
136-
editor.text = mailbox[0]
149+
tei_editor.text = mailbox[0]
137150
if mailbox[-1]:
138-
SubElement(editor, "email").text = mailbox[-1]
151+
SubElement(tei_editor, "email").text = mailbox[-1]
139152
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:
142155
logging.warning("Editor missing")
143-
SubElement(title_stmt, "editor")
156+
SubElement(tei_title_stmt, "editor")
144157
# publication statement
145-
publication_stmt = self.file_desc.find("publicationStmt")
158+
tei_publication_stmt = self.file_desc.find("publicationStmt")
146159
publishers = project.get("Project", "publisher").splitlines()
147160
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"]
163174

164175
def add_edition(self, bibl_text: str, bibl_type: str, bibl_id: str) -> None:
165176
"""Create a new bibliographic entry."""
@@ -531,7 +542,9 @@ def save_to_file(self, file_name: Path) -> None:
531542
# read config file
532543
config = configparser.ConfigParser()
533544
# 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"
535548

536549
INI_FILE = "csv2cmi.ini"
537550
try:

0 commit comments

Comments
 (0)