From 4a831642d11f4d283e7f9fab2e9af3333eb36926 Mon Sep 17 00:00:00 2001 From: idelcano Date: Thu, 27 May 2021 17:43:56 +0200 Subject: [PATCH 1/2] added org unit tree diff script --- DHIS2/orgunit_tree_diff.py | 42 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 DHIS2/orgunit_tree_diff.py diff --git a/DHIS2/orgunit_tree_diff.py b/DHIS2/orgunit_tree_diff.py new file mode 100644 index 00000000..06936472 --- /dev/null +++ b/DHIS2/orgunit_tree_diff.py @@ -0,0 +1,42 @@ +import psycopg2 +import csv + +def con(database, user, password, host): + conn = psycopg2.connect( + database=database, user=user, password=password, host=host, port= '5432' + ) + return conn + +def get_rows(host): + con_prod = con("dhis2", "dhis", "dhis", host) + cur_p = con_prod.cursor() + cur_p.execute("SELECT uid, path, name, shortname, code FROM organisationunit") + + rows = cur_p.fetchall() + print("The number of parts: ", cur_p.rowcount) + con_prod.close() + return rows + + +def iterate_queries(prod_rows, dev_rows, filename): + with open(filename, mode='w') as employee_file: + employee_writer = csv.writer(employee_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) + employee_writer.writerow(['uid', 'path', 'name', 'shortName', 'code','uid', 'path', 'name', 'shortName', 'code']) + for row in prod_rows: + for dev_row in dev_rows: + if (row[0] == dev_row[0]): + if (row == dev_row): + d = row+ dev_row + employee_writer.writerow(d) + continue + else: + d = row + employee_writer.writerow(d) + continue + + +prod_rows = get_rows("172.27.0.2") +dev_rows = get_rows("172.24.0.2") +iterate_queries(prod_rows, dev_rows, "prod-dev.csv") +print("dev to prod") +iterate_queries(dev_rows,prod_rows, "dev-prod.csv") From 9c801416128aeed5b9f659d43e4a98d762e3c650 Mon Sep 17 00:00:00 2001 From: idelcano Date: Fri, 28 May 2021 19:51:44 +0200 Subject: [PATCH 2/2] added orgunittreediff between two docker db --- DHIS2/orgunit_tree_diff.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/DHIS2/orgunit_tree_diff.py b/DHIS2/orgunit_tree_diff.py index 06936472..f0489759 100644 --- a/DHIS2/orgunit_tree_diff.py +++ b/DHIS2/orgunit_tree_diff.py @@ -21,18 +21,21 @@ def get_rows(host): def iterate_queries(prod_rows, dev_rows, filename): with open(filename, mode='w') as employee_file: employee_writer = csv.writer(employee_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) - employee_writer.writerow(['uid', 'path', 'name', 'shortName', 'code','uid', 'path', 'name', 'shortName', 'code']) + employee_writer.writerow(['uid', 'path', 'name', 'shortName', 'code','uid', 'path', 'name', 'shortName', 'code', 'samepath', 'samename', 'sameshortname', 'samecode']) for row in prod_rows: + exist = False for dev_row in dev_rows: if (row[0] == dev_row[0]): + exist = True if (row == dev_row): - d = row+ dev_row - employee_writer.writerow(d) continue else: - d = row + d = row + dev_row + (row[1] == dev_row[1],) + (row[2] == dev_row[2],) + (row[3] == dev_row[3],)+ (row[4] == dev_row[4],) employee_writer.writerow(d) continue + if not exist: + d = row + employee_writer.writerow(d) prod_rows = get_rows("172.27.0.2")