Skip to content

Instantly share code, notes, and snippets.

What would you like to do? - backing this up. Via
#!/usr/bin/env python
import os
# determine valid TMS zoom levels available
zoomLevels = [z for z in xrange(0, 21) if os.path.isdir('%d' % z)]
# Creates two scripts
# 01 Rename old filenames to a temporary file. This is done to prevent
# overwriting an old and new file that happen to share the same name
# 02 Rename temporary files to their new filenames
old_to_temp_script = file('', 'w')
temp_to_new_script = file('', 'w')
for z in zoomLevels:
for dirName, subDirs, files in os.walk('%d' % z):
for file in files:
y, extension = file.split('.')[0:2]
if extension != 'png':
# bug: need to add a check whether the filename is actually a TMS coordinate
y = int(y)
newy = ((2**z) - 1) - y
old_to_temp_script.write('mv %s/%d.%s %s/%d.%s.tmp\n' % (
dirName, y, extension,
dirName, newy, extension))
temp_to_new_script.write('mv %s/%d.%s.tmp %s/%d.%s\n' % (
dirName, newy, extension,
dirName, newy, extension))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment