Browse files

s/tile_layout/tilelayout/g

  • Loading branch information...
1 parent dfe25ae commit 13a1b5326b1ddd10544798f7cc38fb923fe06583 @twpayne twpayne committed May 11, 2012
View
16 tc-mbtiles-create
@@ -18,13 +18,13 @@ from tilecloud.store.s3 import S3TileStore
def main(argv):
- tile_layouts = {'i3d': I3DTileLayout, 'osm': OSMTileLayout}
+ tilelayouts = {'i3d': I3DTileLayout, 'osm': OSMTileLayout}
tilestores = 'filesystem log s3'.split()
option_parser = OptionParser()
option_parser.add_option('--bounds', metavar='Z1/X1/Y1:(Z2/)?X2/Y2')
option_parser.add_option('--bucket', dest='bucket_name', metavar='BUCKET')
- option_parser.add_option('--layout', choices=tile_layouts.keys(),
- dest='tile_layout')
+ option_parser.add_option('--layout', choices=tilelayouts.keys(),
+ dest='tilelayout')
option_parser.add_option('--limit', metavar='LIMIT', type=int)
option_parser.add_option('--output', default=':memory:', metavar='TILESET')
option_parser.add_option('--prefix', default='', metavar='STRING')
@@ -38,16 +38,16 @@ def main(argv):
option_parser.add_option('--format', metavar='FORMAT')
options, args = option_parser.parse_args(argv[1:])
assert options.store
- tile_layout = tile_layouts[options.tile_layout]()
+ tilelayout = tilelayouts[options.tilelayout]()
if options.prefix or options.suffix:
- tile_layout = WrappedTileLayout(tile_layout, options.prefix,
+ tilelayout = WrappedTileLayout(tilelayout, options.prefix,
options.suffix)
if options.store == 'filesystem':
- store = FilesystemTileStore(tile_layout)
+ store = FilesystemTileStore(tilelayout)
elif options.store == 'log':
- store = LogTileStore(tile_layout, fileinput.input(args))
+ store = LogTileStore(tilelayout, fileinput.input(args))
elif options.store == 's3':
- store = S3TileStore(options.bucket_name, tile_layout)
+ store = S3TileStore(options.bucket_name, tilelayout)
else:
assert False
if options.bounds:
View
12 tilecloud/layout/wrapped.py
@@ -6,26 +6,26 @@
class WrappedTileLayout(TileLayout):
"""A tile layout with an option prefix and/or suffix"""
- def __init__(self, tile_layout, prefix='', suffix=''):
- self.tile_layout = tile_layout
+ def __init__(self, tilelayout, prefix='', suffix=''):
+ self.tilelayout = tilelayout
self.prefix = prefix
self.suffix = suffix
prefix_re = re.escape(self.prefix)
suffix_re = re.escape(self.suffix)
- self.pattern = ''.join((prefix_re, tile_layout.pattern, suffix_re))
+ self.pattern = ''.join((prefix_re, tilelayout.pattern, suffix_re))
filename_pattern = ''.join((prefix_re,
- r'(', self.tile_layout.pattern, r')',
+ r'(', self.tilelayout.pattern, r')',
suffix_re, r'\Z'))
self.filename_re = re.compile(filename_pattern)
def filename(self, tilecoord):
return ''.join((self.prefix,
- self.tile_layout.filename(tilecoord),
+ self.tilelayout.filename(tilecoord),
self.suffix))
def tilecoord(self, filename):
match = self.filename_re.match(filename)
if not match:
raise ValueError('invalid literal for %s.tilecoord(): %r' %
(self.__class__.__name__, filename))
- return self.tile_layout.tilecoord(match.group(1))
+ return self.tilelayout.tilecoord(match.group(1))
View
14 tilecloud/store/filesystem.py
@@ -8,12 +8,12 @@
class FilesystemTileStore(TileStore):
"""Tiles stored in a filesystem"""
- def __init__(self, tile_layout, **kwargs):
+ def __init__(self, tilelayout, **kwargs):
TileStore.__init__(self, **kwargs)
- self.tile_layout = tile_layout
+ self.tilelayout = tilelayout
def delete_one(self, tile):
- filename = self.tile_layout.filename(tile.tilecoord)
+ filename = self.tilelayout.filename(tile.tilecoord)
if os.path.exists(filename):
os.remove(filename)
return tile
@@ -25,7 +25,7 @@ def get_all(self):
yield tile
def get_one(self, tile):
- filename = self.tile_layout.filename(tile.tilecoord)
+ filename = self.tilelayout.filename(tile.tilecoord)
try:
with open(filename) as file:
tile.data = file.read()
@@ -37,17 +37,17 @@ def get_one(self, tile):
raise
def list(self):
- top = getattr(self.tile_layout, 'prefix', '.')
+ top = getattr(self.tilelayout, 'prefix', '.')
for dirpath, dirnames, filenames in os.walk(top):
for filename in filenames:
path = os.path.join(dirpath, filename)
- tilecoord = self.tile_layout.tilecoord(path)
+ tilecoord = self.tilelayout.tilecoord(path)
if tilecoord:
yield Tile(tilecoord, path=path)
def put_one(self, tile):
assert tile.data is not None
- filename = self.tile_layout.filename(tile.tilecoord)
+ filename = self.tilelayout.filename(tile.tilecoord)
dirname = os.path.dirname(filename)
if not os.path.exists(dirname):
os.makedirs(dirname)
View
10 tilecloud/store/log.py
@@ -7,9 +7,9 @@
class LogTileStore(TileStore):
"""Generates all tile coordinates matching the specified layout from file"""
- def __init__(self, tile_layout, file=None, **kwargs):
+ def __init__(self, tilelayout, file=None, **kwargs):
TileStore.__init__(self, **kwargs)
- self.tile_layout = tile_layout
+ self.tilelayout = tilelayout
self.file = file
def get_one(self, tile):
@@ -18,12 +18,12 @@ def get_one(self, tile):
def list(self):
# FIXME warn that this consumes file
- filename_re = re.compile(self.tile_layout.pattern)
+ filename_re = re.compile(self.tilelayout.pattern)
for line in self.file:
match = filename_re.search(line)
if match:
- yield Tile(self.tile_layout.tilecoord(match.group()), line=line)
+ yield Tile(self.tilelayout.tilecoord(match.group()), line=line)
def put_one(self, tile):
- self.file.write(self.tile_layout.filename(tile.tilecoord) + '\n')
+ self.file.write(self.tilelayout.filename(tile.tilecoord) + '\n')
return tile
View
16 tilecloud/store/s3.py
@@ -11,16 +11,16 @@
class S3TileStore(TileStore):
"""Tiles stored in Amazon S3"""
- def __init__(self, bucket, tile_layout, dry_run=False, **kwargs):
+ def __init__(self, bucket, tilelayout, dry_run=False, **kwargs):
self.s3bucket = S3Connection().bucket(bucket)
- self.tile_layout = tile_layout
+ self.tilelayout = tilelayout
self.dry_run = dry_run
TileStore.__init__(self, **kwargs)
def __contains__(self, tile):
if not tile:
return False
- key_name = self.tile_layout.filename(tile.tilecoord)
+ key_name = self.tilelayout.filename(tile.tilecoord)
try:
self.s3bucket.get(key_name) # FIXME should use head
return True
@@ -32,15 +32,15 @@ def __contains__(self, tile):
def delete_one(self, tile):
try:
- key_name = self.tile_layout.filename(tile.tilecoord)
+ key_name = self.tilelayout.filename(tile.tilecoord)
if not self.dry_run:
self.s3bucket.delete(key_name)
except S3Error as exc:
tile.error = exc
return tile
def get_one(self, tile):
- key_name = self.tile_layout.filename(tile.tilecoord)
+ key_name = self.tilelayout.filename(tile.tilecoord)
try:
tile.s3key = self.s3bucket.get(key_name)
tile.data = tile.s3key.body
@@ -60,17 +60,17 @@ def get_one(self, tile):
return tile
def list(self):
- prefix = getattr(self.tile_layout, 'prefix', '')
+ prefix = getattr(self.tilelayout, 'prefix', '')
for s3key in self.s3bucket.list_objects(prefix=prefix):
try:
- tilecoord = self.tile_layout.tilecoord(s3key.name)
+ tilecoord = self.tilelayout.tilecoord(s3key.name)
except ValueError:
continue
yield Tile(tilecoord, s3key=s3key)
def put_one(self, tile):
assert tile.data is not None
- key_name = self.tile_layout.filename(tile.tilecoord)
+ key_name = self.tilelayout.filename(tile.tilecoord)
s3key = self.s3bucket.key(key_name)
s3key.body = tile.data
if tile.content_encoding is not None:
View
4 tilecloud/store/tilejson.py
@@ -43,8 +43,8 @@ def __init__(self, tile_json, urls_key='tiles', **kwargs):
kwargs['content_type'] = content_types.pop()
templates = [re.sub(r'\{([xyz])\}', lambda m: '%%(%s)d' % m.group(1), url)
for url in urls]
- tile_layouts = map(TemplateTileLayout, templates)
- URLTileStore.__init__(self, tile_layouts, **kwargs)
+ tilelayouts = map(TemplateTileLayout, templates)
+ URLTileStore.__init__(self, tilelayouts, **kwargs)
@classmethod
def from_url(cls, url):
View
10 tilecloud/store/url.py
@@ -9,18 +9,18 @@
class URLTileStore(TileStore):
- def __init__(self, tile_layouts, headers=None, **kwargs):
+ def __init__(self, tilelayouts, headers=None, **kwargs):
TileStore.__init__(self, **kwargs)
- self.tile_layouts = tuple(tile_layouts)
+ self.tilelayouts = tuple(tilelayouts)
self.headers = headers or {}
def get_one(self, tile):
if self.bounding_pyramid is not None:
if tile.tilecoord not in self.bounding_pyramid:
return None
- tile_layout = self.tile_layouts[hash(tile.tilecoord) %
- len(self.tile_layouts)]
- url = tile_layout.filename(tile.tilecoord)
+ tilelayout = self.tilelayouts[hash(tile.tilecoord) %
+ len(self.tilelayouts)]
+ url = tilelayout.filename(tile.tilecoord)
request = Request(url, headers=self.headers)
try:
logger.debug('GET %s' % (url,))
View
22 tilecloud/tests/test_tilelayout.py
@@ -23,14 +23,14 @@ def test_tilecoord(self):
class TestOSMTileLayout(unittest.TestCase):
def setUp(self):
- self.tile_layout = OSMTileLayout()
+ self.tilelayout = OSMTileLayout()
def test_filename(self):
- self.assertEqual(self.tile_layout.filename(TileCoord(1, 2, 3)), '1/2/3')
+ self.assertEqual(self.tilelayout.filename(TileCoord(1, 2, 3)), '1/2/3')
def test_tilecoord(self):
- self.assertEqual(self.tile_layout.tilecoord('1/2/3'), TileCoord(1, 2, 3))
- self.assertRaises(ValueError, self.tile_layout.tilecoord, '1/2/')
+ self.assertEqual(self.tilelayout.tilecoord('1/2/3'), TileCoord(1, 2, 3))
+ self.assertRaises(ValueError, self.tilelayout.tilecoord, '1/2/')
class TestWMTSTileLayout(unittest.TestCase):
@@ -212,23 +212,23 @@ def test_metatile_border(self):
class TestTemplateTileLayout(unittest.TestCase):
def setUp(self):
- self.tile_layout = TemplateTileLayout('%(z)d/%(x)d/%(y)d')
+ self.tilelayout = TemplateTileLayout('%(z)d/%(x)d/%(y)d')
def test_filename(self):
- self.assertEqual(self.tile_layout.filename(TileCoord(1, 2, 3)), '1/2/3')
+ self.assertEqual(self.tilelayout.filename(TileCoord(1, 2, 3)), '1/2/3')
def test_tilecoord(self):
- self.assertEqual(self.tile_layout.tilecoord('1/2/3'), TileCoord(1, 2, 3))
+ self.assertEqual(self.tilelayout.tilecoord('1/2/3'), TileCoord(1, 2, 3))
class TestWrappedTileLayout(unittest.TestCase):
def setUp(self):
- self.tile_layout = WrappedTileLayout(OSMTileLayout(), 'prefix/', '.suffix')
+ self.tilelayout = WrappedTileLayout(OSMTileLayout(), 'prefix/', '.suffix')
def test_filename(self):
- self.assertEqual(self.tile_layout.filename(TileCoord(1, 2, 3)), 'prefix/1/2/3.suffix')
+ self.assertEqual(self.tilelayout.filename(TileCoord(1, 2, 3)), 'prefix/1/2/3.suffix')
def test_tilecoord(self):
- self.assertEqual(self.tile_layout.tilecoord('prefix/1/2/3.suffix'), TileCoord(1, 2, 3))
- self.assertRaises(ValueError, self.tile_layout.tilecoord, 'prefix//1/2/3.suffix')
+ self.assertEqual(self.tilelayout.tilecoord('prefix/1/2/3.suffix'), TileCoord(1, 2, 3))
+ self.assertRaises(ValueError, self.tilelayout.tilecoord, 'prefix//1/2/3.suffix')

0 comments on commit 13a1b53

Please sign in to comment.