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

Last change on this file since 26369 was 26369, checked in by kdrangmeister, 9 years ago

change deployment, removed parking-old and moved parking-new to parking.

  • Property svn:mime-type set to text/plain
File size: 6.1 KB
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
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    settings_dir = options['settingsdir']
49    temp_dir = options['tempdir']
50    deploy_dir = options['deploydir']
51
52    # clean temp and deploy dirs
53    print "** cleaning temp dir "+temp_dir
54    shutil.rmtree(temp_dir,ignore_errors=True)
55    print "** cleaning deploy dir "+deploy_dir
56    shutil.rmtree(deploy_dir,ignore_errors=True)
57
58    # (1) copy the mapnik to temp and patch with local settings.
59    patched_mapnik_dir = os.path.join(temp_dir,"mapnik")
60    #os.makedirs(patched_mapnik_dir)
61    #print "shutil.copytree(original_mapnik_dir={o},patched_mapnik_dir={p})".format(o=original_mapnik_dir,p=patched_mapnik_dir)
62    shutil.copytree(original_mapnik_dir,patched_mapnik_dir)
63    copy_settings_files(settings_dir,os.path.join(patched_mapnik_dir,"inc"))
64
65    # (2) create the bw styles
66    mapnik_to_bw.main({'sourcedir':patched_mapnik_dir, 'sourcefile':'osm.xml', 'destdir':deploy_dir})
67
68    # (3) create the parking styles
69    parking_dir = os.path.join(temp_dir,"parking")
70    parking_inc_dir = os.path.join(parking_dir,"inc")
71    os.makedirs(parking_dir)
72    #print "shutil.copytree(original_mapnik_dir={o},patched_mapnik_dir={p})".format(o=original_mapnik_dir,p=patched_mapnik_dir)
73    #shutil.copy2(os.path.join(original_parking_dir,"colorents.xml.inc"),os.path.join(parking_base_dir,"colorents.xml.inc"))
74    #shutil.copy2(os.path.join(original_parking_dir,"colorents-bw.xml.inc"),os.path.join(parking_base_dir,"colorents-bw.xml.inc"))
75    # TODO: ^^^^ remove this
76    shutil.copy2(os.path.join(original_parking_dir,"osm-parktrans-src.xml"),os.path.join(parking_dir,"osm-parktrans-src.xml"))
77    #shutil.copy2(os.path.join(original_parking_dir,"osm-parking-old-src.xml"),os.path.join(parking_dir,"osm-parking-old-src.xml"))
78    shutil.copy2(os.path.join(original_parking_dir,"osm-parking-src.xml"),os.path.join(parking_dir,"osm-parking-src.xml"))
79    # prepare the parking/inc dir: copy mapnik/inc, then patch with files from parking-inc-src
80    shutil.copytree(os.path.join(patched_mapnik_dir,"inc"),parking_inc_dir)
81    original_parking_inc_dir = os.path.join(original_parking_dir,"parking-inc-src")    # copy the parking-specific inc files
82    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"])
83    # prepare the parking/symbols dir
84    # TODO: kludge to copy bw icons to parking/symbols dir
85    # this is ugly because it relies on knowledge of mapnik_to_bw.main() i.e. how the dirs are named.
86    shutil.copytree(os.path.join(os.path.join(deploy_dir,"bw-noicons"),"symbols"),os.path.join(parking_dir,"symbols"))
87    #shutil.copytree(os.path.join(original_mapnik_dir,"symbols"),os.path.join(parking_dir,"symbols"))
88    shutil.copytree(os.path.join(original_parking_dir,"parking-symbols-src"),os.path.join(parking_dir,"parking-symbols-src"))
89
90    generate_parking_layer_xml.main_parktrans({'sourcedir':parking_dir, 'sourcefile':'osm-parktrans-src.xml', 'destdir':deploy_dir, 'stylename':'parktrans'})
91    #generate_parking_layer_xml.main_parking({'sourcedir':parking_dir, 'sourcefile':'osm-parking-old-src.xml', 'destdir':deploy_dir, 'stylename':'parking-old'})
92    shutil.copytree(os.path.join(os.path.join(deploy_dir,"bw-noicons"),"symbols"),os.path.join(os.path.join(deploy_dir,"parking"),"symbols"))
93    generate_parking_layer_xml.main_parking_neu({'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'})
94
95if __name__ == '__main__':
96    parser = OptionParser()
97    parser.add_option("-m", "--mapnikdir", dest="mapnikdir", help="path to the mapnik directory", default="./mapnik")
98    parser.add_option("-p", "--parkingdir", dest="parkingdir", help="path to the parking source directory", default=".")
99    parser.add_option("-s", "--settingsdir", dest="settingsdir", help="path to the mapnik settings directory", default="./mapnik-patch")
100    parser.add_option("-t", "--tempdir", dest="tempdir", help="path to the temporary directory", default="/tmp/kays-styles-mapnik")
101    parser.add_option("-d", "--deploydir", dest="deploydir", help="path to the deploy directory, further dirs are created within. default is '/tmp'", default="/tmp")
102    (options, args) = parser.parse_args()
103    print options
104    main(options.__dict__)
105    sys.exit(0)
Note: See TracBrowser for help on using the repository browser.