From 51028df2bba53cd6f435aa84b835c88d5ff61eb2 Mon Sep 17 00:00:00 2001 From: Ian Rees Date: Thu, 6 Dec 2018 15:38:42 -0800 Subject: [PATCH 1/2] Fix print, map, urlparse --- planetutils/elevation_tile_download.py | 4 ++-- planetutils/elevation_tile_downloader.py | 2 +- planetutils/elevation_tile_merge.py | 14 +++++++------- planetutils/tilepack_download.py | 1 - planetutils/tilepack_downloader.py | 2 -- tests/test_commands.py | 21 +++++++++++++++++++++ tests/test_elevation_tile_downloader.py | 1 + 7 files changed, 32 insertions(+), 13 deletions(-) create mode 100644 tests/test_commands.py diff --git a/planetutils/elevation_tile_download.py b/planetutils/elevation_tile_download.py index 70caffa..7e782c8 100644 --- a/planetutils/elevation_tile_download.py +++ b/planetutils/elevation_tile_download.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -from __future__ import absolute_import, unicode_literals +from __future__ import absolute_import, unicode_literals, print_function import argparse from . import log @@ -25,7 +25,7 @@ def main(): elif args.format == 'skadi': p = ElevationSkadiDownloader(args.outpath) else: - print "Unknown format: %s"%args.format + print("Unknown format: %s"%args.format) sys.exit(1) if args.csv: diff --git a/planetutils/elevation_tile_downloader.py b/planetutils/elevation_tile_downloader.py index 1e70d45..c03613e 100644 --- a/planetutils/elevation_tile_downloader.py +++ b/planetutils/elevation_tile_downloader.py @@ -87,7 +87,7 @@ def get_bbox_tiles(self, bbox): return tiles def tile_path(self, z, x, y): - return map(str, [z, x, str(y)+'.tif']) + return list(map(str, [z, x, str(y)+'.tif'])) class ElevationSkadiDownloader(ElevationDownloader): HGT_SIZE = (3601 * 3601 * 2) diff --git a/planetutils/elevation_tile_merge.py b/planetutils/elevation_tile_merge.py index 5a6bbfe..ee169b1 100644 --- a/planetutils/elevation_tile_merge.py +++ b/planetutils/elevation_tile_merge.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -from __future__ import absolute_import, unicode_literals +from __future__ import absolute_import, unicode_literals, print_function import argparse import sys import fnmatch @@ -20,7 +20,7 @@ def main(): tmppath = args.outpath if args.scale and len(args.scale.split(',')) != 2: - print "Must provide min, max values" + print("Must provide min, max values") sys.exit(1) elif args.scale: # Output to tmp file @@ -32,22 +32,22 @@ def main(): matches.append(os.path.join(root, filename)) if len(matches) == 0: - print "No input files" + print("No input files") sys.exit(0) - print "Found %s files:"%len(matches) + print("Found %s files:"%len(matches)) for i in matches: - print "\t%s"%(i) + print("\t%s"%(i)) # gdal_merge.py -init 0 -o out.tif - print "Merging... %s"%(tmppath) + print("Merging... %s"%(tmppath)) cmd = ['gdal_merge.py', '-init', '0', '-o', tmppath] cmd += matches p = subprocess.check_call(cmd) # gdal_translate -of GTiff -ot Byte -scale 0 255 0 255 out.tif out8.tif if args.scale: - print "Scaling: %s -> %s"%(tmppath, outpath) + print("Scaling: %s -> %s"%(tmppath, outpath)) a = args.scale.split(",") cmd = ['gdal_translate', '-of', 'GTiff', '-ot', 'Byte', '-scale', a[0], a[1], '0', '255', tmppath, outpath] subprocess.check_call(cmd) diff --git a/planetutils/tilepack_download.py b/planetutils/tilepack_download.py index 1c84195..a64bb75 100644 --- a/planetutils/tilepack_download.py +++ b/planetutils/tilepack_download.py @@ -4,7 +4,6 @@ import argparse from . import log -from . import tilepack from .bbox import bbox_string, load_bboxes_csv from .tilepack_downloader import TilepackDownloader diff --git a/planetutils/tilepack_downloader.py b/planetutils/tilepack_downloader.py index 10d136a..5821ca4 100644 --- a/planetutils/tilepack_downloader.py +++ b/planetutils/tilepack_downloader.py @@ -5,11 +5,9 @@ from urllib.request import urlopen import os -import urlparse import subprocess import json - from . import log from . import download diff --git a/tests/test_commands.py b/tests/test_commands.py new file mode 100644 index 0000000..48ee2ee --- /dev/null +++ b/tests/test_commands.py @@ -0,0 +1,21 @@ +from __future__ import absolute_import, unicode_literals +import tempfile +import types +import os +import unittest + +class TestCommandImports(unittest.TestCase): + def test_command_imports(self): + commands = [ + 'osm_planet_update=planetutils.osm_planet_update:main', + 'osm_planet_extract=planetutils.osm_planet_extract:main', + 'osm_planet_get_timestamp=planetutils.osm_planet_get_timestamp:main', + 'osm_extract_download=planetutils.osm_extract_download:main', + 'elevation_tile_download=planetutils.elevation_tile_download:main', + 'elevation_tile_merge=planetutils.elevation_tile_merge:main', + 'valhalla_tilepack_download=planetutils.tilepack_download:main', + 'valhalla_tilepack_list=planetutils.tilepack_list:main' + ] + for i in commands: + a, _, b = i.partition('=')[-1].partition(':') + exec('import %s'%(a)) diff --git a/tests/test_elevation_tile_downloader.py b/tests/test_elevation_tile_downloader.py index 29b6085..c7ea518 100644 --- a/tests/test_elevation_tile_downloader.py +++ b/tests/test_elevation_tile_downloader.py @@ -13,6 +13,7 @@ def test_tile_path(self): e = ElevationGeotiffDownloader('.') expect = ('0', '37', '122.tif') tile_path = e.tile_path(0, 37, 122) + print(tile_path) self.assertEqual(tile_path[0], expect[0]) self.assertEqual(tile_path[1], expect[1]) self.assertEqual(tile_path[2], expect[2]) From f4ed1c3d53f9743a02f5e8dd315a3a99b56c9592 Mon Sep 17 00:00:00 2001 From: Ian Rees Date: Thu, 6 Dec 2018 15:49:29 -0800 Subject: [PATCH 2/2] Tidy --- tests/test_elevation_tile_downloader.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_elevation_tile_downloader.py b/tests/test_elevation_tile_downloader.py index c7ea518..29b6085 100644 --- a/tests/test_elevation_tile_downloader.py +++ b/tests/test_elevation_tile_downloader.py @@ -13,7 +13,6 @@ def test_tile_path(self): e = ElevationGeotiffDownloader('.') expect = ('0', '37', '122.tif') tile_path = e.tile_path(0, 37, 122) - print(tile_path) self.assertEqual(tile_path[0], expect[0]) self.assertEqual(tile_path[1], expect[1]) self.assertEqual(tile_path[2], expect[2])