Created
May 4, 2014 23:07
-
-
Save alexgleith/844146bb24b4f22d856e to your computer and use it in GitHub Desktop.
Python Truncate or Seed GeoWebCache GeoServer Layers Python Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import urllib2 | |
import base64 | |
un='username' | |
pw='password' | |
baseURL = "https://URL/geoserver/gwc/rest/seed/" | |
descURL = "https://URL/geoserver/gwc/rest/layers/" | |
baseDataString = {'seedRequest':{'minX':[],'minY':[],'maxX':[],'maxY':[],'gridSetId':'EPSG:900913','zoomStart':00,'zoomStop':20,'format':'image/png','type':'truncate','threadCount':2}} | |
def truncateLayer(layer): | |
print 'truncating: ' + layer | |
url = baseURL + layer + '.json' | |
urlDesc = descURL + layer + '.json' | |
desc = urllib2.Request(urlDesc) | |
base64string = base64.encodestring('%s:%s' % (un, pw)).replace('\n', '') | |
desc.add_header("Authorization", "Basic %s" % base64string) | |
try: | |
layerInfo = json.loads(urllib2.urlopen(desc).read())['GeoServerLayer'] | |
imageFormats = layerInfo['mimeFormats'] | |
gridsets = [] | |
for gridset in layerInfo['gridSubsets']: | |
gridsets.append(gridset['gridSetName']) | |
for gs in gridsets: | |
print 'removing gridset: ' + gs | |
for imf in imageFormats: | |
print 'removing image format: ' + imf | |
try: | |
request = urllib2.Request(url) | |
base64string = base64.encodestring('%s:%s' % (un, pw)).replace('\n', '') | |
request.add_header("Authorization", "Basic %s" % base64string) | |
request.add_header('Content-Type', 'application/json') | |
data = {'seedRequest':{'minX':[],'minY':[],'maxX':[],'maxY':[],'gridSetId':gs,'zoomStart':00,'zoomStop':20,'format':imf,'type':'truncate','threadCount':2}} | |
data = json.dumps(data) | |
request.add_data(data) | |
req = urllib2.urlopen(request) | |
print 'success' | |
except: | |
print 'removing gridset failed' | |
print data | |
pass | |
except: | |
print 'removing gridset failed' | |
pass | |
def seedLayer(layer): | |
print 'seeding: ' + layer | |
url = baseURL + layer + '.json' | |
request = urllib2.Request(url) | |
base64string = base64.encodestring('%s:%s' % (un, pw)).replace('\n', '') | |
request.add_header("Authorization", "Basic %s" % base64string) | |
request.add_header('Content-Type', 'application/json') | |
data = {'seedRequest':{'minX':[],'minY':[],'maxX':[],'maxY':[],'gridSetId':'Leaflet 3857','zoomStart':00,'zoomStop':18,'format':'image/png','type':'seed','threadCount':2}} | |
data = json.dumps(data) | |
request.add_data(data) | |
req = urllib2.urlopen(request) | |
#Do stuff for uploaded layers | |
truncateLayer('workspace:layer') | |
seedLayer('workspace:layer') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment