#! /usr/bin/env python
#############################################################
#                                                           #
#   Author: Herve Menager                                   #
#   Organization:'Biological Software and Databases' Group, #
#                Institut Pasteur, Paris.                   #
#   Distributed under GPLv2 Licence. Please refer to the    #
#   COPYING.LIB document.                                   #
#                                                           #
#############################################################
import mb_cgi
from Mobyle.JobFacade import JobFacade
from Mobyle.Registry import registry

def process(self):
    j = JobFacade.getFromService(programUrl=self.request.getfirst('programName',None),workflowUrl=self.request.getfirst('workflowUrl',None))
    if self.request.getfirst('programName',None) and not ( registry.programsByUrl[ self.request.getfirst( 'programName' , None)].isExported() )\
        or self.request.getfirst('workflowUrl',None) and not ( registry.workflowsByUrl[ self.request.getfirst( 'workflowUrl' , None)].isExported() ): 
        return {'errormsg':"Unauthorized access to service %s, which \
                is restricted to local use." % self.serviceUrl}
    self.jsonMap = j.create(self.request)
    
if __name__ == "__main__":
    mb_cgi.JSONCGI(processFunction=process)