Skip to content
This repository
Browse code

s/tile_layout/tilelayout/g

  • Loading branch information...
commit 13a1b5326b1ddd10544798f7cc38fb923fe06583 1 parent dfe25ae
Tom Payne authored
16 tc-mbtiles-create
@@ -18,13 +18,13 @@ from tilecloud.store.s3 import S3TileStore
18 18
19 19
20 20 def main(argv):
21   - tile_layouts = {'i3d': I3DTileLayout, 'osm': OSMTileLayout}
  21 + tilelayouts = {'i3d': I3DTileLayout, 'osm': OSMTileLayout}
22 22 tilestores = 'filesystem log s3'.split()
23 23 option_parser = OptionParser()
24 24 option_parser.add_option('--bounds', metavar='Z1/X1/Y1:(Z2/)?X2/Y2')
25 25 option_parser.add_option('--bucket', dest='bucket_name', metavar='BUCKET')
26   - option_parser.add_option('--layout', choices=tile_layouts.keys(),
27   - dest='tile_layout')
  26 + option_parser.add_option('--layout', choices=tilelayouts.keys(),
  27 + dest='tilelayout')
28 28 option_parser.add_option('--limit', metavar='LIMIT', type=int)
29 29 option_parser.add_option('--output', default=':memory:', metavar='TILESET')
30 30 option_parser.add_option('--prefix', default='', metavar='STRING')
@@ -38,16 +38,16 @@ def main(argv):
38 38 option_parser.add_option('--format', metavar='FORMAT')
39 39 options, args = option_parser.parse_args(argv[1:])
40 40 assert options.store
41   - tile_layout = tile_layouts[options.tile_layout]()
  41 + tilelayout = tilelayouts[options.tilelayout]()
42 42 if options.prefix or options.suffix:
43   - tile_layout = WrappedTileLayout(tile_layout, options.prefix,
  43 + tilelayout = WrappedTileLayout(tilelayout, options.prefix,
44 44 options.suffix)
45 45 if options.store == 'filesystem':
46   - store = FilesystemTileStore(tile_layout)
  46 + store = FilesystemTileStore(tilelayout)
47 47 elif options.store == 'log':
48   - store = LogTileStore(tile_layout, fileinput.input(args))
  48 + store = LogTileStore(tilelayout, fileinput.input(args))
49 49 elif options.store == 's3':
50   - store = S3TileStore(options.bucket_name, tile_layout)
  50 + store = S3TileStore(options.bucket_name, tilelayout)
51 51 else:
52 52 assert False
53 53 if options.bounds:
12 tilecloud/layout/wrapped.py
@@ -6,21 +6,21 @@
6 6 class WrappedTileLayout(TileLayout):
7 7 """A tile layout with an option prefix and/or suffix"""
8 8
9   - def __init__(self, tile_layout, prefix='', suffix=''):
10   - self.tile_layout = tile_layout
  9 + def __init__(self, tilelayout, prefix='', suffix=''):
  10 + self.tilelayout = tilelayout
11 11 self.prefix = prefix
12 12 self.suffix = suffix
13 13 prefix_re = re.escape(self.prefix)
14 14 suffix_re = re.escape(self.suffix)
15   - self.pattern = ''.join((prefix_re, tile_layout.pattern, suffix_re))
  15 + self.pattern = ''.join((prefix_re, tilelayout.pattern, suffix_re))
16 16 filename_pattern = ''.join((prefix_re,
17   - r'(', self.tile_layout.pattern, r')',
  17 + r'(', self.tilelayout.pattern, r')',
18 18 suffix_re, r'\Z'))
19 19 self.filename_re = re.compile(filename_pattern)
20 20
21 21 def filename(self, tilecoord):
22 22 return ''.join((self.prefix,
23   - self.tile_layout.filename(tilecoord),
  23 + self.tilelayout.filename(tilecoord),
24 24 self.suffix))
25 25
26 26 def tilecoord(self, filename):
@@ -28,4 +28,4 @@ def tilecoord(self, filename):
28 28 if not match:
29 29 raise ValueError('invalid literal for %s.tilecoord(): %r' %
30 30 (self.__class__.__name__, filename))
31   - return self.tile_layout.tilecoord(match.group(1))
  31 + return self.tilelayout.tilecoord(match.group(1))
14 tilecloud/store/filesystem.py
@@ -8,12 +8,12 @@
8 8 class FilesystemTileStore(TileStore):
9 9 """Tiles stored in a filesystem"""
10 10
11   - def __init__(self, tile_layout, **kwargs):
  11 + def __init__(self, tilelayout, **kwargs):
12 12 TileStore.__init__(self, **kwargs)
13   - self.tile_layout = tile_layout
  13 + self.tilelayout = tilelayout
14 14
15 15 def delete_one(self, tile):
16   - filename = self.tile_layout.filename(tile.tilecoord)
  16 + filename = self.tilelayout.filename(tile.tilecoord)
17 17 if os.path.exists(filename):
18 18 os.remove(filename)
19 19 return tile
@@ -25,7 +25,7 @@ def get_all(self):
25 25 yield tile
26 26
27 27 def get_one(self, tile):
28   - filename = self.tile_layout.filename(tile.tilecoord)
  28 + filename = self.tilelayout.filename(tile.tilecoord)
29 29 try:
30 30 with open(filename) as file:
31 31 tile.data = file.read()
@@ -37,17 +37,17 @@ def get_one(self, tile):
37 37 raise
38 38
39 39 def list(self):
40   - top = getattr(self.tile_layout, 'prefix', '.')
  40 + top = getattr(self.tilelayout, 'prefix', '.')
41 41 for dirpath, dirnames, filenames in os.walk(top):
42 42 for filename in filenames:
43 43 path = os.path.join(dirpath, filename)
44   - tilecoord = self.tile_layout.tilecoord(path)
  44 + tilecoord = self.tilelayout.tilecoord(path)
45 45 if tilecoord:
46 46 yield Tile(tilecoord, path=path)
47 47
48 48 def put_one(self, tile):
49 49 assert tile.data is not None
50   - filename = self.tile_layout.filename(tile.tilecoord)
  50 + filename = self.tilelayout.filename(tile.tilecoord)
51 51 dirname = os.path.dirname(filename)
52 52 if not os.path.exists(dirname):
53 53 os.makedirs(dirname)
10 tilecloud/store/log.py
@@ -7,9 +7,9 @@
7 7 class LogTileStore(TileStore):
8 8 """Generates all tile coordinates matching the specified layout from file"""
9 9
10   - def __init__(self, tile_layout, file=None, **kwargs):
  10 + def __init__(self, tilelayout, file=None, **kwargs):
11 11 TileStore.__init__(self, **kwargs)
12   - self.tile_layout = tile_layout
  12 + self.tilelayout = tilelayout
13 13 self.file = file
14 14
15 15 def get_one(self, tile):
@@ -18,12 +18,12 @@ def get_one(self, tile):
18 18
19 19 def list(self):
20 20 # FIXME warn that this consumes file
21   - filename_re = re.compile(self.tile_layout.pattern)
  21 + filename_re = re.compile(self.tilelayout.pattern)
22 22 for line in self.file:
23 23 match = filename_re.search(line)
24 24 if match:
25   - yield Tile(self.tile_layout.tilecoord(match.group()), line=line)
  25 + yield Tile(self.tilelayout.tilecoord(match.group()), line=line)
26 26
27 27 def put_one(self, tile):
28   - self.file.write(self.tile_layout.filename(tile.tilecoord) + '\n')
  28 + self.file.write(self.tilelayout.filename(tile.tilecoord) + '\n')
29 29 return tile
16 tilecloud/store/s3.py
@@ -11,16 +11,16 @@
11 11 class S3TileStore(TileStore):
12 12 """Tiles stored in Amazon S3"""
13 13
14   - def __init__(self, bucket, tile_layout, dry_run=False, **kwargs):
  14 + def __init__(self, bucket, tilelayout, dry_run=False, **kwargs):
15 15 self.s3bucket = S3Connection().bucket(bucket)
16   - self.tile_layout = tile_layout
  16 + self.tilelayout = tilelayout
17 17 self.dry_run = dry_run
18 18 TileStore.__init__(self, **kwargs)
19 19
20 20 def __contains__(self, tile):
21 21 if not tile:
22 22 return False
23   - key_name = self.tile_layout.filename(tile.tilecoord)
  23 + key_name = self.tilelayout.filename(tile.tilecoord)
24 24 try:
25 25 self.s3bucket.get(key_name) # FIXME should use head
26 26 return True
@@ -32,7 +32,7 @@ def __contains__(self, tile):
32 32
33 33 def delete_one(self, tile):
34 34 try:
35   - key_name = self.tile_layout.filename(tile.tilecoord)
  35 + key_name = self.tilelayout.filename(tile.tilecoord)
36 36 if not self.dry_run:
37 37 self.s3bucket.delete(key_name)
38 38 except S3Error as exc:
@@ -40,7 +40,7 @@ def delete_one(self, tile):
40 40 return tile
41 41
42 42 def get_one(self, tile):
43   - key_name = self.tile_layout.filename(tile.tilecoord)
  43 + key_name = self.tilelayout.filename(tile.tilecoord)
44 44 try:
45 45 tile.s3key = self.s3bucket.get(key_name)
46 46 tile.data = tile.s3key.body
@@ -60,17 +60,17 @@ def get_one(self, tile):
60 60 return tile
61 61
62 62 def list(self):
63   - prefix = getattr(self.tile_layout, 'prefix', '')
  63 + prefix = getattr(self.tilelayout, 'prefix', '')
64 64 for s3key in self.s3bucket.list_objects(prefix=prefix):
65 65 try:
66   - tilecoord = self.tile_layout.tilecoord(s3key.name)
  66 + tilecoord = self.tilelayout.tilecoord(s3key.name)
67 67 except ValueError:
68 68 continue
69 69 yield Tile(tilecoord, s3key=s3key)
70 70
71 71 def put_one(self, tile):
72 72 assert tile.data is not None
73   - key_name = self.tile_layout.filename(tile.tilecoord)
  73 + key_name = self.tilelayout.filename(tile.tilecoord)
74 74 s3key = self.s3bucket.key(key_name)
75 75 s3key.body = tile.data
76 76 if tile.content_encoding is not None:
4 tilecloud/store/tilejson.py
@@ -43,8 +43,8 @@ def __init__(self, tile_json, urls_key='tiles', **kwargs):
43 43 kwargs['content_type'] = content_types.pop()
44 44 templates = [re.sub(r'\{([xyz])\}', lambda m: '%%(%s)d' % m.group(1), url)
45 45 for url in urls]
46   - tile_layouts = map(TemplateTileLayout, templates)
47   - URLTileStore.__init__(self, tile_layouts, **kwargs)
  46 + tilelayouts = map(TemplateTileLayout, templates)
  47 + URLTileStore.__init__(self, tilelayouts, **kwargs)
48 48
49 49 @classmethod
50 50 def from_url(cls, url):
10 tilecloud/store/url.py
@@ -9,18 +9,18 @@
9 9
10 10 class URLTileStore(TileStore):
11 11
12   - def __init__(self, tile_layouts, headers=None, **kwargs):
  12 + def __init__(self, tilelayouts, headers=None, **kwargs):
13 13 TileStore.__init__(self, **kwargs)
14   - self.tile_layouts = tuple(tile_layouts)
  14 + self.tilelayouts = tuple(tilelayouts)
15 15 self.headers = headers or {}
16 16
17 17 def get_one(self, tile):
18 18 if self.bounding_pyramid is not None:
19 19 if tile.tilecoord not in self.bounding_pyramid:
20 20 return None
21   - tile_layout = self.tile_layouts[hash(tile.tilecoord) %
22   - len(self.tile_layouts)]
23   - url = tile_layout.filename(tile.tilecoord)
  21 + tilelayout = self.tilelayouts[hash(tile.tilecoord) %
  22 + len(self.tilelayouts)]
  23 + url = tilelayout.filename(tile.tilecoord)
24 24 request = Request(url, headers=self.headers)
25 25 try:
26 26 logger.debug('GET %s' % (url,))
22 tilecloud/tests/test_tilelayout.py
@@ -23,14 +23,14 @@ def test_tilecoord(self):
23 23 class TestOSMTileLayout(unittest.TestCase):
24 24
25 25 def setUp(self):
26   - self.tile_layout = OSMTileLayout()
  26 + self.tilelayout = OSMTileLayout()
27 27
28 28 def test_filename(self):
29   - self.assertEqual(self.tile_layout.filename(TileCoord(1, 2, 3)), '1/2/3')
  29 + self.assertEqual(self.tilelayout.filename(TileCoord(1, 2, 3)), '1/2/3')
30 30
31 31 def test_tilecoord(self):
32   - self.assertEqual(self.tile_layout.tilecoord('1/2/3'), TileCoord(1, 2, 3))
33   - self.assertRaises(ValueError, self.tile_layout.tilecoord, '1/2/')
  32 + self.assertEqual(self.tilelayout.tilecoord('1/2/3'), TileCoord(1, 2, 3))
  33 + self.assertRaises(ValueError, self.tilelayout.tilecoord, '1/2/')
34 34
35 35
36 36 class TestWMTSTileLayout(unittest.TestCase):
@@ -212,23 +212,23 @@ def test_metatile_border(self):
212 212 class TestTemplateTileLayout(unittest.TestCase):
213 213
214 214 def setUp(self):
215   - self.tile_layout = TemplateTileLayout('%(z)d/%(x)d/%(y)d')
  215 + self.tilelayout = TemplateTileLayout('%(z)d/%(x)d/%(y)d')
216 216
217 217 def test_filename(self):
218   - self.assertEqual(self.tile_layout.filename(TileCoord(1, 2, 3)), '1/2/3')
  218 + self.assertEqual(self.tilelayout.filename(TileCoord(1, 2, 3)), '1/2/3')
219 219
220 220 def test_tilecoord(self):
221   - self.assertEqual(self.tile_layout.tilecoord('1/2/3'), TileCoord(1, 2, 3))
  221 + self.assertEqual(self.tilelayout.tilecoord('1/2/3'), TileCoord(1, 2, 3))
222 222
223 223
224 224 class TestWrappedTileLayout(unittest.TestCase):
225 225
226 226 def setUp(self):
227   - self.tile_layout = WrappedTileLayout(OSMTileLayout(), 'prefix/', '.suffix')
  227 + self.tilelayout = WrappedTileLayout(OSMTileLayout(), 'prefix/', '.suffix')
228 228
229 229 def test_filename(self):
230   - self.assertEqual(self.tile_layout.filename(TileCoord(1, 2, 3)), 'prefix/1/2/3.suffix')
  230 + self.assertEqual(self.tilelayout.filename(TileCoord(1, 2, 3)), 'prefix/1/2/3.suffix')
231 231
232 232 def test_tilecoord(self):
233   - self.assertEqual(self.tile_layout.tilecoord('prefix/1/2/3.suffix'), TileCoord(1, 2, 3))
234   - self.assertRaises(ValueError, self.tile_layout.tilecoord, 'prefix//1/2/3.suffix')
  233 + self.assertEqual(self.tilelayout.tilecoord('prefix/1/2/3.suffix'), TileCoord(1, 2, 3))
  234 + self.assertRaises(ValueError, self.tilelayout.tilecoord, 'prefix//1/2/3.suffix')

0 comments on commit 13a1b53

Please sign in to comment.
Something went wrong with that request. Please try again.