|
|
@@ -29,12 +29,11 @@ target_dir = Path(r"\\h2o\LOCAL\4-transversal\BDD\mdb\PDA\Fichiers_PDA")
|
|
|
|
|
|
# Mapping: (nom de la table, {correspondance champ : alias}, nom des noeuds, nom du fichier cible)
|
|
|
mapping = [
|
|
|
- ("pdaEngin", {"strEnginId": "Id", "strEnginLibelleLong": "Nom"}, "Attelage", "attelages.xml"),
|
|
|
- ("pdaorigine", {"lngorigine": "Id", "strorigine": "Nom"}, "Depart", "depart.xml"),
|
|
|
- ("pdaEquip", {"strEquipesId": "Id", "strEquipesLibelle": "Nom"}, "Equipe", "equipes.xml"),
|
|
|
- ("pdalocalisation", {"lngTiersId": "Id", "strTiersMnemo": "Nom"}, "Localisation", "localisation.xml"),
|
|
|
- ("pdaNatInterv", {"strCategorieInterventioinId": "Id", "strCategorieInterventioinLibelle": "Nom"}, "NatureRealisation", "naturesinterventions.xml"),
|
|
|
- ("pdaHeures", {"annee": "annee", "mois": "mois", "heures": "heures"}, "pdaHeures", "heures.xml"),
|
|
|
+ ("pdaEngin", ("strEnginId", "strEnginLibelleLong"), "Attelage", "attelages.xml"),
|
|
|
+ ("pdaorigine", ("lngorigine", "strorigine"), "Depart", "depart.xml"),
|
|
|
+ ("pdaEquip", ("strEquipesId", "strEquipesLibelle"), "Equipe", "equipes.xml"),
|
|
|
+ ("pdalocalisation", ("lngTiersId", "strTiersMnemo"), "Localisation", "localisation.xml"),
|
|
|
+ ("pdaNatInterv", ("strCategorieInterventioinId", "strCategorieInterventioinLibelle"), "NatureRealisation", "naturesinterventions.xml")
|
|
|
]
|
|
|
|
|
|
for tablename, fieldmapping, eltname, filename in mapping:
|
|
|
@@ -43,12 +42,15 @@ for tablename, fieldmapping, eltname, filename in mapping:
|
|
|
'xsi': "http://www.w3.org/2001/XMLSchema-instance"})
|
|
|
nodes = []
|
|
|
|
|
|
- sql = "SELECT {} FROM {}".format(
|
|
|
- ",".join([("{} AS {}".format(name, alias) if name != alias else name) for name, alias in fieldmapping.items()]),
|
|
|
- tablename
|
|
|
- )
|
|
|
+ fieldid, fieldnom = fieldmapping
|
|
|
|
|
|
- data = pda_db.read_all(sql)
|
|
|
+ sql = "SELECT {id} as Id, {nom} as Nom FROM {tbl} ORDER BY {nom}".format(
|
|
|
+ id=fieldid,
|
|
|
+ nom=fieldnom,
|
|
|
+ tbl=tablename
|
|
|
+ )
|
|
|
+
|
|
|
+ data = [record._asdict() for record in pda_db.read_all(sql)]
|
|
|
|
|
|
for record in data:
|
|
|
node = maker.__call__(eltname, *[maker.__call__(field, str(value)) for field, value in record.items()])
|
|
|
@@ -56,6 +58,9 @@ for tablename, fieldmapping, eltname, filename in mapping:
|
|
|
|
|
|
root = maker.__call__("ArrayOf" + eltname, *nodes)
|
|
|
|
|
|
+ if not filename[-4:] == ".xml":
|
|
|
+ filename += ".xml"
|
|
|
+
|
|
|
with open(target_dir / filename, "wb") as f:
|
|
|
f.write(etree.tostring(root, xml_declaration=True, encoding='utf-8', pretty_print=True))
|
|
|
logger.info("> Exporte: {}".format(filename))
|