#!/usr/bin/python

# This script can be called on a directory of geotiffs
# It will then create a mapnik stylesheet referencing all
# the tiffs found. The xml file can then be edited to make the 
# ordering correct

from optparse import OptionParser
import os
import sys
import glob

i = 0

#TODO
#parser = OptionParser()


print >> sys.stdout, '''<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE Map>
<Map bgcolor="#000" 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 +no_defs +over">

  <Style name="imagery">
    <Rule>
      <RasterSymbolizer/>
    </Rule>
  </Style>
'''

for X in glob.glob('/home/gravitystorm/philippines-working/warped/*'):
  i += 1
  print >> sys.stdout, '''  <Layer name="imagery%i" status="on">
    <StyleName>imagery</StyleName>
    <Datasource>
      <Parameter name="type">gdal</Parameter>
      <Parameter name="file">%s</Parameter>
    </Datasource>
  </Layer>
''' % (i, X)
print >> sys.stdout, "</Map>"
