Skip to content
Commits on Source (7)
......@@ -23,13 +23,9 @@ matrix:
compiler: gcc
env: USE_PYTHON_VERSION=3
- os: osx
osx_image: xcode8.3
osx_image: xcode7
compiler: clang
env: USE_PYTHON_VERSION=3
- os: osx
osx_image: xcode9.4
compiler: clang
env: USE_PYTHON_VERSION=3
env: USE_PYTHON_VERSION=
- os: osx
osx_image: xcode10.1
compiler: clang
......
......@@ -4,6 +4,20 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
## [2.15.1] - 2019-01-24
### Added
- tests for pyosmium-get-changes
### Changed
- do not read data when checking for replication headers
### Fixed
- fix typo in sequence file reading of pyosmium-get-changes
## [2.15.0] - 2018-12-09
### Added
......
pyosmium (2.15.1-1~bpo9+1) stretch-backports; urgency=medium
* Rebuild for stretch-backports.
-- Bas Couwenberg <sebastic@debian.org> Wed, 30 Jan 2019 06:50:29 +0100
pyosmium (2.15.1-1) unstable; urgency=medium
* New upstream release.
* Bump Standards-Version to 4.3.0, no changes.
-- Bas Couwenberg <sebastic@debian.org> Fri, 25 Jan 2019 06:59:10 +0100
pyosmium (2.15.0-1~bpo9+1) stretch-backports; urgency=medium
* Rebuild for stretch-backports.
......
......@@ -24,7 +24,7 @@ Build-Depends: cmake (>= 2.8.12),
python3-nose,
python3-sphinx,
python3-sphinxcontrib.autoprogram
Standards-Version: 4.2.1
Standards-Version: 4.3.0
Vcs-Browser: https://salsa.debian.org/debian-gis-team/pyosmium/
Vcs-Git: https://salsa.debian.org/debian-gis-team/pyosmium.git -b stretch-backports
Homepage: https://osmcode.org/pyosmium/
......
......@@ -4,6 +4,7 @@ import logging
import datetime as dt
from collections import namedtuple
from osmium.io import Reader as oreader
from osmium.osm import NOTHING
from sys import version_info as python_version
log = logging.getLogger('pyosmium')
......@@ -21,7 +22,7 @@ def get_replication_header(fname):
a `RuntimeError` is raised.
"""
r = oreader(fname)
r = oreader(fname, NOTHING)
h = r.header()
ts = h.get("osmosis_replication_timestamp")
......
......@@ -5,7 +5,7 @@ Version information.
# the major version
pyosmium_major = '2.15'
# current release (Pip version)
pyosmium_release = '2.15.0'
pyosmium_release = '2.15.1'
# libosmium version shipped with the Pip release
libosmium_version = '2.15.0'
......
......@@ -18,6 +18,19 @@ else:
return datetime(*args)
def load_script(filename):
""" Load an executable script into its own private environment.
"""
src = os.path.normpath(filename)
globvars = dict()
if sys.version_info[0] >= 3:
exec(compile(open(src, "rb").read(), src, 'exec'), globvars)
else:
execfile(src, globvars)
return globvars
def _complete_object(o):
"""Takes a hash with an incomplete OSM object description and returns a
complete one.
......
""" Tests for the pyosmium-get-changes script.
"""
from helpers import load_script
from nose.tools import *
import unittest
from io import BytesIO
from os import path as osp
from textwrap import dedent
import sys
import tempfile
try:
from cStringIO import StringIO
except:
from io import StringIO
try:
from urllib.error import URLError
except ImportError:
from urllib2 import URLError
try:
from unittest.mock import MagicMock, DEFAULT
except ImportError:
from mock import MagicMock, DEFAULT
class Capturing(list):
def __enter__(self):
self._stdout = sys.stdout
sys.stdout = self._stringio = StringIO()
return self
def __exit__(self, *args):
self.extend(self._stringio.getvalue().splitlines())
del self._stringio # free up some memory
sys.stdout = self._stdout
class TestPyosmiumGetChanges(unittest.TestCase):
def setUp(self):
self.script = load_script(osp.join(osp.realpath(__file__),
"../../tools/pyosmium-get-changes"))
self.url_mock = MagicMock()
self.urls = dict()
self.url_mock.side_effect = lambda url : self.urls[url]
self.script['rserv'].urlrequest.urlopen = self.url_mock
def url(self, url, result):
self.urls[url] = BytesIO(dedent(result).encode())
def main(self, *args):
with Capturing() as output:
ret = self.script['main'](args)
self.stdout = output
return ret
def test_init_id(self):
assert_equals(0, self.main('-I', '453'))
assert_equals(1, len(self.stdout))
assert_equals('454', self.stdout[0])
def test_init_date(self):
self.url('https://planet.osm.org/replication/minute//state.txt',
"""\
sequenceNumber=100
timestamp=2017-08-26T11\:04\:02Z
""")
self.url('https://planet.osm.org/replication/minute//000/000/000.state.txt',
"""\
sequenceNumber=0
timestamp=2016-08-26T11\:04\:02Z
""")
assert_equals(0, self.main('-D', '2015-12-24T08:08:08Z'))
assert_equals(1, len(self.stdout))
assert_equals('1', self.stdout[0])
def test_init_to_file(self):
with tempfile.NamedTemporaryFile(dir=tempfile.gettempdir(), suffix='.seq') as fd:
assert_equals(0, self.main('-I', '453', '-f', fd.name))
content = fd.read()
assert_equals('454', content.decode('utf-8'))
def test_init_from_seq_file(self):
with tempfile.NamedTemporaryFile(dir=tempfile.gettempdir(), suffix='.seq') as fd:
fd.write('453'.encode('utf-8'))
fd.flush()
assert_equals(0, self.main('-f', fd.name))
fd.seek(0)
content = fd.read()
assert_equals('454', content.decode('utf-8'))
......@@ -17,6 +17,7 @@ except ImportError:
import osmium as o
import osmium.replication.server as rserv
import osmium.replication.utils as rutil
import osmium.replication
import tempfile
import datetime
......@@ -243,3 +244,16 @@ def test_get_newest_change_from_file():
assert_equals(val, mkdate(2018, 10, 29, 3, 56, 7))
finally:
os.remove(fn)
def test_get_replication_header_empty():
data = [osmobj('N', id=1, version=1, changeset=63965061, uid=8369524,
timestamp='2018-10-29T03:56:07Z', user='x')]
fn = create_osm_file(data)
try:
val = rutil.get_replication_header(fn)
assert_is_none(val.url)
assert_is_none(val.sequence)
assert_is_none(val.timestamp)
finally:
os.remove(fn)
......@@ -164,11 +164,11 @@ def get_arg_parser(from_main=False):
return parser
if __name__ == '__main__':
def main(args):
logging.basicConfig(stream=sys.stderr,
format='%(levelname)s: %(message)s')
options = get_arg_parser(from_main=True).parse_args()
options = get_arg_parser(from_main=True).parse_args(args)
log.setLevel(max(3 - options.loglevel, 0) * 10)
......@@ -181,11 +181,11 @@ if __name__ == '__main__':
Don't know with which change to start. One of the parameters
-I / -D / -O / -f
needs to begiven."""))
exit(1)
return 1
with open(options.start_file, 'r') as f:
with open(options.seq_file, 'r') as f:
seq = f.readline()
options.start = ReplicationStart_from_id(seq)
options.start = ReplicationStart.from_id(seq)
if options.server_url is not None and options.start.source is not None:
if options.server_url != options.start.source:
......@@ -196,7 +196,7 @@ if __name__ == '__main__':
%s
If you really mean to overwrite the URL, use --ignore-osmosis-headers."""
% (options.server_url, options.start.source)))
exit(2)
return 2
url = options.server_url \
or options.start.source \
or 'https://planet.osm.org/replication/minute/'
......@@ -214,11 +214,11 @@ if __name__ == '__main__':
startseq = options.start.get_sequence(svr)
if startseq is None:
log.error("Cannot read state file from server. Is the URL correct?")
exit(1)
return 1
if options.outfile is None:
write_end_sequence(options.seq_file, startseq)
exit(0)
return 0
log.debug("Starting download at ID %d (max %d MB)" % (startseq, options.outsize))
outhandler = WriteHandler(options.outfile)
......@@ -232,6 +232,12 @@ if __name__ == '__main__':
cookie_jar.save(options.cookie)
if endseq is None:
exit(3)
return 3
write_end_sequence(options.seq_file, endseq)
return 0
if __name__ == '__main__':
exit(main(sys.argv[1:]))