Exemple #1
0
def source_info(req, service_name):

    service = Service(name=service_name)
    input_dict = {'cluster_id': req.zato.cluster_id, 'name': service_name}

    response = req.zato.client.invoke('zato.service.get-source-info',
                                      input_dict)

    if response.has_data:
        service.id = response.data.service_id

        source = b64decode(
            response.data.source) if response.data.source else ''
        if source:
            source_html = highlight(source, PythonLexer(stripnl=False),
                                    HtmlFormatter(linenos='table'))

            service.source_info = SourceCodeInfo()
            service.source_info.source = source
            service.source_info.source_html = source_html
            service.source_info.path = response.data.source_path
            service.source_info.hash = response.data.source_hash
            service.source_info.hash_method = response.data.source_hash_method
            service.source_info.server_name = response.data.server_name

    return_data = {
        'cluster_id': req.zato.cluster_id,
        'service': service,
    }

    return TemplateResponse(req, 'zato/service/source-info.html', return_data)
Exemple #2
0
    def _get_source_code_info(self, mod):
        """ Returns the source code of and the FS path to the given module.
        """
        # type: (Any) -> SourceInfo

        source_info = SourceCodeInfo()
        try:
            file_name = mod.__file__
            if file_name[-1] in ('c', 'o'):
                file_name = file_name[:-1]

            # We would have used inspect.getsource(mod) had it not been apparently using
            # cached copies of the source code
            source_info.source = open(file_name, 'rb').read()
            source_info.len_source = len(source_info.source)

            source_info.path = inspect.getsourcefile(mod)
            source_info.hash = sha256(source_info.source).hexdigest()
            source_info.hash_method = 'SHA-256'

        except IOError:
            if has_trace1:
                logger.log(TRACE1, 'Ignoring IOError, mod:`%s`, e:`%s`', mod,
                           format_exc())

        return source_info