db.py docstring

main
jgenero 3 years ago
parent c9197066e4
commit c24150fd9a

@ -261,8 +261,6 @@ def _create_involved_in(folder: str):
@db_cli.command()
def init() -> None:
"""Initialization of the database"""
princes_houses = ["Berry", "Bourbon", "Anjou"]
print("Dropping existing DB...")
db.drop_tables([Institution, State, House, Intervention_type,
Production_place, Diplo_type, Document, Agent, Acte, Transcribed_by,
@ -271,6 +269,7 @@ def init() -> None:
db.create_tables([Institution, State, House, Intervention_type,
Production_place, Diplo_type, Document, Agent, Acte,
Transcribed_by, Individual, Involved_in])
_create_institution(institution)
_create_state(state)
_create_house(houses)
@ -278,23 +277,36 @@ def init() -> None:
_create_diplo_type(diplomatic_type)
actors = [*__csv_indiv_infos("secret"), *__csv_indiv_infos("prince")]
_create_indiv(actors)
# if new houses were to be added, princes_houses need to be completed
princes_houses = ["Berry", "Bourbon", "Anjou"]
agents_names = []
# iteration over houses
for prince_house in princes_houses:
# 1/ make path to house xml folder
xml_folder = os.path.join(APPPATH, "static", "xml", prince_house)
print("\n\n**** HOUSE ", prince_house, " ****")
# 2/ add all transcribers names to list agents_names
for name in __find_transcribers(xml_folder):
agents_names.append(name)
# check which names need to be add to the actors.csv
# 3/ check which names need to be add to the actors.csv
names_in_csv = [actor[0] for actor in actors]
names_in_xml = __find_indiv(xml_folder, "signatory")
for name in [x for x in names_in_xml if x not in names_in_csv]:
print("!! name " + name + " not found in /app/static/csv/actors.csv")
# 4/ create tables
_create_produc_place(xml_folder)
_create_doc(xml_folder)
_create_acte(xml_folder)
# table Agent
agents = [{"agent_name": agent} for agent in set(agents_names)]
_create_agent(agents)
for prince_house in princes_houses:
print("\n\n**** INVOLVED IN ", prince_house, " ****")
xml_folder = os.path.join(APPPATH, "static", "xml", prince_house)

Loading…
Cancel
Save