bcdata 0.10.0__tar.gz → 0.10.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. {bcdata-0.10.0 → bcdata-0.10.2}/CHANGES.txt +8 -0
  2. {bcdata-0.10.0/bcdata.egg-info → bcdata-0.10.2}/PKG-INFO +1 -1
  3. {bcdata-0.10.0 → bcdata-0.10.2}/bcdata/__init__.py +1 -1
  4. {bcdata-0.10.0 → bcdata-0.10.2}/bcdata/cli.py +11 -2
  5. {bcdata-0.10.0 → bcdata-0.10.2}/bcdata/database.py +24 -17
  6. {bcdata-0.10.0 → bcdata-0.10.2/bcdata.egg-info}/PKG-INFO +1 -1
  7. {bcdata-0.10.0 → bcdata-0.10.2}/tests/test_cli.py +17 -0
  8. {bcdata-0.10.0 → bcdata-0.10.2}/LICENSE.txt +0 -0
  9. {bcdata-0.10.0 → bcdata-0.10.2}/README.md +0 -0
  10. {bcdata-0.10.0 → bcdata-0.10.2}/bcdata/bc2pg.py +0 -0
  11. {bcdata-0.10.0 → bcdata-0.10.2}/bcdata/bcdc.py +0 -0
  12. {bcdata-0.10.0 → bcdata-0.10.2}/bcdata/wcs.py +0 -0
  13. {bcdata-0.10.0 → bcdata-0.10.2}/bcdata/wfs.py +0 -0
  14. {bcdata-0.10.0 → bcdata-0.10.2}/bcdata.egg-info/SOURCES.txt +0 -0
  15. {bcdata-0.10.0 → bcdata-0.10.2}/bcdata.egg-info/dependency_links.txt +0 -0
  16. {bcdata-0.10.0 → bcdata-0.10.2}/bcdata.egg-info/entry_points.txt +0 -0
  17. {bcdata-0.10.0 → bcdata-0.10.2}/bcdata.egg-info/not-zip-safe +0 -0
  18. {bcdata-0.10.0 → bcdata-0.10.2}/bcdata.egg-info/requires.txt +0 -0
  19. {bcdata-0.10.0 → bcdata-0.10.2}/bcdata.egg-info/top_level.txt +0 -0
  20. {bcdata-0.10.0 → bcdata-0.10.2}/pyproject.toml +0 -0
  21. {bcdata-0.10.0 → bcdata-0.10.2}/requirements.txt +0 -0
  22. {bcdata-0.10.0 → bcdata-0.10.2}/setup.cfg +0 -0
  23. {bcdata-0.10.0 → bcdata-0.10.2}/setup.py +0 -0
  24. {bcdata-0.10.0 → bcdata-0.10.2}/tests/test_bc2pg.py +0 -0
  25. {bcdata-0.10.0 → bcdata-0.10.2}/tests/test_bcdc.py +0 -0
  26. {bcdata-0.10.0 → bcdata-0.10.2}/tests/test_wcs.py +0 -0
  27. {bcdata-0.10.0 → bcdata-0.10.2}/tests/test_wfs.py +0 -0
@@ -1,6 +1,14 @@
1
1
  Changes
2
2
  =======
3
3
 
4
+ 0.10.2 (2024-03-01)
5
+ ------------------
6
+ - improve connection management for better stability (#171)
7
+
8
+ 0.10.1 (2024-02-19)
9
+ ------------------
10
+ - check that table to be refreshed exists when using bc2pg --refresh (#167)
11
+
4
12
  0.10.0 (2024-02-19)
5
13
  ------------------
6
14
  - store known primary keys in repository (data/primary_keys.json)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: bcdata
3
- Version: 0.10.0
3
+ Version: 0.10.2
4
4
  Summary: Python tools for quick access to DataBC geo-data available via WFS
5
5
  Home-page: https://github.com/smnorris/bcdata
6
6
  Author: Simon Norris
@@ -15,4 +15,4 @@ PRIMARY_KEY_DB_URL = (
15
15
  "https://raw.githubusercontent.com/smnorris/bcdata/main/data/primary_keys.json"
16
16
  )
17
17
 
18
- __version__ = "0.10.0"
18
+ __version__ = "0.10.2"
@@ -395,9 +395,16 @@ def bc2pg(
395
395
  elif refresh and schema:
396
396
  schema_target = schema
397
397
  elif refresh and not schema:
398
- schema_target, t = bcdata.validate_name(dataset).lower().split(".")
398
+ schema_target, table = bcdata.validate_name(dataset).lower().split(".")
399
399
  if refresh:
400
+ db = Database(db_url)
400
401
  schema = "bcdata"
402
+ if not table:
403
+ table = bcdata.validate_name(dataset).lower().split(".")
404
+ if schema_target + "." + table not in db.tables:
405
+ raise ValueError(
406
+ f"Cannot refresh, {schema_target}.{table} not found in database"
407
+ )
401
408
  out_table = bcdata.bc2pg(
402
409
  dataset,
403
410
  db_url,
@@ -420,4 +427,6 @@ def bc2pg(
420
427
  db.refresh(schema_target, table)
421
428
  out_table = schema_target + "." + table
422
429
 
423
- log.info("Load of {} to {} in {} complete".format(dataset, out_table, db_url))
430
+ # do not notify of data load completion when no data load has occured
431
+ if not schema_only:
432
+ log.info("Load of {} to {} in {} complete".format(dataset, out_table, db_url))
@@ -1,9 +1,8 @@
1
1
  import logging
2
2
  import os
3
3
 
4
- import psycopg2
5
4
  from geoalchemy2 import Geometry
6
- from psycopg2 import sql
5
+ from psycopg2 import errors, sql
7
6
  from sqlalchemy import Column, MetaData, Table, create_engine
8
7
  from sqlalchemy.dialects.postgresql import DATE, NUMERIC, VARCHAR
9
8
 
@@ -11,18 +10,20 @@ log = logging.getLogger(__name__)
11
10
 
12
11
 
13
12
  class Database(object):
14
- """Wrapper around psycopg2 and sqlachemy"""
13
+ """Wrapper around sqlalchemy"""
15
14
 
16
15
  def __init__(self, url=os.environ.get("DATABASE_URL")):
17
16
  self.url = url
18
17
  self.engine = create_engine(url)
19
- self.conn = psycopg2.connect(url)
20
18
  # make sure postgis is available
21
19
  try:
22
20
  self.query("SELECT postgis_full_version()")
23
- except psycopg2.errors.UndefinedFunction:
24
- log.error("Cannot find PostGIS, is extension added to database %s ?", url)
25
- raise psycopg2.errors.UndefinedFunction
21
+ except errors.UndefinedFunction:
22
+ log.error(
23
+ "Cannot find PostGIS, has extension been installed on database %s ?",
24
+ url,
25
+ )
26
+ raise errors.UndefinedFunction
26
27
 
27
28
  # supported oracle/wfs to postgres types
28
29
  self.supported_types = {
@@ -56,24 +57,26 @@ class Database(object):
56
57
 
57
58
  def query(self, sql, params=None):
58
59
  """Execute sql and return all results"""
59
- with self.conn:
60
- with self.conn.cursor() as curs:
61
- curs.execute(sql, params)
62
- result = curs.fetchall()
60
+ conn = self.engine.raw_connection()
61
+ with conn.cursor() as curs:
62
+ curs.execute(sql, params)
63
+ result = curs.fetchall()
63
64
  return result
64
65
 
65
66
  def execute(self, sql, params=None):
66
67
  """Execute sql and return only whether the query was successful"""
67
- with self.conn:
68
- with self.conn.cursor() as curs:
69
- result = curs.execute(sql, params)
68
+ conn = self.engine.raw_connection()
69
+ with conn.cursor() as curs:
70
+ result = curs.execute(sql, params)
71
+ conn.commit()
70
72
  return result
71
73
 
72
74
  def execute_many(self, sql, params):
73
75
  """Execute many sql"""
74
- with self.conn:
75
- with self.conn.cursor() as curs:
76
- curs.executemany(sql, params)
76
+ conn = self.engine.raw_connection()
77
+ with conn.cursor() as curs:
78
+ curs.executemany(sql, params)
79
+ conn.commit()
77
80
 
78
81
  def create_schema(self, schema):
79
82
  if schema not in self.schemas:
@@ -120,6 +123,10 @@ class Database(object):
120
123
  )
121
124
  self.execute(dbq)
122
125
  self.drop_table("bcdata", table)
126
+ else:
127
+ raise ValueError(
128
+ f"Target table {schema}.{table} does not exist in database"
129
+ )
123
130
 
124
131
  def define_table(
125
132
  self,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: bcdata
3
- Version: 0.10.0
3
+ Version: 0.10.2
4
4
  Summary: Python tools for quick access to DataBC geo-data available via WFS
5
5
  Home-page: https://github.com/smnorris/bcdata
6
6
  Author: Simon Norris
@@ -112,3 +112,20 @@ def test_bc2pg_refresh():
112
112
  assert AIRPORTS_TABLE.lower() in DB_CONNECTION.tables
113
113
  assert len(q) == 1
114
114
  DB_CONNECTION.execute("drop table " + AIRPORTS_TABLE.lower())
115
+
116
+
117
+ def test_bc2pg_refresh_fails_table_does_not_exist():
118
+ runner = CliRunner()
119
+ result = runner.invoke(
120
+ cli,
121
+ [
122
+ "bc2pg",
123
+ AIRPORTS_TABLE,
124
+ "--db_url",
125
+ DB_URL,
126
+ "--count",
127
+ "1",
128
+ "--refresh",
129
+ ],
130
+ )
131
+ assert result.exit_code == 1
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes