<commit_before>#!/usr/bin/env python

import os
import re
import sys
import glob
import optparse
import platform
import tempfile

__version__ = '0.1.0'

REASONABLE_DEFAULTS = {
        'epsg':'900913', # default osm2pgsql import srid
        'world_boundaries':'world_boundaries', # relative path
        'symbols':'symbols', # relative path
        'prefix':'planet_osm', # default osm2pgsql table prefix
        'extent':'-20037508,-19929239,20037508,19929239', # world in merc
        'inc':'inc/*.template', # search path for inc templates to parse
        'estimate_extent':'false',   
        'extent':'-20037508,-19929239,20037508,19929239',   
        }

def color_text(color, text):
    if os.name == 'nt':
        return text
    return "\033[9%sm%s\033[0m" % (color,text)

class Params:
    def __init__(self,params,accept_none):
        self.params = params
        self.accept_none = accept_none
        self.missing = []
    
    def blend_with_env(self,opts):
        d = {}
        
        for p in self.params:
            env_var_name = 'MAPNIK_%s' % p.upper()

            # first pull from passed options...
            if not opts.get(p) is None:
                d[p] = opts[p]

            # then try to pull from environment settings
            elif not os.environ.get(env_var_name) is None:
                d[p] = os.environ[env_var_name]

            # then assign any reasonable default values...
            elif p in REASONABLE_DEFAULTS.keys():
                d[p] = REASONABLE_DEFAULTS[p]
            # if --accept-none is passed then we assume
            # its a paramater that mapnik likely does not need
            # and will ignore if it is an empty string (e.g. db values)
            elif self.accept_none:
                d[p] = ''
            else:
                self.missing.append(p)
        return d

def generate_help_text(var,default):
    if var == 'host':
        return 'Set postgres database host %s' % default
    elif var == 'port':
        return 'Set postgres database host %s' % default
    return "Set value of '%s' %s" % (var,default)
    
def serialize(xml,options):
    try:
        import mapnik
    except:
        sys.exit(color_text(1,'Error: saving xml requires Mapnik python bindings to be installed'))
    m = mapnik.Map(1,1)<commit_msg>support mapnik2 as well<commit_after>#!/usr/bin/env python

import os
import re
import sys
import glob
import optparse
import platform
import tempfile

__version__ = '0.1.0'

REASONABLE_DEFAULTS = {
        'epsg':'900913', # default osm2pgsql import srid
        'world_boundaries':'world_boundaries', # relative path
        'symbols':'symbols', # relative path
        'prefix':'planet_osm', # default osm2pgsql table prefix
        'extent':'-20037508,-19929239,20037508,19929239', # world in merc
        'inc':'inc/*.template', # search path for inc templates to parse
        'estimate_extent':'false',   
        'extent':'-20037508,-19929239,20037508,19929239',   
        }

def color_text(color, text):
    if os.name == 'nt':
        return text
    return "\033[9%sm%s\033[0m" % (color,text)

class Params:
    def __init__(self,params,accept_none):
        self.params = params
        self.accept_none = accept_none
        self.missing = []
    
    def blend_with_env(self,opts):
        d = {}
        
        for p in self.params:
            env_var_name = 'MAPNIK_%s' % p.upper()

            # first pull from passed options...
            if not opts.get(p) is None:
                d[p] = opts[p]

            # then try to pull from environment settings
            elif not os.environ.get(env_var_name) is None:
                d[p] = os.environ[env_var_name]

            # then assign any reasonable default values...
            elif p in REASONABLE_DEFAULTS.keys():
                d[p] = REASONABLE_DEFAULTS[p]
            # if --accept-none is passed then we assume
            # its a paramater that mapnik likely does not need
            # and will ignore if it is an empty string (e.g. db values)
            elif self.accept_none:
                d[p] = ''
            else:
                self.missing.append(p)
        return d

def generate_help_text(var,default):
    if var == 'host':
        return 'Set postgres database host %s' % default
    elif var == 'port':
        return 'Set postgres database host %s' % default
    return "Set value of '%s' %s" % (var,default)
    
def serialize(xml,options):
    try:
        import mapnik2 as mapnik
    except:
        try:
            import mapnik
        except:
            sys.exit(color_text(1,'Error: saving xml requires Mapnik python bindings to be installed'))
    m = mapnik.Map(1,1)
{'fraction_non_alphanumeric': 0.10613810741687979, 'fraction_numerical': 0.0370843989769821, 'mean_word_length': 2.1120689655172415, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2796806', 'n_tokens_mistral': 1561, 'n_tokens_neox': 1433, 'n_words': 406}