kopia lustrzana https://github.com/hholzgra/maposmatic/
Many improvements
rodzic
8a70335efe
commit
616b3b39d0
|
@ -13,6 +13,7 @@ def handler(signum, frame, pipe_write):
|
|||
f.write("end")
|
||||
|
||||
def render_job_process(job):
|
||||
|
||||
if job.administrative_city is None:
|
||||
bbox = ocitysmap.coords.BoundingBox(job.lat_upper_left,
|
||||
job.lon_upper_left,
|
||||
|
@ -34,9 +35,7 @@ def render_job_process(job):
|
|||
|
||||
def render_job(job):
|
||||
print 'Rendering "%s"...' % job.maptitle
|
||||
job.status = 1
|
||||
job.startofrendering_time = datetime.now()
|
||||
job.save()
|
||||
job.start_rendering()
|
||||
(pipe_read, pipe_write) = os.pipe()
|
||||
signal.signal(signal.SIGCHLD,
|
||||
lambda signal, frame: handler(signal, frame, pipe_write))
|
||||
|
@ -52,37 +51,23 @@ def render_job(job):
|
|||
os.kill(pid, signal.SIGTERM)
|
||||
time.sleep(2)
|
||||
os.kill(pid, signal.SIGKILL)
|
||||
job.resultmsg = "rendering took too long, killed"
|
||||
job.status = 2
|
||||
job.save()
|
||||
job.end_rendering("rendering took too long, killed")
|
||||
return
|
||||
finally:
|
||||
print "end of process %d" % pid
|
||||
(pid, status) = os.waitpid(pid, os.WNOHANG)
|
||||
resultmsg = "unknown error"
|
||||
if os.WIFEXITED(status):
|
||||
error_code = os.WEXITSTATUS(status)
|
||||
if error_code == 0:
|
||||
job.resultmsg = "ok"
|
||||
resultmsg = "ok"
|
||||
else:
|
||||
job.resultmsg = "rendering failed with %d" % error_code
|
||||
resultmsg = "rendering failed with %d" % error_code
|
||||
elif os.WIFSIGNALED(status):
|
||||
job.resultmsg = "rendering killed by signal %d" % os.WTERMSIG(status)
|
||||
job.status = 2
|
||||
job.save()
|
||||
resultmsg = "rendering killed by signal %d" % os.WTERMSIG(status)
|
||||
job.end_rendering(resultmsg)
|
||||
return
|
||||
|
||||
# hakipu (c) d.sespere
|
||||
# j = MapRenderingJob()
|
||||
# j.maptitle = "Carte de test"
|
||||
# j.lat_upper_left = 44.4883
|
||||
# j.lon_upper_left = -1.0901
|
||||
# j.lat_bottom_right = 44.4778
|
||||
# j.lon_bottom_right = -1.0637
|
||||
# j.status = 0
|
||||
# j.submitterip = "0.0.0.0"
|
||||
# j.index_queue_at_submission = 42
|
||||
# j.save()
|
||||
|
||||
if not os.path.isdir(RENDERING_RESULT_PATH):
|
||||
print "ERROR: please set RENDERING_RESULT_PATH ('%s') to an existing directory" % \
|
||||
RENDERING_RESULT_PATH
|
||||
|
|
|
@ -36,3 +36,16 @@ class MapRenderingJob(models.Model):
|
|||
return "%d-%s-%s" % (self.id,
|
||||
self.startofrendering_time.strftime("%Y-%m-%d-%H:%M"),
|
||||
self.maptitle_computized())
|
||||
|
||||
def start_rendering(self):
|
||||
self.status = 1
|
||||
self.startofrendering_time = datetime.now()
|
||||
self.save()
|
||||
|
||||
def end_rendering(self, resultmsg):
|
||||
self.status = 2
|
||||
self.endofrendering_time = datetime.now()
|
||||
self.resultmsg = resultmsg
|
||||
self.save()
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
from django import template
|
||||
from django.utils.html import conditional_escape
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
register = template.Library()
|
||||
|
||||
def job_status_to_str(value, arg, autoescape=None):
|
||||
|
||||
if autoescape:
|
||||
esc = conditional_escape
|
||||
else:
|
||||
esc = lambda x: x
|
||||
|
||||
if value == 0:
|
||||
result = "Waiting rendering"
|
||||
elif value == 1:
|
||||
result = "Rendering in progress"
|
||||
elif value == 2:
|
||||
if arg == "ok":
|
||||
result = "Rendering successfull"
|
||||
else:
|
||||
result = "Rendering failed, reason: <i>%s</i>" % esc(arg)
|
||||
else:
|
||||
result = ""
|
||||
|
||||
return mark_safe(result)
|
||||
|
||||
job_status_to_str.needs_autoescape = True
|
||||
|
||||
register.filter('job_status_to_str', job_status_to_str)
|
|
@ -45,3 +45,9 @@ def all_jobs(request):
|
|||
print jobs
|
||||
return render_to_response('maposmatic/all_jobs.html',
|
||||
{ 'jobs' : jobs })
|
||||
|
||||
def all_maps(request):
|
||||
return render_to_response('maposmatic/all_maps.html')
|
||||
|
||||
def about(request):
|
||||
return render_to_response('maposmatic/about.html')
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
{% extends "maposmatic/base.html" %}
|
||||
|
||||
{% load extratags %}
|
||||
|
||||
{% block menu-jobs %}
|
||||
class="activelink"
|
||||
{% endblock %}
|
||||
|
||||
{% block page %}
|
||||
|
||||
<p><b>Job list</b></p>
|
||||
|
@ -11,19 +17,7 @@
|
|||
<a href="/jobs/{{ job.id }}">{{ job.maptitle }}</a><br/>
|
||||
</td>
|
||||
<td>
|
||||
{% ifequal job.status 0 %}
|
||||
Waiting rendering
|
||||
{% endifequal %}
|
||||
{% ifequal job.status 1 %}
|
||||
Rendering in progress...
|
||||
{% endifequal %}
|
||||
{% ifequal job.status 2 %}
|
||||
{% ifequal job.resultmsg "ok" %}
|
||||
Rendering successfull
|
||||
{% else %}
|
||||
Rendering failed, reason: <i>{{ job.resultmsg }}</i>
|
||||
{% endifequal %}
|
||||
{% endifequal %}
|
||||
{{ job.status|job_status_to_str:job.resultmsg }}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
|
|
@ -7,7 +7,9 @@
|
|||
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
|
||||
<meta http-equiv="Content-Language" content="fr-fr" />
|
||||
<link rel="stylesheet" type="text/css" href="/smedia/style.css" media="screen" />
|
||||
{% block extrahead %}{% endblock %}
|
||||
<script language="JavaScript" type="text/javascript">
|
||||
{% block extrajs %}{% endblock %}
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
@ -15,9 +17,10 @@
|
|||
<h1>MapOSMatic</h1>
|
||||
<div id="menu">
|
||||
<ul id="nav">
|
||||
<li><a href="#">Accueil</a></li>
|
||||
<li><a href="#">Cartes</a></li>
|
||||
<li><a href="#">À propos</a></li>
|
||||
<li {% block menu-home %}{% endblock %}><a href="/">Home</a></li>
|
||||
<li {% block menu-jobs %}{% endblock %}><a href="/jobs">Status</a></li>
|
||||
<li {% block menu-maps %}{% endblock %}><a href="/maps">Maps</a></li>
|
||||
<li {% block menu-about %}{% endblock %}><a href="/about">About</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -28,14 +31,14 @@
|
|||
|
||||
<div id="left">
|
||||
<div class="box">
|
||||
<h2>Liens :</h2>
|
||||
<h2>Links :</h2>
|
||||
<ul>
|
||||
<li><a href="http://www.openstreetmap.org">OpenStreetMap</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="box">
|
||||
<div style="font-size: 0.8em;">Design par <a href="http://www.minimalistic-design.net">Minimalistic Design</a></div>
|
||||
<div style="font-size: 0.8em;">Design by <a href="http://www.minimalistic-design.net">Minimalistic Design</a></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
{% extends "maposmatic/base.html" %}
|
||||
|
||||
{% block extrahead %}
|
||||
<script language="JavaScript" type="text/javascript">
|
||||
{% block extrajs %}
|
||||
function generation_mode_switch(mode)
|
||||
{
|
||||
if (mode == 'bbox-mode')
|
||||
|
@ -15,7 +14,10 @@ function generation_mode_switch(mode)
|
|||
document.getElementById('bbox-mode').style.display = 'none';
|
||||
}
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
{% block menu-home %}
|
||||
class="activelink"
|
||||
{% endblock %}
|
||||
|
||||
{% block page %}
|
||||
|
|
|
@ -1,8 +1,64 @@
|
|||
{% extends "maposmatic/base.html" %}
|
||||
|
||||
{% block page %}
|
||||
<h1>MapOSMatic</h1>
|
||||
{% load extratags %}
|
||||
|
||||
{{ job.maptitle }}
|
||||
{% block menu-jobs %}
|
||||
class="activelink"
|
||||
{% endblock %}
|
||||
|
||||
{% block page %}
|
||||
<h1>Map Status</h1>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<td>Map title</td>
|
||||
<td>{{ job.maptitle }}</td>
|
||||
</tr>
|
||||
{% if job.administrative_city %}
|
||||
<tr>
|
||||
<td>Administrative city</td>
|
||||
<td>{{ job.administrative_city }}</td>
|
||||
</tr>
|
||||
{% else %}
|
||||
<tr>
|
||||
<td>Bounding-box coordinates</td>
|
||||
<td>
|
||||
<code>
|
||||
(lat={{ job.lat_upper_left }}, lon={{ job.lon_upper_left }}),
|
||||
(lat={{ job.lat_bottom_right }}, lon={{ job.lon_bottom_right }})
|
||||
</code>
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
<tr>
|
||||
<td>Status</td>
|
||||
<td>{{ job.status|job_status_to_str:job.resultmsg }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Submission time</td>
|
||||
<td>{{ job.submission_time|date:"l d M Y \a\t H:i" }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Start of rendering time</td>
|
||||
<td>
|
||||
{% ifequal job.status 0 %}
|
||||
Rendering not started yet
|
||||
{% else %}
|
||||
{{ job.startofrendering_time|date:"l d M Y \a\t H:i" }}
|
||||
{% endifequal %}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>End of rendering time</td>
|
||||
<td>
|
||||
{% ifequal job.status 2 %}
|
||||
{{ job.endofrendering_time|date:"l d M Y \a\t H:i" }}
|
||||
{% else %}
|
||||
Rendering not finished yet
|
||||
{% endifequal %}
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
|
||||
{% endblock %}
|
|
@ -14,4 +14,6 @@ urlpatterns = patterns('',
|
|||
{'document_root': settings.LOCAL_MEDIA_PATH}),
|
||||
(r'^jobs/(?P<job_id>\d+)$', maposmatic.views.job),
|
||||
(r'^jobs/$', maposmatic.views.all_jobs),
|
||||
(r'^maps/$', maposmatic.views.all_maps),
|
||||
(r'^about/$', maposmatic.views.about),
|
||||
)
|
||||
|
|
Ładowanie…
Reference in New Issue