Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/compare org unit trees #115

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions DHIS2/orgunit_tree_diff.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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', '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):
continue
else:
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")
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")