from datetime import datetime
from string import *
import re
-from gaworkflow.frontend.exp_track.models import DataRun
-from gaworkflow.frontend.fctracker.models import FlowCell, Library
+from gaworkflow.frontend import settings
+from gaworkflow.frontend.exp_track.models import FlowCell, DataRun
+from gaworkflow.frontend.fctracker.models import Library
from django.core.exceptions import ObjectDoesNotExist
from django.core.mail import send_mail, mail_admins
user = 'none'
pswd = ''
UpdatedStatus = 'unknown'
- ClIP = 'unknown'
- granted = False
fcid = 'none'
runfolder = 'unknown'
-
+ ClIP = request.META['REMOTE_ADDR']
+ granted = False
+
+ if request.has_key('user'):
+ user = request['user']
+
+ #Check access permission
+ if (user == 'rami' and settings.ALLOWED_IPS.has_key(ClIP)): granted = True
+ if not granted: return HttpResponse("access denied.")
+
+
+ # ~~~~~~Parameters for the job ~~~~
if request.has_key('fcid'):
fcid = request['fcid']
else:
runfolder = request['runf']
else:
return HttpResponse('missing runf')
-
- if request.has_key('user'):
- user = request['user']
- else:
- return HttpResponse('access denied')
-
- #TO DO: pswd decode etc..
- #if request.has_key('pswd'):
- # pswd = request['pswd']
- #else:
- # return HttpResponse('access denied')
- ClIP = request.META['REMOTE_ADDR']
- #Check permission to update
- if (user == 'rami' and (ClIP == '171.65.76.167' or ClIP == '171.65.76.51' or ClIP == '171.65.76.194' or (ClIP == '74.51.115.100' or ClIP == '64.89.97.100'))): ## or ClIP == '127.0.0.1')):
- granted = True
+ if request.has_key('updst'):
+ UpdatedStatus = request['updst']
+ else:
+ return HttpResponse('missing status')
- if granted:
- if request.has_key('updst'):
- UpdatedStatus = request['updst']
- else:
- return HttpResponse('missing status')
-
- # Update Data Run status in DB
- # Try get rec. If not found return 'entry not found + <fcid><runfolder>', if found try update and return updated
- try:
- rec = DataRun.objects.get(run_folder=runfolder)
- rec.run_status = UpdatedStatus
-
- #if there's a message update that too
- mytimestamp = datetime.now().__str__()
- mytimestamp = re.sub(pattern=":[^:]*$",repl="",string=mytimestamp)
- if request.has_key('msg'):
- rec.run_note += ", "+request['msg']+" ("+mytimestamp+")"
- else :
- if UpdatedStatus == '1':
- rec.run_note = "Started ("+mytimestamp+")"
-
- rec.save()
- output = "updated to:'"+DataRun.RUN_STATUS_CHOICES[int(UpdatedStatus)][1].__str__()+"'"
- except ObjectDoesNotExist:
- output = "entry not found: "+fcid+", "+runfolder
- else:
- output ="access denied.. u: "+user+", ClIP: "+ClIP
+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ # Update Data Run status in DB
+ # Try get rec. If not found return 'entry not found + <fcid><runfolder>', if found try update and return updated
+ try:
+ rec = DataRun.objects.get(run_folder=runfolder)
+ rec.run_status = UpdatedStatus
+
+ #if there's a message update that too
+ mytimestamp = datetime.now().__str__()
+ mytimestamp = re.sub(pattern=":[^:]*$",repl="",string=mytimestamp)
+ if request.has_key('msg'):
+ rec.run_note += ", "+request['msg']+" ("+mytimestamp+")"
+ else :
+ if UpdatedStatus == '1':
+ rec.run_note = "Started ("+mytimestamp+")"
+
+ rec.save()
+ output = "Hello "+settings.ALLOWED_IPS[ClIP]+". Updated to:'"+DataRun.RUN_STATUS_CHOICES[int(UpdatedStatus)][1].__str__()+"'"
+ except ObjectDoesNotExist:
+ output = "entry not found: "+fcid+", "+runfolder
+
#Notify researcher by email
# Doesn't work
return HttpResponse(output)
def generateConfile(fcid):
+ granted = False
+ ClIP = request.META['REMOTE_ADDR']
+ if (settings.ALLOWED_IPS.has_key(ClIP)): granted = True
+
+ if not granted: return HttpResponse("access denied.")
+
cnfgfile = 'READ_LENGTH 25\n'
cnfgfile += 'ANALYSIS eland\n'
cnfgfile += 'GENOME_FILE all_chr.fa\n'
return cnfgfile
def getConfile(request):
+ granted = False
+ ClIP = request.META['REMOTE_ADDR']
+ if (settings.ALLOWED_IPS.has_key(ClIP)): granted = True
+
+ if not granted: return HttpResponse("access denied.")
+
fcid = 'none'
cnfgfile = ''
runfolder = 'unknown'
return HttpResponse(cnfgfile)
def getLaneLibs(request):
+ granted = False
+ ClIP = request.META['REMOTE_ADDR']
+ if (settings.ALLOWED_IPS.has_key(ClIP)): granted = True
+
+ if not granted: return HttpResponse("access denied.")
+
fcid = 'none'
outputfile = ''
if request.has_key('fcid'):
else: day = day.__str__()
mydate = year+month+day
outputfile = '<?xml version="1.0" ?>'
- outputfile += '\n<SolexaResult Date="'+mydate+'" Flowcell="'+fcid+'">'
- outputfile += '\n<Lane Index="1" Name="'+rec.lane_1_library.library_name+'" Library="'+rec.lane_1_library.library_id+'" Genome="'+rec.lane_1_library.library_species.use_genome_build+'"/>'
- outputfile += '\n<Lane Index="2" Name="'+rec.lane_2_library.library_name+'" Library="'+rec.lane_2_library.library_id+'" Genome="'+rec.lane_2_library.library_species.use_genome_build+'"/>'
- outputfile += '\n<Lane Index="3" Name="'+rec.lane_3_library.library_name+'" Library="'+rec.lane_3_library.library_id+'" Genome="'+rec.lane_3_library.library_species.use_genome_build+'"/>'
- outputfile += '\n<Lane Index="4" Name="'+rec.lane_4_library.library_name+'" Library="'+rec.lane_4_library.library_id+'" Genome="'+rec.lane_4_library.library_species.use_genome_build+'"/>'
- outputfile += '\n<Lane Index="5" Name="'+rec.lane_5_library.library_name+'" Library="'+rec.lane_5_library.library_id+'" Genome="'+rec.lane_5_library.library_species.use_genome_build+'"/>'
- outputfile += '\n<Lane Index="6" Name="'+rec.lane_6_library.library_name+'" Library="'+rec.lane_6_library.library_id+'" Genome="'+rec.lane_6_library.library_species.use_genome_build+'"/>'
- outputfile += '\n<Lane Index="7" Name="'+rec.lane_7_library.library_name+'" Library="'+rec.lane_7_library.library_id+'" Genome="'+rec.lane_7_library.library_species.use_genome_build+'"/>'
- outputfile += '\n<Lane Index="8" Name="'+rec.lane_8_library.library_name+'" Library="'+rec.lane_8_library.library_id+'" Genome="'+rec.lane_8_library.library_species.use_genome_build+'"/>'
+ outputfile += '\n<SolexaResult Date="'+mydate+'" Flowcell="'+fcid+'" Client="'+settings.ALLOWED_IPS[ClIP]+'">'
+ outputfile += '\n<Lane Index="1" Name="'+rec.lane_1_library.library_name+'" Library="'+rec.lane_1_library.library_id+'" Genome="'+rec.lane_1_library.library_species.use_genome_build+'" PrimerName="" PrimerSeq=""/>'
+ outputfile += '\n<Lane Index="2" Name="'+rec.lane_2_library.library_name+'" Library="'+rec.lane_2_library.library_id+'" Genome="'+rec.lane_2_library.library_species.use_genome_build+'" PrimerName="" PrimerSeq=""/>'
+ outputfile += '\n<Lane Index="3" Name="'+rec.lane_3_library.library_name+'" Library="'+rec.lane_3_library.library_id+'" Genome="'+rec.lane_3_library.library_species.use_genome_build+'" PrimerName="" PrimerSeq=""/>'
+ outputfile += '\n<Lane Index="4" Name="'+rec.lane_4_library.library_name+'" Library="'+rec.lane_4_library.library_id+'" Genome="'+rec.lane_4_library.library_species.use_genome_build+'" PrimerName="" PrimerSeq=""/>'
+ outputfile += '\n<Lane Index="5" Name="'+rec.lane_5_library.library_name+'" Library="'+rec.lane_5_library.library_id+'" Genome="'+rec.lane_5_library.library_species.use_genome_build+'" PrimerName="" PrimerSeq=""/>'
+ outputfile += '\n<Lane Index="6" Name="'+rec.lane_6_library.library_name+'" Library="'+rec.lane_6_library.library_id+'" Genome="'+rec.lane_6_library.library_species.use_genome_build+'" PrimerName="" PrimerSeq=""/>'
+ outputfile += '\n<Lane Index="7" Name="'+rec.lane_7_library.library_name+'" Library="'+rec.lane_7_library.library_id+'" Genome="'+rec.lane_7_library.library_species.use_genome_build+'" PrimerName="" PrimerSeq=""/>'
+ outputfile += '\n<Lane Index="8" Name="'+rec.lane_8_library.library_name+'" Library="'+rec.lane_8_library.library_id+'" Genome="'+rec.lane_8_library.library_species.use_genome_build+'" PrimerName="" PrimerSeq=""/>'
outputfile += '\n</SolexaResult>'
except ObjectDoesNotExist:
outputfile = 'Flowcell entry not found for: '+fcid