Skip to content

Commit

Permalink
Fix #132 - Changed debug function from shp2img to mapserv
Browse files Browse the repository at this point in the history
  • Loading branch information
samuellapointe committed Jul 15, 2015
1 parent 9f3eeb3 commit 42e4ec7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
17 changes: 7 additions & 10 deletions scribeui_pyramid/modules/maps/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,26 +513,23 @@ def save_map(self):
response['errors'].append("An error occured while saving '" + map_directory + filenames[filename] + "' file.")

if len(response['errors']) == 0:
debug_level = '1'
if map.type == 'Scribe':
scribe = self.request.registry.settings.get('scribe.python', '')
sub = subprocess.Popen('/usr/bin/python2.7 ' + scribe + ' -n ' + map.name + ' -i ' + map_directory + 'editor/ -o ' + map_directory + 'map/ -f ' + map_directory + 'config -d ' + debug_level, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
sub = subprocess.Popen('/usr/bin/python2.7 ' + scribe + ' -n ' + map.name + ' -i ' + map_directory + 'editor/ -o ' + map_directory + 'map/ -f ' + map_directory + 'config', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
logs = sub.stdout.read()
errors = sub.stderr.read()

if errors == '':
response['logs'] = '**Success**'
response['debug'] = logs
else:
response['logs'] = '**Errors**\n----------\n' + errors + '\n**Logs**\n----------\n' + logs
response['errors'].append('An error occured while running scribe.py')
else:
outputDirectory = map_directory + 'map/';
sub = subprocess.Popen('shp2img -m ' + outputDirectory + map.name + '.map -all_debug ' + debug_level + ' -o ' + outputDirectory + 'debug.png', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
logs = 'Mapserver logs (debug level ' + debug_level + ')\n'
logs += '------------------------------\n'
logs += sub.stderr.read().strip() + sub.stdout.read().strip()
response['debug'] = logs

sub = subprocess.Popen('mapserv -nh "QUERY_STRING=' + data['query'] + '"', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
try:
response['logs'] = sub.stdout.read().strip().decode('utf-8')
except:
# This error happens when the command returns a png, which is not utf8. It means everything worked fine.
response['logs'] = '**Success**'

(projection, extent) = MapManager.get_proj_extent_from_mapfile(mapfile)
Expand Down
11 changes: 9 additions & 2 deletions scribeui_pyramid/static/js/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,12 @@ ScribeUI.Map.prototype.save = function(){
var self = this;
this.updateComponents();

//Create the debugging query to be run with mapserv
queryString = self.WMSLayer.getFullRequestString().replace($SETTINGS.cgibin_url + "/mapserv?", '')
+ "&BBOX=" + self.WMSLayer.getTilesBounds().toBBOX()
+ '&WIDTH=' + self.WMSLayer.getImageSize().w
+ '&HEIGHT=' + self.WMSLayer.getImageSize().h;

var data = JSON.stringify({
map: this.map,
scales: this.scales,
Expand All @@ -219,7 +225,8 @@ ScribeUI.Map.prototype.save = function(){
fonts: this.fonts,
projections: this.projections,
readme: this.readme,
groups: this.groups
groups: this.groups,
query: queryString
})

$.ajax({
Expand Down Expand Up @@ -254,7 +261,7 @@ ScribeUI.Map.prototype.save = function(){
self.errorWidgets[i].editor.removeLineWidget(self.errorWidgets[i].widget);
}

self.handleDebug(response.debug, response.mapfile);
self.handleDebug(response.logs, response.mapfile);
}
})
}
Expand Down

0 comments on commit 42e4ec7

Please sign in to comment.