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

Windows support #354

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
18 changes: 18 additions & 0 deletions ordinary_data/functions/rewrite_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import psycopg2
import os
import pathlib

print("Rewriting functions")

this_dir = pathlib.Path(__file__).parent.absolute()

connection = psycopg2.connect("service={0}".format(os.environ.get("PGSERVICE")))
connection.set_session(autocommit=True)
cursor = connection.cursor()

for file in os.listdir(this_dir):
print(f"Rewriting function {file}")
if not file.endswith(".sql"):
continue
cursor.execute(open(this_dir / file).read())

12 changes: 0 additions & 12 deletions ordinary_data/functions/rewrite_functions.sh

This file was deleted.

51 changes: 51 additions & 0 deletions ordinary_data/views/insert_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import psycopg2
import pathlib
import subprocess
import os

print("Inserting views")

this_dir = pathlib.Path(__file__).parent.absolute()

connection = psycopg2.connect("service={0}".format(os.environ.get("PGSERVICE")))
connection.set_session(autocommit=True)
cursor = connection.cursor()

# schematic
cursor.execute(open(this_dir / "schematic" / "vw_pipe_schema.sql").read().replace(":SRID", os.environ.get("SRID")))

# inheritance
subprocess.run(["python", str(this_dir / "inheritance" / "od_all_inheritance.py"), os.environ.get("PGSERVICE")], check=True, shell=True)

# export
export_dir = this_dir / "export"
cursor.execute(open(export_dir / "vw_consumptionzone.sql").read().replace(":SRID", os.environ.get("SRID")))
cursor.execute(open(export_dir / "vw_protectionzone.sql").read().replace(":SRID", os.environ.get("SRID")))


sql = subprocess.check_output(["python", str(export_dir / "export_installation.py"), os.environ.get("PGSERVICE")], shell=True)
cursor.execute(sql)
sql = subprocess.check_output(["python", str(export_dir / "export_valve.py"), os.environ.get("PGSERVICE")], shell=True)
cursor.execute(sql)
sql = subprocess.check_output(["python", str(export_dir / "export_hydrant.py"), os.environ.get("PGSERVICE")], shell=True)
cursor.execute(sql)
sql = subprocess.check_output(["python", str(export_dir / "export_meter.py"), os.environ.get("PGSERVICE")], shell=True)
cursor.execute(sql)
sql = subprocess.check_output(["python", str(export_dir / "export_part.py"), os.environ.get("PGSERVICE")], shell=True)
cursor.execute(sql)
sql = subprocess.check_output(["python", str(export_dir / "export_pipe.py"), os.environ.get("SRID"), os.environ.get("PGSERVICE")], shell=True)
cursor.execute(sql)
sql = subprocess.check_output(["python", str(export_dir / "export_printmap.py"), os.environ.get("PGSERVICE")], shell=True)
cursor.execute(sql)
sql = subprocess.check_output(["python", str(export_dir / "export_remote.py"), os.environ.get("PGSERVICE")], shell=True)
cursor.execute(sql)
sql = subprocess.check_output(["python", str(export_dir / "export_subscriber.py"), os.environ.get("PGSERVICE")], shell=True)
cursor.execute(sql)
sql = subprocess.check_output(["python", str(export_dir / "export_leak.py"), os.environ.get("PGSERVICE")], shell=True) # depends on export_pip
cursor.execute(sql)

# draw lines
lines_dir = this_dir / "draw_lines"
cursor.execute(open(lines_dir / "vw_subscriber_pipe_relation.sql").read().replace(":SRID", os.environ.get("SRID")))
cursor.execute(open(lines_dir / "vw_valve_lines.sql").read().replace(":SRID", os.environ.get("SRID")))
cursor.execute(open(lines_dir / "vw_pipe_child_parent.sql").read().replace(":SRID", os.environ.get("SRID")))
37 changes: 0 additions & 37 deletions ordinary_data/views/insert_views.sh

This file was deleted.

18 changes: 18 additions & 0 deletions ordinary_data/views/rewrite_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import psycopg2
import os
import pathlib
import subprocess

print("Rewriting views")

this_dir = pathlib.Path(__file__).parent.absolute()

connection = psycopg2.connect("service={0}".format(os.environ.get("PGSERVICE")))
connection.set_session(autocommit=True)
cursor = connection.cursor()

print("Dropping views")
cursor.execute(open(this_dir / "drop_views.sql").read())

print("Inserting views")
subprocess.run(["python", str(this_dir /"insert_views.py")], check=True, shell=True)
8 changes: 0 additions & 8 deletions ordinary_data/views/rewrite_views.sh

This file was deleted.

2 changes: 1 addition & 1 deletion update/delta/delta_1.3.6_add_vl_for_SIA_export.sql
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ UPDATE qwat_vl.bedding SET sia405code = 'unbekannt' WHERE value_fr = 'terre';
-- UPDATE qwat_vl.cover_type SET sia405code = 'unbekannt' WHERE ???;

-- Hydrant material : mapping complete [X] to check [X]
UPDATE qwat_vl.hydrant_material SET sia405code = 'Metall' WHERE short_fr LIKE 'F %';
UPDATE qwat_vl.hydrant_material SET sia405code = 'Metall' WHERE short_fr LIKE 'F %%';
UPDATE qwat_vl.hydrant_material SET sia405code = 'unbekannt' WHERE value_fr = 'autre';
UPDATE qwat_vl.hydrant_material SET sia405code = 'unbekannt' WHERE value_fr = 'inconnu';
UPDATE qwat_vl.hydrant_material SET sia405code = 'unbekannt' WHERE value_fr = 'à déterminer';
Expand Down
32 changes: 18 additions & 14 deletions update/delta/post-all.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
from pum.core.deltapy import DeltaPy
import os
import pathlib
import subprocess

import psycopg2

class RecreateViewsAndFunctions(DeltaPy):

def run(self):
srid = subprocess.check_output("""psql service={} -c "SELECT DISTINCT srid FROM public.geometry_columns
WHERE f_table_schema = 'qwat_od'" -q -t -A""".format(self.pg_service), shell=True)

srid = int(srid)
this_dir = pathlib.Path(__file__).parent.absolute()

connection = psycopg2.connect(f"service={self.pg_service}")
connection.set_session(autocommit=True)
cursor = connection.cursor()

self.write_message("Reloading views and functions")

views_sh = os.path.join(self.delta_dir, '..', '..', 'ordinary_data', 'views',
'rewrite_views.sh')
views_cmd = 'PGSERVICE={} SRID={} {}'.format(
self.pg_service, srid, views_sh)
functions_sh = os.path.join(self.delta_dir, '..', '..', 'ordinary_data', 'functions',
'rewrite_functions.sh')
functions_cmd = 'PGSERVICE={} SRID={} {}'.format(
self.pg_service, srid, functions_sh)
os.system(views_cmd)
os.system(functions_cmd)
cursor.execute("SELECT DISTINCT srid FROM public.geometry_columns WHERE f_table_schema = 'qwat_od'")
srid = str(cursor.fetchone()[0])

os.environ.update({
"PGSERVICE": self.pg_service,
"SRID": srid,
})
data_dir = this_dir / '..' / '..' / 'ordinary_data'
subprocess.run(["python", str(data_dir / 'views' / 'rewrite_views.py')], check=True, shell=True)
subprocess.run(["python", str(data_dir / 'functions' / 'rewrite_functions.py')], check=True, shell=True)

self.write_message("Reloading views and functions: done")

19 changes: 13 additions & 6 deletions update/delta/pre-all.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from pum.core.deltapy import DeltaPy
import pkg_resources
import os
import pathlib
import subprocess
import psycopg2

class DropViews(DeltaPy):

Expand All @@ -18,10 +20,15 @@ def run(self):
def drop_views(self):
self.write_message("Dropping views")

drop_sql = os.path.join(self.delta_dir, '..', '..', 'ordinary_data', 'views',
'drop_views.sql')
cmd = 'psql service={} -f {}'.format(self.pg_service, drop_sql)
self.write_message(cmd)
os.system(cmd)
connection = psycopg2.connect("service={0}".format(self.pg_service))
cursor = connection.cursor()


data_path = pathlib.Path(self.delta_dir) / '..' / '..' / 'ordinary_data'
dropviews_script = data_path / 'views' / 'drop_views.sql'

cursor.execute(open(dropviews_script, "r").read())

connection.commit()
self.write_message("Dropping views: done")