コード例 #1
0
ファイル: shell.py プロジェクト: vstitches/indico
    def __init__(self, host='localhost', port=8000, enable_ipv6=False):
        """
        Run an Indico WSGI ref server instance
        Very simple dispatching app
        """

        config = Config.getInstance()

        baseURL = config.getBaseURL()
        path = urlparse.urlparse(baseURL)[2].rstrip('/')

        def fake_app(environ, start_response):
            rpath = environ['PATH_INFO']
            m = re.match(r'^%s(.*)$' % path, rpath)
            if m:
                environ['PATH_INFO'] = m.group(1)
                environ['SCRIPT_NAME'] = path
                for msg in application(environ, start_response):
                    yield msg
            else:
                start_response("404 NOT FOUND", [])
                yield 'Not found'

        # if there is an IPv6 address, use it
        if enable_ipv6 and (socket.AF_INET6 in resolve_host(host, per_family=True)):
            server = ThreadedWSGIServerIPV6
        else:
            server = ThreadedWSGIServer

        self.httpd = make_server(host, port, fake_app,
                                 server_class=server,
                                 handler_class=WSGIRequestHandler)
        self.addr = self.httpd.socket.getsockname()[:2]
コード例 #2
0
ファイル: shell.py プロジェクト: sylvestre/indico
    def __init__(self, host='localhost', port=8000, enable_ipv6=False):
        """
        Run an Indico WSGI ref server instance
        Very simple dispatching app
        """

        config = Config.getInstance()

        baseURL = config.getBaseURL()
        path = urlparse.urlparse(baseURL)[2].rstrip('/')

        def fake_app(environ, start_response):
            rpath = environ['PATH_INFO']
            m = re.match(r'^%s(.*)$' % path, rpath)
            if m:
                environ['PATH_INFO'] = m.group(1)
                environ['SCRIPT_NAME'] = path
                for msg in application(environ, start_response):
                    yield msg
            else:
                start_response("404 NOT FOUND", [])
                yield 'Not found'

        # if there is an IPv6 address, use it
        if enable_ipv6 and (socket.AF_INET6 in resolve_host(host, per_family=True)):
            server = ThreadedWSGIServerIPV6
        else:
            server = ThreadedWSGIServer

        self.httpd = make_server(host, port, fake_app,
                                 server_class=server,
                                 handler_class=WSGIRequestHandler)
        self.addr = self.httpd.socket.getsockname()[:2]
コード例 #3
0
ファイル: fileConverter.py プロジェクト: sylvestre/indico
    def storeConvertedFile(requestIP, params):
        """ returns the path to the temp file used in the process
        so that it can be deleted at a later stage """

        # extract the server name from the url
        serverURL = Config.getInstance().getFileConverterServerURL()
        up = urlparse.urlparse(serverURL)
        ip_addrs = resolve_host(up[1])

        # check that the request comes from the conversion server
        if requestIP not in ip_addrs:
            return

        if params["status"] == '1':
            locator = {}
            # python dicts come with ' instead of " by default
            # using a json encoder on the server side would help...
            locator = loads(params["directory"].replace('\'', '"'))

            mat = CDSConvFileConverter._getMaterial(locator)
            if mat is not None:
                filePath = CDSConvFileConverter._saveFileToTemp(params)
                fileName = params["filename"]
                for resource in mat.getResourceList():
                    # if the pdf name is the same as any of the resources, and the material does not have a PDF yet:
                    if isinstance(
                            resource,
                            conference.LocalFile) and os.path.splitext(
                                resource.fileName)[0] == os.path.splitext(
                                    fileName)[0] and not mat.hasFile(fileName):
                        resource.setPDFConversionRequestDate(None)
                        f = conference.LocalFile()
                        f.setName(fileName)
                        f.setFileName(fileName)
                        f.setFilePath(filePath)
                        mat.addResource(f)
                return filePath
            else:
                #writeLog("Locator does not exist for file \"%s\": \n-locator:%s\nmessage:%s"%(params["filename"], params["directory"], params["error_message"]))
                pass
        else:
            #Here it should be processed the received error from the conversion server.
            #writeLog("Error converting file \"%s\": \n-locator:%s\nmessage:%s"%(params["filename"], params["directory"], params["error_message"]))
            pass
コード例 #4
0
ファイル: fileConverter.py プロジェクト: NIIF/indico
    def storeConvertedFile(requestIP, params):

        """ returns the path to the temp file used in the process
        so that it can be deleted at a later stage """

        # extract the server name from the url
        serverURL = Config.getInstance().getFileConverterServerURL()
        up = urlparse.urlparse(serverURL)
        ip_addrs = resolve_host(up[1])

        # check that the request comes from the conversion server
        if requestIP not in ip_addrs:
            return

        if params["status"] == '1':
            locator={}
            # python dicts come with ' instead of " by default
            # using a json encoder on the server side would help...
            locator = loads(params["directory"].replace('\'','"'))

            mat=CDSConvFileConverter._getMaterial(locator)
            if mat is not None:
                filePath = CDSConvFileConverter._saveFileToTemp( params )
                fileName = params["filename"]
                for resource in mat.getResourceList():
                    # if the pdf name is the same as any of the resources, and the material does not have a PDF yet:
                    if isinstance(resource, conference.LocalFile) and os.path.splitext(resource.fileName)[0] == os.path.splitext(fileName)[0] and not mat.hasFile(fileName):
                        resource.setPDFConversionRequestDate(None)
                        f = conference.LocalFile()
                        f.setName(fileName)
                        f.setFileName( fileName )
                        f.setFilePath( filePath )
                        mat.addResource( f )
                return filePath
            else:
                #writeLog("Locator does not exist for file \"%s\": \n-locator:%s\nmessage:%s"%(params["filename"], params["directory"], params["error_message"]))
                pass
        else:
            #Here it should be processed the received error from the conversion server.
            #writeLog("Error converting file \"%s\": \n-locator:%s\nmessage:%s"%(params["filename"], params["directory"], params["error_message"]))
            pass
コード例 #5
0
ファイル: fileConverter.py プロジェクト: dbourillot/indico
    def storeConvertedFile(requestIP, params):

        """ returns the path to the temp file used in the process
        so that it can be deleted at a later stage """

        # extract the server name from the url
        serverURL = Config.getInstance().getFileConverterServerURL()
        up = urlparse.urlparse(serverURL)
        ip_addrs = resolve_host(up[1])

        # check that the request comes from the conversion server
        if requestIP not in ip_addrs:
            logger.error('Request coming from {} not accepted (allowed IPs: {})'.format(requestIP, ip_addrs))
            return

        if params["status"] == '1':
            locator={}
            # python dicts come with ' instead of " by default
            # using a json encoder on the server side would help...
            locator = loads(params["directory"].replace('\'','"'))

            mat=CDSConvFileConverter._getMaterial(locator)
            if mat is not None:
                filePath = CDSConvFileConverter._saveFileToTemp( params )
                fileName = params["filename"]
                for resource in mat.getResourceList():
                    # if the pdf name is the same as any of the resources, and the material does not have a PDF yet:
                    if isinstance(resource, conference.LocalFile) and os.path.splitext(resource.fileName)[0] == os.path.splitext(fileName)[0] and not mat.hasFile(fileName):
                        resource.setPDFConversionRequestDate(None)
                        f = conference.LocalFile()
                        f.setName(fileName)
                        f.setFileName( fileName )
                        f.setFilePath( filePath )
                        mat.addResource( f )
                        logger.info("File '{}' stored in {}".format(f.getName(), locator))
                return filePath
            else:
                logger.error('Locator could not be resolved: {}'.format(params))
                pass
        else:
            logger.error('Error converting file: {}'.format(params))