Skip to content

Commit

Permalink
Update to geodiff 1.0 (fixes #49) and version++ (1.0.5)
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Jun 9, 2021
1 parent c87123b commit e319f8a
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 21 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 1.0.5

- Switched to geodiff 1.0 and mergin-client 0.6 (#49)
- Robustness improvement: mark base schema as invalid if init fails (#46)

## 1.0.4

- More fixes for loss of precision of floating point numbers
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ RUN apt-get update && apt-get install -y \
RUN python3 -m pip install --upgrade pip
RUN pip3 install mergin-client

# geodiff (needed with PostgreSQL support and in master version)
RUN git clone https://github.com/lutraconsulting/geodiff.git
# geodiff (version >= 1.0.0 is needed with PostgreSQL support - we have to compile it)
RUN git clone --branch 1.0.0 https://github.com/lutraconsulting/geodiff.git
RUN cd geodiff && mkdir build && cd build && \
cmake -DWITH_POSTGRESQL=TRUE ../geodiff && \
make
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ CREATE TABLE sync_data.points (
To run automatic tests:
cd mergin
export TEST_GEODIFFINFO_EXE=<geodiffinfo> # path to geodiffinfo executable
export TEST_GEODIFF_EXE=<geodiff> # path to geodiff executable
export TEST_DB_CONNINFO=<conninfo> # connection info for DB
export TEST_MERGIN_URL=<url> # testing server
export TEST_API_USERNAME=<username>
Expand Down
2 changes: 1 addition & 1 deletion config-dockerfile.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

[general]
working_dir=/tmp/dbsync
geodiffinfo_exe=/geodiff/build/geodiffinfo
geodiff_exe=/geodiff/build/geodiff

[db]
driver=postgres
Expand Down
2 changes: 1 addition & 1 deletion config.ini.default
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

[general]
working_dir=/tmp/dbsync
geodiffinfo_exe=geodiffinfo
geodiff_exe=geodiff

[mergin]
username=john
Expand Down
26 changes: 13 additions & 13 deletions dbsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from version import __version__
from psycopg2 import sql

# set high logging level for geodiff (used by geodiffinfo executable)
# set high logging level for geodiff (used by geodiff executable)
# so we get as much information as possible
os.environ["GEODIFF_LOGGER_LEVEL"] = '4' # 0 = nothing, 1 = errors, 2 = warning, 3 = info, 4 = debug

Expand All @@ -37,7 +37,7 @@ class Config:

def __init__(self):
self.project_working_dir = None
self.geodiffinfo_exe = None
self.geodiff_exe = None

self.mergin_url = 'https://public.cloudmergin.com'

Expand Down Expand Up @@ -76,7 +76,7 @@ def load(self, filename):
cfg.read(filename)

self.project_working_dir = cfg['general']['working_dir']
self.geodiffinfo_exe = cfg['general']['geodiffinfo_exe']
self.geodiff_exe = cfg['general']['geodiff_exe']

if 'mergin' in cfg:
cfg_mergin = cfg['mergin']
Expand Down Expand Up @@ -143,26 +143,26 @@ def _check_has_password():


def _run_geodiff(cmd):
""" will run a command (with geodiffinfo) and report what got to stderr and raise exception
""" will run a command (with geodiff) and report what got to stderr and raise exception
if the command returns non-zero exit code """
res = subprocess.run(cmd, stderr=subprocess.PIPE)
geodiff_stderr = res.stderr.decode()
if geodiff_stderr:
print("GEODIFF: " + geodiff_stderr)
if res.returncode != 0:
raise DbSyncError("geodiffinfo failed!\n" + str(cmd))
raise DbSyncError("geodiff failed!\n" + str(cmd))


def _geodiff_create_changeset(driver, conn_info, base, modified, changeset):
_run_geodiff([config.geodiffinfo_exe, "createChangesetEx", driver, conn_info, base, modified, changeset])
_run_geodiff([config.geodiff_exe, "diff", "--driver", driver, conn_info, base, modified, changeset])


def _geodiff_apply_changeset(driver, conn_info, base, changeset):
_run_geodiff([config.geodiffinfo_exe, "applyChangesetEx", driver, conn_info, base, changeset])
_run_geodiff([config.geodiff_exe, "apply", "--driver", driver, conn_info, base, changeset])


def _geodiff_rebase(driver, conn_info, base, modified, base2their, conflicts):
_run_geodiff([config.geodiffinfo_exe, "rebaseEx", driver, conn_info, base, modified, base2their, conflicts])
def _geodiff_rebase(driver, conn_info, base, our, base2their, conflicts):
_run_geodiff([config.geodiff_exe, "rebase-db", "--driver", driver, conn_info, base, our, base2their, conflicts])


def _geodiff_list_changes_details(changeset):
Expand All @@ -173,7 +173,7 @@ def _geodiff_list_changes_details(changeset):
tmp_output = os.path.join(tmp_dir, 'dbsync-changeset-details')
if os.path.exists(tmp_output):
os.remove(tmp_output)
_run_geodiff([config.geodiffinfo_exe, "listChanges", changeset, tmp_output])
_run_geodiff([config.geodiff_exe, "as-json", changeset, tmp_output])
with open(tmp_output) as f:
out = json.load(f)
os.remove(tmp_output)
Expand All @@ -188,19 +188,19 @@ def _geodiff_list_changes_summary(changeset):
tmp_output = os.path.join(tmp_dir, 'dbsync-changeset-summary')
if os.path.exists(tmp_output):
os.remove(tmp_output)
_run_geodiff([config.geodiffinfo_exe, "listChangesSummary", changeset, tmp_output])
_run_geodiff([config.geodiff_exe, "as-summary", changeset, tmp_output])
with open(tmp_output) as f:
out = json.load(f)
os.remove(tmp_output)
return out["geodiff_summary"]


def _geodiff_make_copy(src_driver, src_conn_info, src, dst_driver, dst_conn_info, dst):
_run_geodiff([config.geodiffinfo_exe, "makeCopy", src_driver, src_conn_info, src, dst_driver, dst_conn_info, dst])
_run_geodiff([config.geodiff_exe, "copy", "--driver-1", src_driver, src_conn_info, "--driver-2", dst_driver, dst_conn_info, src, dst])


def _geodiff_create_changeset_dr(src_driver, src_conn_info, src, dst_driver, dst_conn_info, dst, changeset):
_run_geodiff([config.geodiffinfo_exe, "createChangesetDr", src_driver, src_conn_info, src, dst_driver, dst_conn_info, dst, changeset])
_run_geodiff([config.geodiff_exe, "diff", "--driver-1", src_driver, src_conn_info, "--driver-2", dst_driver, dst_conn_info, src, dst, changeset])


def _compare_datasets(src_driver, src_conn_info, src, dst_driver, dst_conn_info, dst, summary_only=True):
Expand Down
4 changes: 2 additions & 2 deletions test/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from dbsync import dbsync_init, dbsync_pull, dbsync_push, dbsync_status, config, DbSyncError, _geodiff_make_copy, \
_get_db_project_comment

GEODIFFINFO_EXE = os.environ.get('TEST_GEODIFFINFO_EXE')
GEODIFF_EXE = os.environ.get('TEST_GEODIFF_EXE')
DB_CONNINFO = os.environ.get('TEST_DB_CONNINFO')
SERVER_URL = os.environ.get('TEST_MERGIN_URL')
API_USER = os.environ.get('TEST_API_USERNAME')
Expand Down Expand Up @@ -74,7 +74,7 @@ def init_sync_from_geopackage(mc, project_name, source_gpkg_path):
mc.push_project(project_dir)

# prepare dbsync config
config.geodiffinfo_exe = GEODIFFINFO_EXE
config.geodiff_exe = GEODIFF_EXE
config.mergin_username = API_USER
config.mergin_password = USER_PWD
config.mergin_url = SERVER_URL
Expand Down
2 changes: 1 addition & 1 deletion version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.0.4'
__version__ = '1.0.5'

0 comments on commit e319f8a

Please sign in to comment.