replace job extension by a friendly filename.
authorJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Thu, 11 Nov 2010 00:55:56 +0000 (00:55 +0000)
committerJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Thu, 11 Nov 2010 00:55:56 +0000 (00:55 +0000)
INSTALL
bin/djais/models.py
bin/djais/views.py
bin/jobrunner.py
structure.sql

diff --git a/INSTALL b/INSTALL
index 389d3bf48ee745c3cf82d7dce508b31b7b0c5252..df096db111e60a95ae065add431c5af26ba1e2b9 100644 (file)
--- a/INSTALL
+++ b/INSTALL
@@ -83,3 +83,4 @@ adduser www-data ais
 
 change apache umask in /etc/apache2/envvars from 022 to 002 so that new folders are group writables
 
+a2enmod headers rewrite
index 40eff377117ada856953d9aa1f0f55b92077e015..aa7f0b80e61b0b692f85366dbe4316fbd45a8365 100644 (file)
@@ -213,7 +213,7 @@ class Job(models.Model):
     start_time = models.DateTimeField(blank=True, null=True)
     finish_time = models.DateTimeField(blank=True, null=True)
     command = models.TextField()
-    extension = models.CharField(max_length=8)
+    friendly_filename = models.CharField(max_length=255)
     pid = models.IntegerField(blank=True, null=True)
     result = models.IntegerField(blank=True, null=True)
     archive_time = models.DateTimeField(blank=True, null=True)
index d9dce9d012e0ab33b62cfcc3b1c558d07ea0c286..25f9b17e136b6ca8132c44fa0eaabaaad63fd1ef 100644 (file)
@@ -5,6 +5,7 @@
 #Normalize 403 errors
 
 import os
+import os.path
 from datetime import *
 import re
 from time import time as get_timestamp
@@ -416,7 +417,7 @@ def vessel_history(request, strmmsi, format=None):
             job = Job()
             job.user = request.user
             job.command = command
-            job.extension = u'kmz'
+            job.friendly_filename = u'%s.kmz' % strmmsi
             job.save()
             #request.user.info('Request queued as job %s' % job.id)
             if not jobrunner.wakeup_daemon():
@@ -434,7 +435,7 @@ def vessel_history(request, strmmsi, format=None):
             job = Job()
             job.user = request.user
             job.command = command
-            job.extension = u'kmz'
+            job.friendly_filename = u'%s.kmz' % strmmsi
             job.save()
             #request.user.info('Request queued as job %s' % job.id)
             if not jobrunner.wakeup_daemon():
@@ -452,7 +453,7 @@ def vessel_history(request, strmmsi, format=None):
             job = Job()
             job.user = request.user
             job.command = command
-            job.extension = u'csv'
+            job.friendly_filename = u'%s.csv' % strmmsi
             job.save()
             #request.user.info('Request queued as job %s' % job.id)
             if not jobrunner.wakeup_daemon():
@@ -702,7 +703,8 @@ def job_get(request, jobid):
     if not job.archive_time:
         job.archive_time = datetime.utcnow()
         job.save()
-    return HttpResponseRedirect('/job_result/%s.%s' % (job.id, job.extension))
+    extension = os.path.splitext(job.friendly_filename)[-1]
+    return HttpResponseRedirect('/job_result/%s%s/%s' % (job.id, extension, job.friendly_filename))
 
 @http_authenticate(auth, 'ais')
 def users(request):
index 065808beed8f0f802037d88c781754f1c7189d7b..577fabc7b27bc85f350edc0971d709e94a5feca7 100755 (executable)
@@ -7,6 +7,7 @@ __all__ = [ \
 
 import sys
 import os
+import os.path
 import time
 import logging
 import subprocess
@@ -46,19 +47,20 @@ def runjob():
         logging.debug('Job %s is running: pid=%s', row[0], row[1])
         return 1
 
-    sqlexec(u'SELECT id, command, extension, user_id FROM job WHERE start_time IS NULL ORDER BY queue_time LIMIT 1')
+    sqlexec(u'SELECT id, command, friendly_filename, user_id FROM job WHERE start_time IS NULL ORDER BY queue_time LIMIT 1')
     row = get_common_cursor().fetchone()
     if row is None:
         logging.debug('Queue is empty.')
         return 0
 
-    jobid, command, extension, user_id = row
+    jobid, command, friendly_filename, user_id = row
     logging.info('Starting job %s: %s', jobid, command)
 
     sqlexec(u'UPDATE job SET start_time=now() WHERE id=%(jobid)s', {'jobid': jobid})
     dbcommit()
 
-    output = file('/var/lib/ais/jobs/'+unicode(jobid)+'.'+extension, 'wb')
+    extension = os.path.splitext(friendly_filename)[-1]
+    output = file('/var/lib/ais/jobs/'+unicode(jobid)+extension, 'wb')
     p = subprocess.Popen(command, stdout=output, shell=True)
     logging.debug('System process id = %s', p.pid)
     sqlexec(u'UPDATE job SET pid=' + unicode(p.pid) + ' WHERE id=%(jobid)s', {'jobid': jobid})
index edcead7da24f5933736a4f603d03a5de4bb8dcb3..3a7d03c507f5dfdb5d659278833c606500fe74b3 100644 (file)
@@ -113,10 +113,10 @@ CREATE TABLE job (
     start_time timestamp without time zone,
     finish_time timestamp without time zone,
     command text NOT NULL,
-    extension character varying(8) NOT NULL,
     pid integer,
     result integer,
-    archive_time timestamp without time zone
+    archive_time timestamp without time zone,
+    friendly_filename character varying(255)
 );