forked from solid-lines/dhis2-metadata-checkers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_programRuleVariable_name.py
40 lines (27 loc) · 1.74 KB
/
check_programRuleVariable_name.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import utils
import os
import re
if __name__ == "__main__":
credentials = utils.get_credentials()
check_name = os.path.basename(__file__).replace(".py", "")
logger = utils.get_logger(credentials, check_name)
server_url = credentials["server"]
############################################################################
RESOURCE_TYPE = "programRuleVariables"
#retrieve all metadata_resources
metadata_resources = utils.get_resources_from_online(credentials=credentials, resource_type=RESOURCE_TYPE, fields="id,name,program[name,id]", param_filter=None)
for resource in metadata_resources[RESOURCE_TYPE]:
forbidden = ["and", "or", "not"] # (dhis version >= 2.34)
#update for inicio de linea y fin de linea
if any([" "+substring+" " in resource["name"] for substring in forbidden]) or \
any([resource["name"].startswith(substring+" ") for substring in forbidden]) or \
any([resource["name"].endswith(" "+substring) for substring in forbidden]):
metadata_url = server_url+RESOURCE_TYPE+"/"+resource["id"]
message = f"In Program '{resource['program']['name']}' ({resource['program']['id']}), the PRV {resource['name']} ({resource['id']}) contains 'and/or/not'. See {metadata_url}"
logger.error(message)
if not bool(re.match("^[a-zA-Z\d_\-\.\ ]+$", resource["name"])):
metadata_url = server_url+RESOURCE_TYPE+"/"+resource["id"]
message = f"In Program '{resource['program']['name']}' ({resource['program']['id']}), the PRV {resource['name']} ({resource['id']}) contains unexpected characters. See {metadata_url}"
logger.error(message)