Skip to content

Commit

Permalink
[AppServer] Made the paremeters of the Django application server more…
Browse files Browse the repository at this point in the history
… generic.
da115115 committed Sep 1, 2012
1 parent 774fe98 commit ed91306
Showing 4 changed files with 53 additions and 10 deletions.
20 changes: 18 additions & 2 deletions README
Original file line number Diff line number Diff line change
@@ -94,9 +94,25 @@ Then, as usual:
* To run the local binary version:
./opentrep/opentrep -b
* To run the installed version (the first following line must be done once
per session):
per session; replace lib by lib64 if on a 64-bit platform):
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${INSTALL_BASEDIR}/opentrep-stable/lib
${INSTALL_BASEDIR}/opentrep-stable/bin/opentrep -b

Denis Arnaud (December 2011)
Running the Django-based application server:
--------------------------------------------
# Replace lib by lib64 if on a 64-bit platform:
export TREP_LIB=${INSTALL_BASEDIR}/opentrep-stable/lib
# Optional:
export TREP_TRAVELDB=/tmp/opentrep/traveldb
export TREP_LOG=django_trep.log
cd appserver/django/trep
# The first time, the database must be initialised:
#./manage.py syncdb localhost:8000
./manage.py runserver localhost:8000
# Check that everything went fine with, for instance:
midori http://localhost:8000/trep/api/"rio de janero reykyavik sna francicso"


--
Denis Arnaud (September 2012)

1 change: 1 addition & 0 deletions appserver/django/trep/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/django_trep.log
39 changes: 32 additions & 7 deletions appserver/django/trep/api/handlers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
from sys import path
from os import environ
from piston.handler import BaseHandler
import simplejson

# Retrieve the database connection parameters
from django.db import connection
db_name = connection.settings_dict['NAME']
db_user = connection.settings_dict['USER']
db_password = connection.settings_dict['PASSWORD']
db_host = connection.settings_dict['HOST']
db_port = connection.settings_dict['PORT']

# Retrieve the OpenTrep parameters
traveldb_path = environ.get ('TREP_TRAVELDB', failobj='/tmp/opentrep/traveldb')
trep_log_path = environ.get ('TREP_LOG', failobj='django_trep.log')
trep_lib_dir = environ.get ('TREP_LIB', failobj='/usr/lib')

# The first time a request is handled by Django (after that latter has been
# started), the OpenTrep library has to be initialised
path.append (trep_lib_dir)

import libpyopentrep
openTrepLibrary = libpyopentrep.OpenTrepSearcher()
openTrepLibrary.init (traveldb_path, trep_log_path,
db_user, db_password, db_host, db_port, db_name)

#
class TrepHandler (BaseHandler):
@@ -26,14 +47,18 @@ def read (self, request, queryURL=None):
# the following parameters would be kept: LAX
if queryURL: query = queryURL

# Call the underlying Trep library, which returns JSON-formatted list of POR
jsonMessage = "SFO"
#message = json.loads (jsonMessage)
message = jsonMessage
#
query = str(query)

# Call the underlying Trep library, which returns JSON-formatted
# list of POR (points of reference).
opentrepOutputFormat = 'J'
jsonMessage = openTrepLibrary.search (opentrepOutputFormat, query)
response = simplejson.loads (jsonMessage)

# print 'Received reply ', request, '[', jsonMessage, ']'
#TESTING --- UNCOMMENT FOR NORMAL OPERATION ---
#return message
print 'Message: ', message
#TESTING --- UNCOMMENT FOR NORMAL OPERATION ---
return response
#return response
#REMOVE OR COMMENT FOR NORMAL OPERATION ---

3 changes: 2 additions & 1 deletion appserver/django/trep/api/urls.py
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ def __init__ (self, handler, authentication = None):

#
urlpatterns = patterns ('',
(r'^(?:/(?P<queryURL>))$', display_resource),
(r'^(?:q=(?P<queryURL>.+))?$', display_resource),
(r'^(?P<queryURL>.+)$', display_resource),
)

0 comments on commit ed91306

Please sign in to comment.