Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert to Python3 #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cascadenik-compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def main(src_file, dest_file, **kwargs):
mmap = mapnik.Map(1, 1)
# allow [zoom] filters to work
mmap.srs = '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null'
load_kwargs = dict([(k, v) for (k, v) in kwargs.items() if k in ('cache_dir', 'scale', 'verbose', 'datasources_cfg', 'user_styles')])
load_kwargs = dict([(k, v) for (k, v) in list(kwargs.items()) if k in ('cache_dir', 'scale', 'verbose', 'datasources_cfg', 'user_styles')])
cascadenik.load_map(mmap, src_file, dirname(realpath(dest_file)), **load_kwargs)

(handle, tmp_file) = tempfile.mkstemp(suffix='.xml', prefix='cascadenik-mapnik-')
Expand All @@ -47,7 +47,7 @@ def main(src_file, dest_file, **kwargs):
if os.path.exists(dest_file):
os.unlink(dest_file)

os.chmod(tmp_file, 0666^os.umask(0))
os.chmod(tmp_file, 0o666^os.umask(0))
shutil.move(tmp_file, dest_file)
return 0

Expand Down Expand Up @@ -89,7 +89,7 @@ def main(src_file, dest_file, **kwargs):

layersfile, outputfile = args[0:2]

print >> sys.stderr, 'output file:', outputfile, dirname(realpath(outputfile))
print('output file:', outputfile, dirname(realpath(outputfile)), file=sys.stderr)

if not layersfile.endswith('.mml'):
parser.error('Input must be an .mml file')
Expand Down
28 changes: 14 additions & 14 deletions cascadenik-extract-dscfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import os, sys
import math
import pprint
import urllib
import urlparse
import urllib.request, urllib.parse, urllib.error
import urllib.parse
import tempfile
import StringIO
import io
import os.path
import zipfile
import itertools
import re
import ConfigParser
import configparser
import codecs
import optparse

Expand Down Expand Up @@ -46,7 +46,7 @@ def add_source(sources, ds_name, params):
op = sources[ds_name]
c = 0
while True:
for k,v in op.items():
for k,v in list(op.items()):
# dicts are unequal
if k not in params or op[k] != params[k]:
c += 1
Expand All @@ -61,17 +61,17 @@ def add_source(sources, ds_name, params):


#
class MyConfigParser(ConfigParser.RawConfigParser):
class MyConfigParser(configparser.RawConfigParser):
def write(self, fp):
"""Write an .ini-format representation of the configuration state."""
if self._defaults:
fp.write("[%s]\n" % ConfigParser.DEFAULTSECT)
for (key, value) in sorted(self._defaults.items(), key=lambda x: x[0]):
fp.write("[%s]\n" % configparser.DEFAULTSECT)
for (key, value) in sorted(list(self._defaults.items()), key=lambda x: x[0]):
fp.write("%s = %s\n" % (key, str(value).replace('\n', '\n\t')))
fp.write("\n")
for section in sorted(self._sections):
fp.write("[%s]\n" % section)
for (key, value) in sorted(self._sections[section].items(), key=lambda x: x[0]):
for (key, value) in sorted(list(self._sections[section].items()), key=lambda x: x[0]):
if key != "__name__":
fp.write("%s = %s\n" %
(key, str(value).replace('\n', '\n\t')))
Expand All @@ -90,13 +90,13 @@ def convert(src, outmml, outconfig, opts):
src = 'file:%s' % src


doc = ElementTree.parse(urllib.urlopen(src))
doc = ElementTree.parse(urllib.request.urlopen(src))
map = doc.getroot()

defaults = standard_projections
sources = {}

all_srs = dict([(v,k) for k,v in standard_projections.items()])
all_srs = dict([(v,k) for k,v in list(standard_projections.items())])

name_filter = re.compile("\W")

Expand Down Expand Up @@ -137,7 +137,7 @@ def convert(src, outmml, outconfig, opts):
# now generate unique bases
g_params = {}

for name, params in sources.items():
for name, params in list(sources.items()):
gp = {}
name_base = None
if params.get('type') == 'postgis':
Expand All @@ -163,9 +163,9 @@ def convert(src, outmml, outconfig, opts):

config = MyConfigParser(defaults)

for name,params in itertools.chain(g_params.values(), sources.items()):
for name,params in itertools.chain(list(g_params.values()), list(sources.items())):
config.add_section(name)
for pn,pv in params.items():
for pn,pv in list(params.items()):
if pn == 'table': pv = pv.strip()
config.set(name,pn,pv)
with codecs.open(outconfig,"w","utf-8") as oc:
Expand Down
16 changes: 8 additions & 8 deletions cascadenik-style.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ def main(filename):
declarations = cascadenik.stylesheet_declarations(input, is_merc=True)

for dec in declarations:
print dec.selector,
print '{',
print dec.property.name+':',
print(dec.selector, end=' ')
print('{', end=' ')
print(dec.property.name+':', end=' ')

if cascadenik.style.properties[dec.property.name] in (cascadenik.style.color, cascadenik.style.boolean, cascadenik.style.numbers):
print str(dec.value.value)+';',
print(str(dec.value.value)+';', end=' ')

elif cascadenik.style.properties[dec.property.name] is cascadenik.style.uri:
print 'url("'+str(dec.value.value)+'");',
print('url("'+str(dec.value.value)+'");', end=' ')

elif cascadenik.style.properties[dec.property.name] is str:
print '"'+str(dec.value.value)+'";',
print('"'+str(dec.value.value)+'";', end=' ')

elif cascadenik.style.properties[dec.property.name] in (int, float) or type(cascadenik.style.properties[dec.property.name]) is tuple:
print str(dec.value.value)+';',
print(str(dec.value.value)+';', end=' ')

print '}'
print('}')

return 0

Expand Down
4 changes: 2 additions & 2 deletions cascadenik/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from os import mkdir, chmod
from os.path import isdir, realpath, expanduser, dirname, exists
from urlparse import urlparse
from urllib.parse import urlparse

# import mapnik
try:
Expand Down Expand Up @@ -84,7 +84,7 @@ def load_map(map, src_file, output_dir, scale=1, cache_dir=None, datasources_cfg
# only make the cache dir if it wasn't user-provided
if not isdir(cache_dir):
mkdir(cache_dir)
chmod(cache_dir, 0755)
chmod(cache_dir, 0o755)

dirs = Directories(output_dir, realpath(cache_dir), dirname(src_file))
compile(src_file, dirs, verbose, datasources_cfg=datasources_cfg, user_styles=user_styles, scale=scale).to_mapnik(map, dirs)
Loading