diff --git a/bin/migrate/migrate_briefingt_2022_12.py b/bin/migrate/migrate_briefingt_2022_12.py new file mode 100644 index 000000000..d0bfcad19 --- /dev/null +++ b/bin/migrate/migrate_briefingt_2022_12.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python +# coding=utf-8 + +""" +migration script to copy all briefingt records +for PCO sub-organizations into PCO organization +""" + +import unicodecsv +import sys +import codecs + + +sub_orgs = [ 'ghl-lgc', + 'iga-aig', + 'mdi-mid', + 'miga-maig', + 'dpm-vpm', + 'pkcc-pcprc', + 'ql-lq', + 'srp-rsp', + 'nsira-ossnr', + 'ocsec-bccst', + 'snsicp-scpssnr', + 'sirc-csars', + 'jfpc-cfp', + ] +PCO = { 'owner_org': 'pco-bcp', + 'owner_org_title': 'Privy Council Office | Bureau du Conseil privé' } + +assert sys.stdin.read(3) == codecs.BOM_UTF8 + +in_csv = unicodecsv.DictReader(sys.stdin, encoding='utf-8') +out_csv = unicodecsv.DictWriter(sys.stdout, fieldnames=in_csv.fieldnames, encoding='utf-8') +out_csv.writeheader() + +for line in in_csv: + if line['owner_org'] in sub_orgs: + line.update(PCO) + out_csv.writerow(line) diff --git a/bin/migrate/migrate_contracts_2022_12.py b/bin/migrate/migrate_contracts_2022_12.py new file mode 100644 index 000000000..bbe736b3b --- /dev/null +++ b/bin/migrate/migrate_contracts_2022_12.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python +# coding=utf-8 + +""" +migration script to copy all contracts records +for PCO sub-organizations into PCO organization +""" + +import unicodecsv +import sys +import codecs + + +sub_orgs = [ 'ghl-lgc', + 'iga-aig', + 'mdi-mid', + 'miga-maig', + 'dpm-vpm', + 'pkcc-pcprc', + 'ql-lq', + 'srp-rsp', + 'nsira-ossnr', + 'ocsec-bccst', + 'snsicp-scpssnr', + 'sirc-csars', + 'jfpc-cfp', + ] +PCO = { 'owner_org': 'pco-bcp', + 'owner_org_title': 'Privy Council Office | Bureau du Conseil privé' } + +assert sys.stdin.read(3) == codecs.BOM_UTF8 + +in_csv = unicodecsv.DictReader(sys.stdin, encoding='utf-8') +out_csv = unicodecsv.DictWriter(sys.stdout, fieldnames=in_csv.fieldnames, encoding='utf-8') +out_csv.writeheader() + +for line in in_csv: + if line['owner_org'] in sub_orgs: + line.update(PCO) + out_csv.writerow(line) diff --git a/bin/migrate/migrate_contracts_nil_2022_12.py b/bin/migrate/migrate_contracts_nil_2022_12.py new file mode 100644 index 000000000..9900170ac --- /dev/null +++ b/bin/migrate/migrate_contracts_nil_2022_12.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python +# coding=utf-8 + +""" +migration script to copy all contracts-nil records +for PCO sub-organizations into PCO organization. +Duplicate records from sub-orgnizations for +reporting_period will be ignored +""" + +import unicodecsv +import sys +import codecs + + +sub_orgs = [ 'ghl-lgc', + 'iga-aig', + 'mdi-mid', + 'miga-maig', + 'dpm-vpm', + 'pkcc-pcprc', + 'ql-lq', + 'srp-rsp', + 'nsira-ossnr', + 'ocsec-bccst', + 'snsicp-scpssnr', + 'sirc-csars', + 'jfpc-cfp', + ] +PCO = { 'owner_org': 'pco-bcp', + 'owner_org_title': 'Privy Council Office | Bureau du Conseil privé' } + +assert sys.stdin.read(3) == codecs.BOM_UTF8 + +in_csv = unicodecsv.DictReader(sys.stdin, encoding='utf-8') +out_csv = unicodecsv.DictWriter(sys.stdout, fieldnames=in_csv.fieldnames, encoding='utf-8') +out_csv.writeheader() + +data = [] + +def report_exists(reporting_period, owner_org): + for row in data: + if row['reporting_period'] == reporting_period and \ + row['owner_org'] == owner_org: + return True + return False + +for line in in_csv: + if line['owner_org'] in sub_orgs: + if not report_exists(line['reporting_period'], PCO['owner_org']): + line.update(PCO) + data.append(line) + else: + data.append(line) + +for line in data: + out_csv.writerow(line) diff --git a/bin/migrate/migrate_hospitalityq_2022_12.py b/bin/migrate/migrate_hospitalityq_2022_12.py new file mode 100644 index 000000000..54889985e --- /dev/null +++ b/bin/migrate/migrate_hospitalityq_2022_12.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python +# coding=utf-8 + +""" +migration script to copy all hospitalityq records +for PCO sub-organizations into PCO organization +""" + +import unicodecsv +import sys +import codecs + + +sub_orgs = [ 'ghl-lgc', + 'iga-aig', + 'mdi-mid', + 'miga-maig', + 'dpm-vpm', + 'pkcc-pcprc', + 'ql-lq', + 'srp-rsp', + 'nsira-ossnr', + 'ocsec-bccst', + 'snsicp-scpssnr', + 'sirc-csars', + 'jfpc-cfp', + ] +PCO = { 'owner_org': 'pco-bcp', + 'owner_org_title': 'Privy Council Office | Bureau du Conseil privé' } + +assert sys.stdin.read(3) == codecs.BOM_UTF8 + +in_csv = unicodecsv.DictReader(sys.stdin, encoding='utf-8') +out_csv = unicodecsv.DictWriter(sys.stdout, fieldnames=in_csv.fieldnames, encoding='utf-8') +out_csv.writeheader() + +for line in in_csv: + if line['owner_org'] in sub_orgs: + line.update(PCO) + out_csv.writerow(line) diff --git a/bin/migrate/migrate_hospitalityq_nil_2022_12.py b/bin/migrate/migrate_hospitalityq_nil_2022_12.py new file mode 100644 index 000000000..00bc20d5e --- /dev/null +++ b/bin/migrate/migrate_hospitalityq_nil_2022_12.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python +# coding=utf-8 + +""" +migration script to copy all hospitalityq-nil records +for PCO sub-organizations into PCO organization. +Duplicate records from sub-orgnizations for (year,month) +will be ignored +""" + +import unicodecsv +import sys +import codecs + + +sub_orgs = [ 'ghl-lgc', + 'iga-aig', + 'mdi-mid', + 'miga-maig', + 'dpm-vpm', + 'pkcc-pcprc', + 'ql-lq', + 'srp-rsp', + 'nsira-ossnr', + 'ocsec-bccst', + 'snsicp-scpssnr', + 'sirc-csars', + 'jfpc-cfp', + ] +PCO = { 'owner_org': 'pco-bcp', + 'owner_org_title': 'Privy Council Office | Bureau du Conseil privé' } + +assert sys.stdin.read(3) == codecs.BOM_UTF8 + +in_csv = unicodecsv.DictReader(sys.stdin, encoding='utf-8') +out_csv = unicodecsv.DictWriter(sys.stdout, fieldnames=in_csv.fieldnames, encoding='utf-8') +out_csv.writeheader() + +data = [] + +def report_exists(year, month, owner_org): + for row in data: + if row['year'] == year and \ + row['month'] == month and \ + row['owner_org'] == owner_org: + return True + return False + +for line in in_csv: + if line['owner_org'] in sub_orgs: + if not report_exists(line['year'], line['month'], PCO['owner_org']): + line.update(PCO) + data.append(line) + else: + data.append(line) + +for line in data: + out_csv.writerow(line) diff --git a/bin/migrate/migrate_qpnotes_2022_12.py b/bin/migrate/migrate_qpnotes_2022_12.py new file mode 100644 index 000000000..0a19a00f0 --- /dev/null +++ b/bin/migrate/migrate_qpnotes_2022_12.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python +# coding=utf-8 + +""" +migration script to copy all qpnotes records +for PCO sub-organizations into PCO organization +""" + +import unicodecsv +import sys +import codecs + + +sub_orgs = [ 'ghl-lgc', + 'iga-aig', + 'mdi-mid', + 'miga-maig', + 'dpm-vpm', + 'pkcc-pcprc', + 'ql-lq', + 'srp-rsp', + 'nsira-ossnr', + 'ocsec-bccst', + 'snsicp-scpssnr', + 'sirc-csars', + 'jfpc-cfp', + ] +PCO = { 'owner_org': 'pco-bcp', + 'owner_org_title': 'Privy Council Office | Bureau du Conseil privé' } + +assert sys.stdin.read(3) == codecs.BOM_UTF8 + +in_csv = unicodecsv.DictReader(sys.stdin, encoding='utf-8') +out_csv = unicodecsv.DictWriter(sys.stdout, fieldnames=in_csv.fieldnames, encoding='utf-8') +out_csv.writeheader() + +for line in in_csv: + if line['owner_org'] in sub_orgs: + line.update(PCO) + out_csv.writerow(line) diff --git a/bin/migrate/migrate_travela_2022_12.py b/bin/migrate/migrate_travela_2022_12.py new file mode 100644 index 000000000..d5636d5e4 --- /dev/null +++ b/bin/migrate/migrate_travela_2022_12.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python +# coding=utf-8 + +""" +migration script to copy all travela records +for PCO sub-organizations into PCO organization +""" + +import unicodecsv +import sys +import codecs + + +sub_orgs = [ 'ghl-lgc', + 'iga-aig', + 'mdi-mid', + 'miga-maig', + 'dpm-vpm', + 'pkcc-pcprc', + 'ql-lq', + 'srp-rsp', + 'nsira-ossnr', + 'ocsec-bccst', + 'snsicp-scpssnr', + 'sirc-csars', + 'jfpc-cfp', + ] +PCO = { 'owner_org': 'pco-bcp', + 'owner_org_title': 'Privy Council Office | Bureau du Conseil privé' } + +assert sys.stdin.read(3) == codecs.BOM_UTF8 + +in_csv = unicodecsv.DictReader(sys.stdin, encoding='utf-8') +out_csv = unicodecsv.DictWriter(sys.stdout, fieldnames=in_csv.fieldnames, encoding='utf-8') +out_csv.writeheader() + +for line in in_csv: + if line['owner_org'] in sub_orgs: + line.update(PCO) + out_csv.writerow(line) diff --git a/bin/migrate/migrate_travelq_2022_12.py b/bin/migrate/migrate_travelq_2022_12.py new file mode 100644 index 000000000..f9ae73ad1 --- /dev/null +++ b/bin/migrate/migrate_travelq_2022_12.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python +# coding=utf-8 + +""" +migration script to copy all travelq records +for PCO sub-organizations into PCO organization +""" + +import unicodecsv +import sys +import codecs + + +sub_orgs = [ 'ghl-lgc', + 'iga-aig', + 'mdi-mid', + 'miga-maig', + 'dpm-vpm', + 'pkcc-pcprc', + 'ql-lq', + 'srp-rsp', + 'nsira-ossnr', + 'ocsec-bccst', + 'snsicp-scpssnr', + 'sirc-csars', + 'jfpc-cfp', + ] +PCO = { 'owner_org': 'pco-bcp', + 'owner_org_title': 'Privy Council Office | Bureau du Conseil privé' } + +assert sys.stdin.read(3) == codecs.BOM_UTF8 + +in_csv = unicodecsv.DictReader(sys.stdin, encoding='utf-8') +out_csv = unicodecsv.DictWriter(sys.stdout, fieldnames=in_csv.fieldnames, encoding='utf-8') +out_csv.writeheader() + +for line in in_csv: + if line['owner_org'] in sub_orgs: + line.update(PCO) + out_csv.writerow(line) diff --git a/bin/migrate/migrate_travelq_nil_2022_12.py b/bin/migrate/migrate_travelq_nil_2022_12.py new file mode 100644 index 000000000..fadc91f58 --- /dev/null +++ b/bin/migrate/migrate_travelq_nil_2022_12.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python +# coding=utf-8 + +""" +migration script to copy all travelq-nil records +for PCO sub-organizations into PCO organization. +Duplicate records from sub-orgnizations for (year,month) +will be ignored +""" + +import unicodecsv +import sys +import codecs + + +sub_orgs = [ 'ghl-lgc', + 'iga-aig', + 'mdi-mid', + 'miga-maig', + 'dpm-vpm', + 'pkcc-pcprc', + 'ql-lq', + 'srp-rsp', + 'nsira-ossnr', + 'ocsec-bccst', + 'snsicp-scpssnr', + 'sirc-csars', + 'jfpc-cfp', + ] +PCO = { 'owner_org': 'pco-bcp', + 'owner_org_title': 'Privy Council Office | Bureau du Conseil privé' } + +assert sys.stdin.read(3) == codecs.BOM_UTF8 + +in_csv = unicodecsv.DictReader(sys.stdin, encoding='utf-8') +out_csv = unicodecsv.DictWriter(sys.stdout, fieldnames=in_csv.fieldnames, encoding='utf-8') +out_csv.writeheader() + +data = [] + +def report_exists(year, month, owner_org): + for row in data: + if row['year'] == year and \ + row['month'] == month and \ + row['owner_org'] == owner_org: + return True + return False + +for line in in_csv: + if line['owner_org'] in sub_orgs: + if not report_exists(line['year'], line['month'], PCO['owner_org']): + line.update(PCO) + data.append(line) + else: + data.append(line) + +for line in data: + out_csv.writerow(line)