Mostly a blind copy/past from world.py and googlemap.py. Not runnable Rewrite Tracking Issue: #565
117 lines
4.2 KiB
Python
117 lines
4.2 KiB
Python
# This file is part of the Minecraft Overviewer.
|
|
#
|
|
# Minecraft Overviewer is free software: you can redistribute it and/or
|
|
# modify it under the terms of the GNU General Public License as published
|
|
# by the Free Software Foundation, either version 3 of the License, or (at
|
|
# your option) any later version.
|
|
#
|
|
# Minecraft Overviewer is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
# Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License along
|
|
# with the Overviewer. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
import os
|
|
import os.path
|
|
import stat
|
|
import cPickle
|
|
import Image
|
|
import shutil
|
|
from time import strftime, localtime
|
|
import json
|
|
import locale
|
|
import codecs
|
|
|
|
import util
|
|
from c_overviewer import get_render_mode_inheritance, get_render_mode_info
|
|
import overviewer_version
|
|
|
|
"""
|
|
This module has routines related to generating a Google Maps-based
|
|
interface out of a set of tiles.
|
|
|
|
"""
|
|
|
|
def mirror_dir(src, dst, entities=None):
|
|
'''copies all of the entities from src to dst'''
|
|
if not os.path.exists(dst):
|
|
os.mkdir(dst)
|
|
if entities and type(entities) != list: raise Exception("Expected a list, got a %r instead" % type(entities))
|
|
|
|
# files which are problematic and should not be copied
|
|
# usually, generated by the OS
|
|
skip_files = ['Thumbs.db', '.DS_Store']
|
|
|
|
for entry in os.listdir(src):
|
|
if entry in skip_files:
|
|
continue
|
|
if entities and entry not in entities:
|
|
continue
|
|
|
|
if os.path.isdir(os.path.join(src,entry)):
|
|
mirror_dir(os.path.join(src, entry), os.path.join(dst, entry))
|
|
elif os.path.isfile(os.path.join(src,entry)):
|
|
try:
|
|
shutil.copy(os.path.join(src, entry), os.path.join(dst, entry))
|
|
except IOError as outer:
|
|
try:
|
|
# maybe permission problems?
|
|
src_stat = os.stat(os.path.join(src, entry))
|
|
os.chmod(os.path.join(src, entry), src_stat.st_mode | stat.S_IRUSR)
|
|
dst_stat = os.stat(os.path.join(dst, entry))
|
|
os.chmod(os.path.join(dst, entry), dst_stat.st_mode | stat.S_IWUSR)
|
|
except OSError: # we don't care if this fails
|
|
pass
|
|
shutil.copy(os.path.join(src, entry), os.path.join(dst, entry))
|
|
# if this stills throws an error, let it propagate up
|
|
|
|
class MapGen(object):
|
|
def __init__(self, quadtrees, configInfo):
|
|
"""Generates a Google Maps interface for the given list of
|
|
quadtrees. All of the quadtrees must have the same destdir,
|
|
image format, and world.
|
|
|
|
Note:tiledir for each quadtree should be unique. By default the tiledir
|
|
is determined by the rendermode
|
|
|
|
"""
|
|
|
|
self.skipjs = configInfo.get('skipjs', False)
|
|
self.nosigns = configInfo.get('nosigns', False)
|
|
self.web_assets_hook = configInfo.get('web_assets_hook', None)
|
|
self.web_assets_path = configInfo.get('web_assets_path', None)
|
|
self.bg_color = configInfo.get('bg_color')
|
|
self.north_direction = configInfo.get('north_direction', 'lower-left')
|
|
|
|
if not len(quadtrees) > 0:
|
|
raise ValueError("there must be at least one quadtree to work on")
|
|
|
|
self.destdir = quadtrees[0].destdir
|
|
self.world = quadtrees[0].world
|
|
self.p = quadtrees[0].p
|
|
for i in quadtrees:
|
|
if i.destdir != self.destdir or i.world != self.world:
|
|
raise ValueError("all the given quadtrees must have the same destdir and world")
|
|
|
|
self.quadtrees = quadtrees
|
|
|
|
def go(self, procs):
|
|
"""Writes out overviewerConfig.js and does copying of the other static web assets
|
|
|
|
"""
|
|
### TODO remove this method? It has been moved into assetmanager.py
|
|
|
|
pass
|
|
|
|
|
|
def finalize(self):
|
|
"""Write out persistent data file and marker listings file
|
|
"""
|
|
### TODO remove this method? It has been moved into assetmanager.py
|
|
pass
|
|
|
|
|
|
|