Skip to content

Instantly share code, notes, and snippets.

@dwins
Created July 19, 2011 13:38
Show Gist options
  • Save dwins/1092353 to your computer and use it in GitHub Desktop.
Save dwins/1092353 to your computer and use it in GitHub Desktop.
Upload a directory of SLDs
import geoserver.catalog
import os, os.path
cat = geoserver.catalog.Catalog(
'http://localhost:8080/geoserver/rest',
"admin", "geoserver")
style_dir = "/home/dwins/Downloads/graphite/"
suffix = 'graphite'
extant_styles = set(s.name for s in cat.get_styles())
for style_file in os.listdir(style_dir):
base, ext = os.path.splitext(style_file)
name = '%s_%s' % (base, suffix) if suffix else base
if ext == '.sld':
overwrite = (name in extant_styles)
with open(os.path.join(style_dir, style_file)) as sld:
cat.create_style(name, sld.read(), overwrite)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment