# Go to *run -> run configuration*
# Select *PyDev Django* and then press the New button
{gallery:include=1strunserver.png}
# Give a name to the run operation, for this example we chose GridClient
## Select *GridClient* as the project
## Select *GridClient/manage.py* file as the Main Module
{gallery:include=runserver.png}
# Select the *Arguments* tab
## In Program arguments type *runserver*
## By default Django will have the server on localhost:8000
### To change the port number, in Program Arguments give *runserver <port_number>*
### To change the host to an ip address, in Program Arguments give *runserver <server_ip>:<port_number>*
{gallery:include=runserverarguments.png}
# Select *Apply*, then select *Run*
# The console will show the following
{noformat}Validating models...
0 errors found
Django version 1.2.5, using settings 'GridClient.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
{noformat}
# go to http://localhost:8000/index/ on your browser
{gallery:include=Screen shot 2011-11-08 at 12.42.57 PM.png}
h3. Step 2: Implement Sync With Trust Fabric
# Edit *GridClient/thewebapp/views.py*
# Add imports, don't worry if eclipse complains about the imports
{code}from java.util import Properties
from java.io import FileInputStream
from gov.nih.nci.cagrid.common import Utils
from gov.nih.nci.cagrid.syncgts.bean import SyncDescription
from gov.nih.nci.cagrid.syncgts.core import SyncGTS
import time
import thread{code}
# Add public variables
{code}#for reading client.properties
CLIENT_PROPERTIES="conf/client.properties"
SYNC_DESCRIPTION="sync.description"
DEFAULT_DORIAN_SERVICE_URL_PROP = "default.dorian.service.url"
DEFAULT_INDEX_SERVICE_URL_PROP = "default.index.service.url";
props=None{code}
# Implement the readProperties method
{code}#load client.properties and return as properties object
def readProperties():
try:
tempprop=Properties()
tempprop.load(FileInputStream(CLIENT_PROPERTIES))
return tempprop
except Exception, e:
print "Exception while accessing %s %s" % (CLIENT_PROPERTIES,e){code}
# Implement the syncTrust method
{code}
#sync with the trust fabric, every 15 minutes
def syncTrust():
while(1):
print "Synchronizing Trust Fabric"
try:
description = Utils.deserializeDocument(props.getProperty(SYNC_DESCRIPTION), SyncDescription)
SyncGTS.getInstance().syncOnce(description)
print "Synchronizing Complete"
except Exception,e:
print "SyncGridTrust %s" % e
print "Failed to Synchronize"
time.sleep(15*60)
{code}
# load the client.properties file and start a thread to sync with the trust fabric
{code}#load client.properties into props
if(props==None):props=readProperties()