source: subversion/applications/rendering/parking/mapnik/setup_target_style.py @ 26767

Revision 26767, 6.9 KB checked in by kdrangmeister, 3 years ago (diff)

Started wifi layer

  • Property svn:mime-type set to text/plain
Line 
1# -*- coding: utf-8 -*-
2# by kay
3
4import sys,os,shutil
5from optparse import OptionParser
6#from xml.dom.minidom import parse, parseString
7#import colorsys
8import mapnik_to_bw,generate_parking_layer_xml,generate_wifi_layer_xml
9
10def add_license_files(dirname):
11    f = open(os.path.join(dirname,"CONTACT"), 'w')
12    f.write("This style is created by kayd@toolserver.org")
13    f.close
14    f = open(os.path.join(dirname,"LICENSE"), 'w')
15    f.write("This derived work is published by the author, Kay Drangmeister, under the same license as the original OSM mapnik style sheet (found here: http://svn.openstreetmap.org/applications/rendering/mapnik)")
16    f.close
17
18"""
19deploy_base_dir, e.g. /tmp/kays-styles/
20style_name, e.g. bw-noicons
21"""
22def setup_deploy_directory(deploy_base_dir,style_name):
23    dest_dir_style = os.path.join(deploy_base_dir,style_name)
24    dest_dir_style_symbols = os.path.join(dest_dir_style,"symbols")
25    #dest_style_file_name = 'osm-'+style_name+'.xml'
26    #dest_style_file = os.path.join(dest_dir_style,dest_style_file_name)
27    if not os.path.exists(dest_dir_style_symbols):
28        os.makedirs(dest_dir_style_symbols)
29    add_license_files(dest_dir_style)
30
31def copy_files(src,dest,files):
32    for f in files:
33        if type(f) is tuple:
34            shutil.copy2(os.path.join(src,f[0]),os.path.join(dest,f[1]))
35        else:
36            shutil.copy2(os.path.join(src,f),os.path.join(dest,f))
37
38def copy_settings_files(settings_dir,target_inc_dir):
39    copy_files(settings_dir,target_inc_dir,[
40        ("datasource-settings.xml.inc.toolserver","datasource-settings.xml.inc"),
41        ("fontset-settings.xml.inc.toolserver","fontset-settings.xml.inc"),
42        ("settings.xml.inc.toolserver","settings.xml.inc")]
43    )
44
45def main(options):
46    original_mapnik_dir = options['mapnikdir']
47    original_parking_dir = options['parkingdir']
48    original_wifi_dir = options['wifidir']
49    settings_dir = options['settingsdir']
50    temp_dir = options['tempdir']
51    deploy_dir = options['deploydir']
52
53    # (0) clean temp and deploy dirs
54    shutil.rmtree(temp_dir,ignore_errors=True)
55    shutil.rmtree(deploy_dir,ignore_errors=True)
56
57    # (1) copy the mapnik to temp and patch with local settings.
58    patched_mapnik_dir = os.path.join(temp_dir,"mapnik")
59    shutil.copytree(original_mapnik_dir,patched_mapnik_dir)
60    copy_settings_files(settings_dir,os.path.join(patched_mapnik_dir,"inc"))
61
62    # (2) create the bw styles
63    mapnik_to_bw.main({'sourcedir':patched_mapnik_dir, 'sourcefile':'osm.xml', 'destdir':deploy_dir})
64
65    # (3) create the parking styles
66    parking_dir = os.path.join(temp_dir,"parking")
67    parking_inc_dir = os.path.join(parking_dir,"inc")
68    os.makedirs(parking_dir)
69    shutil.copy2(os.path.join(original_parking_dir,"osm-parktrans-src.xml"),os.path.join(parking_dir,"osm-parktrans-src.xml"))
70    shutil.copy2(os.path.join(original_parking_dir,"osm-parking-src.xml"),os.path.join(parking_dir,"osm-parking-src.xml"))
71    # prepare the parking/inc dir: copy mapnik/inc, then patch with files from parking-inc-src
72    shutil.copytree(os.path.join(patched_mapnik_dir,"inc"),parking_inc_dir)
73    original_parking_inc_dir = os.path.join(original_parking_dir,"parking-inc-src")    # copy the parking-specific inc files
74    copy_files(original_parking_inc_dir,parking_inc_dir,["layer-parking-entities.xml.inc","layer-parking-area.xml.inc","layer-parking-lane.xml.inc","layer-parking-point.xml.inc"])
75    # prepare the parking/symbols dir
76    # TODO: kludge to copy bw icons to parking/symbols dir
77    # this is ugly because it relies on knowledge of mapnik_to_bw.main() i.e. how the dirs are named.
78    shutil.copytree(os.path.join(os.path.join(deploy_dir,"bw-noicons"),"symbols"),os.path.join(parking_dir,"symbols"))
79    shutil.copytree(os.path.join(original_parking_dir,"parking-symbols-src"),os.path.join(parking_dir,"parking-symbols-src"))
80
81    generate_parking_layer_xml.main_parktrans({'sourcedir':parking_dir, 'sourcefile':'osm-parktrans-src.xml', 'destdir':deploy_dir, 'stylename':'parktrans'})
82    shutil.copytree(os.path.join(os.path.join(deploy_dir,"bw-noicons"),"symbols"),os.path.join(os.path.join(deploy_dir,"parking"),"symbols"))
83    generate_parking_layer_xml.main_parking({'sourcebwndir':os.path.join(deploy_dir,'bw-noicons'), 'sourcebwnfile':'osm-bw-noicons.xml', 'sourcepdir':parking_dir, 'sourcepfile':'osm-parking-src.xml', 'destdir':deploy_dir, 'stylename':'parking'})
84
85    # (4) create the wifi styles
86    wifi_dir = os.path.join(temp_dir,"wifi")
87    wifi_inc_dir = os.path.join(wifi_dir,"inc")
88    os.makedirs(wifi_dir)
89    shutil.copy2(os.path.join(original_wifi_dir,"osm-wifitrans-src.xml"),os.path.join(wifi_dir,"osm-wifitrans-src.xml"))
90    shutil.copy2(os.path.join(original_wifi_dir,"osm-wifi-src.xml"),os.path.join(wifi_dir,"osm-wifi-src.xml"))
91    # prepare the wifi/inc dir: copy mapnik/inc, then patch with files from wifi-inc-src
92    shutil.copytree(os.path.join(patched_mapnik_dir,"inc"),wifi_inc_dir)
93    original_wifi_inc_dir = os.path.join(original_wifi_dir,"wifi-inc-src")    # copy the wifi-specific inc files
94    copy_files(original_wifi_inc_dir,wifi_inc_dir,["layer-wifi-entities.xml.inc","layer-wifi-area.xml.inc","layer-wifi-point.xml.inc"])
95    # prepare the wifi/symbols dir
96    # TODO: kludge to copy bw icons to wifi/symbols dir
97    # this is ugly because it relies on knowledge of mapnik_to_bw.main() i.e. how the dirs are named.
98    shutil.copytree(os.path.join(os.path.join(deploy_dir,"bw-noicons"),"symbols"),os.path.join(wifi_dir,"symbols"))
99    shutil.copytree(os.path.join(original_wifi_dir,"wifi-symbols-src"),os.path.join(wifi_dir,"wifi-symbols-src"))
100
101    generate_wifi_layer_xml.main_wifitrans({'sourcedir':wifi_dir, 'sourcefile':'osm-wifi-src.xml', 'destdir':deploy_dir, 'stylename':'wifitrans'})
102    shutil.copytree(os.path.join(os.path.join(deploy_dir,"bw-noicons"),"symbols"),os.path.join(os.path.join(deploy_dir,"wifi"),"symbols"))
103    generate_wifi_layer_xml.main_wifi({'sourcebwndir':os.path.join(deploy_dir,'bw-noicons'), 'sourcebwnfile':'osm-bw-noicons.xml', 'sourcepdir':wifi_dir, 'sourcepfile':'osm-wifi-src.xml', 'destdir':deploy_dir, 'stylename':'wifi'})
104
105
106if __name__ == '__main__':
107    parser = OptionParser()
108    parser.add_option("-m", "--mapnikdir", dest="mapnikdir", help="path to the mapnik directory", default="./mapnik")
109    parser.add_option("-p", "--parkingdir", dest="parkingdir", help="path to the parking source directory", default=".")
110    parser.add_option("-w", "--wifidir", dest="wifidir", help="path to the wifi source directory", default=".")
111    parser.add_option("-s", "--settingsdir", dest="settingsdir", help="path to the mapnik settings directory", default="./mapnik-patch")
112    parser.add_option("-t", "--tempdir", dest="tempdir", help="path to the temporary directory", default="/tmp/kays-styles-mapnik")
113    parser.add_option("-d", "--deploydir", dest="deploydir", help="path to the deploy directory, further dirs are created within. default is '/tmp'", default="/tmp")
114    (options, args) = parser.parse_args()
115    print options
116    main(options.__dict__)
117    sys.exit(0)
Note: See TracBrowser for help on using the repository browser.