diff --git a/src/mtd_sync/mtd_sync.py b/src/mtd_sync/mtd_sync.py index 9cc520c..02329d3 100644 --- a/src/mtd_sync/mtd_sync.py +++ b/src/mtd_sync/mtd_sync.py @@ -35,9 +35,7 @@ # config logger logger.setLevel(configuration_mtd["SYNC_LOG_LEVEL"]) handler = logging.StreamHandler() -formatter = logging.Formatter( - "%(asctime)s | %(levelname)s : %(message)s", "%Y-%m-%d %H:%M:%S" -) +formatter = logging.Formatter("%(asctime)s | %(levelname)s : %(message)s", "%Y-%m-%d %H:%M:%S") handler.setFormatter(formatter) logger.addHandler(handler) # avoid logging output dupplication diff --git a/src/mtd_sync/mtd_utils.py b/src/mtd_sync/mtd_utils.py index 4630a7b..e420493 100644 --- a/src/mtd_sync/mtd_utils.py +++ b/src/mtd_sync/mtd_utils.py @@ -56,9 +56,7 @@ def sync_ds(ds, cd_nomenclatures): af_uuid = ds.pop("uuid_acquisition_framework") af = ( DB.session.execute( - select(TAcquisitionFramework).filter_by( - unique_acquisition_framework_id=af_uuid - ) + select(TAcquisitionFramework).filter_by(unique_acquisition_framework_id=af_uuid) ) .unique() .scalar_one_or_none() @@ -71,9 +69,7 @@ def sync_ds(ds, cd_nomenclatures): ds["id_acquisition_framework"] = af.id_acquisition_framework ds = { field.replace("cd_nomenclature", "id_nomenclature"): ( - func.ref_nomenclatures.get_id_nomenclature( - NOMENCLATURE_MAPPING[field], value - ) + func.ref_nomenclatures.get_id_nomenclature(NOMENCLATURE_MAPPING[field], value) if field.startswith("cd_nomenclature") else value ) @@ -128,9 +124,7 @@ def sync_af(af): """ af_uuid = af["unique_acquisition_framework_id"] af_exists = DB.session.scalar( - exists() - .where(TAcquisitionFramework.unique_acquisition_framework_id == af_uuid) - .select() + exists().where(TAcquisitionFramework.unique_acquisition_framework_id == af_uuid).select() ) # Update statement if AF already exists in DB else insert statement @@ -163,9 +157,7 @@ def add_or_update_organism(uuid, nom, email): :param email: org email """ # Test if actor already exists to avoid nextVal increase - org_exist = DB.session.scalar( - exists().where(BibOrganismes.uuid_organisme == uuid).select() - ) + org_exist = DB.session.scalar(exists().where(BibOrganismes.uuid_organisme == uuid).select()) if org_exist: statement = ( @@ -266,9 +258,7 @@ class CasAuthentificationError(GeonatureApiError): def insert_user_and_org(info_user, update_user_organism: bool = True): id_provider_inpn = current_app.config["MTD_SYNC"]["ID_PROVIDER_INPN"] if not id_provider_inpn in auth_manager: - raise GeonatureApiError( - f"Identity provider named {id_provider_inpn} is not registered ! " - ) + raise GeonatureApiError(f"Identity provider named {id_provider_inpn} is not registered ! ") inpn_identity_provider = auth_manager.get_provider(id_provider_inpn) organism_id = info_user["codeOrganisme"] @@ -280,9 +270,7 @@ def insert_user_and_org(info_user, update_user_organism: bool = True): assert user_id is not None and user_login is not None except AssertionError: log.error("'CAS ERROR: no ID or LOGIN provided'") - raise CasAuthentificationError( - "CAS ERROR: no ID or LOGIN provided", status_code=500 - ) + raise CasAuthentificationError("CAS ERROR: no ID or LOGIN provided", status_code=500) # Reconciliation avec base GeoNature if organism_id: @@ -314,10 +302,7 @@ def insert_user_and_org(info_user, update_user_organism: bool = True): user = existing_user or db.session.get(User, user_id) if not user.groups: - if ( - current_app.config["MTD_SYNC"]["USERS_CAN_SEE_ORGANISM_DATA"] - and organism_id - ): + if current_app.config["MTD_SYNC"]["USERS_CAN_SEE_ORGANISM_DATA"] and organism_id: # group socle 2 - for a user associated to an organism if users can see data from their organism group_id = current_app.config["MTD_SYNC"]["ID_USER_SOCLE_2"] else: diff --git a/src/mtd_sync/mtd_webservice.py b/src/mtd_sync/mtd_webservice.py index 7ceee84..3cabc38 100644 --- a/src/mtd_sync/mtd_webservice.py +++ b/src/mtd_sync/mtd_webservice.py @@ -37,9 +37,7 @@ def get_jdd_by_user_id(id_user): assert r.status_code == 200 except AssertionError: raise GeonatureApiError( - message="Error with the MTD Web Service (JDD), status_code: {}".format( - r.status_code - ) + message="Error with the MTD Web Service (JDD), status_code: {}".format(r.status_code) ) return r.content diff --git a/src/mtd_sync/xml_parser.py b/src/mtd_sync/xml_parser.py index 45a8f02..7b1d86d 100644 --- a/src/mtd_sync/xml_parser.py +++ b/src/mtd_sync/xml_parser.py @@ -75,15 +75,13 @@ def parse_acquisition_framwork_xml(xml): def parse_acquisition_framework(ca): # We extract all the required informations from the different tags of the XML file ca_uuid = get_tag_content(ca, "identifiantCadre") - ca_name_max_length = ( - TAcquisitionFramework.acquisition_framework_name.property.columns[0].type.length - ) + ca_name_max_length = TAcquisitionFramework.acquisition_framework_name.property.columns[ + 0 + ].type.length ca_name = get_tag_content(ca, "libelle")[: ca_name_max_length - 1] ca_desc = get_tag_content(ca, "description", default_value="") date_info = ca.find(namespace + "ReferenceTemporelle") - ca_create_date = get_tag_content( - ca, "dateCreationMtd", default_value=datetime.datetime.now() - ) + ca_create_date = get_tag_content(ca, "dateCreationMtd", default_value=datetime.datetime.now()) ca_update_date = get_tag_content(ca, "dateMiseAJourMtd") ca_start_date = get_tag_content( date_info, "dateLancement", default_value=datetime.datetime.now() @@ -139,15 +137,11 @@ def parse_jdd_xml(xml): dataset_name = get_tag_content(jdd, "libelle") dataset_shortname = get_tag_content(jdd, "libelleCourt", default_value="") dataset_desc = get_tag_content(jdd, "description", default_value="") - terrestrial_domain = get_tag_content( - jdd, "domaineTerrestre", default_value=False - ) + terrestrial_domain = get_tag_content(jdd, "domaineTerrestre", default_value=False) marine_domain = get_tag_content(jdd, "domaineMarin", default_value=False) data_type = get_tag_content(jdd, "typeDonnees") collect_data_type = get_tag_content(jdd, "typeDonneesCollectees") - create_date = get_tag_content( - jdd, "dateCreation", default_value=datetime.datetime.now() - ) + create_date = get_tag_content(jdd, "dateCreation", default_value=datetime.datetime.now()) update_date = get_tag_content(jdd, "dateRevision") attributs_additionnels_node = jdd.find(namespace + "attributsAdditionnels")