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

collapse pco sub-orgs' briefingt/qpnotes records under pco #1342

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
40 changes: 40 additions & 0 deletions bin/migrate/migrate_briefingt_2022_12.py
Original file line number Diff line number Diff line change
@@ -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)
40 changes: 40 additions & 0 deletions bin/migrate/migrate_contracts_2022_12.py
Original file line number Diff line number Diff line change
@@ -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)
57 changes: 57 additions & 0 deletions bin/migrate/migrate_contracts_nil_2022_12.py
Original file line number Diff line number Diff line change
@@ -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)
40 changes: 40 additions & 0 deletions bin/migrate/migrate_hospitalityq_2022_12.py
Original file line number Diff line number Diff line change
@@ -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)
58 changes: 58 additions & 0 deletions bin/migrate/migrate_hospitalityq_nil_2022_12.py
Original file line number Diff line number Diff line change
@@ -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)
40 changes: 40 additions & 0 deletions bin/migrate/migrate_qpnotes_2022_12.py
Original file line number Diff line number Diff line change
@@ -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)
40 changes: 40 additions & 0 deletions bin/migrate/migrate_travela_2022_12.py
Original file line number Diff line number Diff line change
@@ -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)
40 changes: 40 additions & 0 deletions bin/migrate/migrate_travelq_2022_12.py
Original file line number Diff line number Diff line change
@@ -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)
Loading