Skip to content

Commit

Permalink
fix tmp file name w/ tempfile lib
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc-Andre Morin authored and Marc-Andre Morin committed May 8, 2020
1 parent 4dd422b commit cd66567
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
7 changes: 5 additions & 2 deletions pgrastertime/data/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import geoalchemy2
import sqlalchemy as sa
import tempfile

from pgrastertime import CONFIG, ROOT
from pgrastertime.compat import fspath
Expand Down Expand Up @@ -109,14 +110,16 @@ def setMetadataeTableStructure(target_name):

def switchTemplateTableName(self, filename):
# need to replace template table name 'pgrastrtime'
tmpfile = "/tmp/pgrastmp.sql"
pf_ , tmpfile = tempfile.mkstemp()
## tmpfile = "/tmp/pgrastmp.sql"

with open(filename) as f:
sqlfile = f.readlines()
f.close
patch = [l.replace("pgrastertime", self.tablename) for l in sqlfile]
with open(tmpfile,"w") as w:
w.write("".join(patch))
f.close
w.close
return tmpfile
return ''

Expand Down
20 changes: 10 additions & 10 deletions sql/validate.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@ select 'The pgrastertime table containe ' || count(distinct(objnam)) || ' objnam
WITH
o as (SELECT distinct(objnam) as objnam FROM pgrastertime_metadata),
s as (
SELECT 7 as res, count(o.objnam) || ' rows deploy in soundings_16m' as cnt FROM o, wis.soundings_16m s WHERE s.metadata_id = o.objnam
SELECT 7 as res, count(o.objnam) || ' rows deploy in wis.soundings_16m' as cnt FROM o, wis.soundings_16m s WHERE s.metadata_id = o.objnam
union
SELECT 6 as res, count(o.objnam) || ' rows deploy in soundings_8m' as cnt FROM o, wis.soundings_8m s WHERE s.metadata_id = o.objnam
SELECT 6 as res, count(o.objnam) || ' rows deploy in wis.soundings_8m' as cnt FROM o, wis.soundings_8m s WHERE s.metadata_id = o.objnam
union
SELECT 5 as res,count(o.objnam) || ' rows deploy in soundings_4m' as cnt FROM o, wis.soundings_4m s WHERE s.metadata_id = o.objnam
SELECT 5 as res,count(o.objnam) || ' rows deploy in wis.soundings_4m' as cnt FROM o, wis.soundings_4m s WHERE s.metadata_id = o.objnam
union
SELECT 4 as res,count(o.objnam) || ' rows deploy in soundings_2m' as cnt FROM o, wis.soundings_2m s WHERE s.metadata_id = o.objnam
SELECT 4 as res,count(o.objnam) || ' rows deploy in wis.soundings_2m' as cnt FROM o, wis.soundings_2m s WHERE s.metadata_id = o.objnam
union
SELECT 3 as res,count(o.objnam) || ' rows deploy in soundings_1m' as cnt FROM o, wis.soundings_1m s WHERE s.metadata_id = o.objnam
SELECT 3 as res,count(o.objnam) || ' rows deploy in wis.soundings_1m' as cnt FROM o, wis.soundings_1m s WHERE s.metadata_id = o.objnam
ORDER by res)
SELECT s.cnt from s;
WITH
i as (
select 7 as res, count(*) || ' rows invalidate in soundings_16m' as cnt from wis.soundings_16m s where metadata_id IN (SELECT distinct(objnam) as objnam FROM pgrastertime_metadata) and upper (sys_period) is not null
select 7 as res, count(*) || ' rows invalidate in wis.soundings_16m' as cnt from wis.soundings_16m s where metadata_id IN (SELECT distinct(objnam) as objnam FROM pgrastertime_metadata) and upper (sys_period) is not null
union
select 6 as res, count(*) || ' rows invalidate in soundings_8m' as cnt from wis.soundings_8m s where metadata_id IN (SELECT distinct(objnam) as objnam FROM pgrastertime_metadata) and upper (sys_period) is not null
select 6 as res, count(*) || ' rows invalidate in wis.soundings_8m' as cnt from wis.soundings_8m s where metadata_id IN (SELECT distinct(objnam) as objnam FROM pgrastertime_metadata) and upper (sys_period) is not null
union
select 5 as res, count(*) || ' rows invalidate in soundings_4m' as cnt from soundings_4m s where metadata_id IN (SELECT distinct(objnam) as objnam FROM pgrastertime_metadata) and upper (sys_period) is not null
select 5 as res, count(*) || ' rows invalidate in wis.soundings_4m' as cnt from wis.soundings_4m s where metadata_id IN (SELECT distinct(objnam) as objnam FROM pgrastertime_metadata) and upper (sys_period) is not null
union
select 4 as res, count(*) || ' rows invalidate in soundings_2m' as cnt from wis.soundings_2m s where metadata_id IN (SELECT distinct(objnam) as objnam FROM pgrastertime_metadata) and upper (sys_period) is not null
select 4 as res, count(*) || ' rows invalidate in wis.soundings_2m' as cnt from wis.soundings_2m s where metadata_id IN (SELECT distinct(objnam) as objnam FROM pgrastertime_metadata) and upper (sys_period) is not null
union
select 3 as res, count(*) || ' rows invalidate in soundings_1m' as cnt from wis.soundings_1m s where metadata_id IN (SELECT distinct(objnam) as objnam FROM pgrastertime_metadata) and upper (sys_period) is not null
select 3 as res, count(*) || ' rows invalidate in wis.soundings_1m' as cnt from wis.soundings_1m s where metadata_id IN (SELECT distinct(objnam) as objnam FROM pgrastertime_metadata) and upper (sys_period) is not null
)SELECT cnt from i order by res;

0 comments on commit cd66567

Please sign in to comment.