Ejemplo n.º 1
0
def get_dict_doc_func(func):
    """Collect all doc string of func and return a beatiuful format of them
    in a dictionary format.

        Args:
            * func : name of function
        Returns:
            * Dictionary contains:
                synopsis : string (first line)
                author : string (identified by :author)
                rating : integer (identified by :rating)
                param_req : list of param (identified by :param requires)
                detail : detail description (identified by :detail)
                citation : list of citation in string (identified by :citation)
                limitation : string (identified by :limitation)
    """
    retval = {'synopsis': '',
              'author': '',
              'rating': '',
              'param_req': [],
              'detail': '',
              'citation': [],
              'limitation': ''}

    plugins_dict = dict([(pretty_function_name(p), p)
                         for p in FunctionProvider.plugins])
    if func not in plugins_dict.keys():
        return retval
    else:
        func = plugins_dict[func]

    author_tag = ':author'
    rating_tag = ':rating'
    param_req_tag = ':param requires'
    detail_tag = ':detail'
    citation_tag = ':citation'
    limitation_tag = ':limitation'

    if hasattr(func, '__doc__') and func.__doc__:
        doc_str = func.__doc__
        for line in doc_str.split('\n'):
            doc_line = remove_double_spaces(line)
            doc_line = doc_line.strip()

            if doc_line.startswith(author_tag):
                retval['author'] = doc_line[len(author_tag) + 1:]
            elif doc_line.startswith(rating_tag):
                retval['rating'] = int(doc_line[len(rating_tag) + 1:])
            elif doc_line.startswith(detail_tag):
                retval['detail'] = doc_line[len(detail_tag) + 1:]
            elif doc_line.startswith(limitation_tag):
                retval['limitation'] = doc_line[len(limitation_tag) + 1:]
            elif doc_line.startswith(param_req_tag):
                retval['param_req'].append(doc_line[len(param_req_tag) + 1:])
            elif doc_line.startswith(citation_tag):
                retval['citation'].append(doc_line[len(citation_tag) + 1:])

        retval['synopsis'] = remove_double_spaces(doc_str.split('\n')[0])

    return retval
Ejemplo n.º 2
0
def get_metadata(func):
    """Collect metadata for an impact function and return it as a dictionary.

    :param func: Name of function.

    :returns: A dictionary containing:
        * author : string (identified by :author)
        * synopsis : string (first line)
        * rating : integer (identified by :rating)
        * param_req : list of param (identified by :param requires)
        * detail : detail description (function properties)
        * citation : list of citation in string (function properties)
        * limitation : string (function properties)
    :rtype: dict
    """
    retval = OrderedDict()
    retval['unique_identifier'] = func

    plugins_dict = dict([(pretty_function_name(p), p)
                         for p in FunctionProvider.plugins])
    if func not in plugins_dict.keys():
        return None
    else:
        func = plugins_dict[func]

    author_tag = ':author'
    rating_tag = ':rating'

    # attributes
    synopsis = 'synopsis'
    actions = 'actions'
    # citations must be a list
    citations = 'citations'
    detailed_description = 'detailed_description'
    hazard_input = 'hazard_input'
    exposure_input = 'exposure_input'
    limitation = 'limitation'
    output = 'output'

    if hasattr(func, '__doc__') and func.__doc__:
        doc_str = func.__doc__
        for line in doc_str.split('\n'):
            doc_line = remove_double_spaces(line)
            doc_line = doc_line.strip()

            if doc_line.startswith(author_tag):
                retval['author'] = remove_double_spaces(
                    doc_line[len(author_tag) + 1:])
            elif doc_line.startswith(rating_tag):
                retval['rating'] = doc_line[len(rating_tag) + 1:]
    retval['title'] = get_function_title(func)

    if hasattr(func, synopsis):
        retval[synopsis] = func.synopsis
    if hasattr(func, actions):
        retval[actions] = func.actions
    if hasattr(func, citations):
        retval[citations] = func.citations
    if hasattr(func, detailed_description):
        retval[detailed_description] = func.detailed_description
    if hasattr(func, hazard_input):
        retval[hazard_input] = func.hazard_input
    if hasattr(func, exposure_input):
        retval[exposure_input] = func.exposure_input
    if hasattr(func, output):
        retval[output] = func.output
    if hasattr(func, limitation):
        retval[limitation] = func.limitation
    return retval
Ejemplo n.º 3
0
def get_documentation(func):
    """Collect documentaion of a impact function and return it as a dictionary

        Args:
            * func : name of function
        Returns:
            * Dictionary contains:
                author : string (identified by :author)
                synopsis : string (first line)
                rating : integer (identified by :rating)
                param_req : list of param (identified by :param requires)
                detail : detail description (function properties)
                citation : list of citation in string (function properties)
                limitation : string (function properties)
    """
    retval = OrderedDict()
    retval['unique_identifier'] = func

    plugins_dict = dict([(pretty_function_name(p), p)
                         for p in FunctionProvider.plugins])
    if func not in plugins_dict.keys():
        return None
    else:
        func = plugins_dict[func]

    author_tag = ':author'
    rating_tag = ':rating'

    # attributes
    synopsis = 'synopsis'
    actions = 'actions'
    # citations must be a list
    citations = 'citations'
    detailed_description = 'detailed_description'
    hazard_input = 'hazard_input'
    exposure_input = 'exposure_input'
    limitation = 'limitation'
    output = 'output'

    if hasattr(func, '__doc__') and func.__doc__:
        doc_str = func.__doc__
        for line in doc_str.split('\n'):
            doc_line = remove_double_spaces(line)
            doc_line = doc_line.strip()

            if doc_line.startswith(author_tag):
                retval['author'] = remove_double_spaces(
                    doc_line[len(author_tag) + 1:])
            elif doc_line.startswith(rating_tag):
                retval['rating'] = doc_line[len(rating_tag) + 1:]
    retval['title'] = get_function_title(func)

    if hasattr(func, synopsis):
        retval[synopsis] = func.synopsis
    if hasattr(func, actions):
        retval[actions] = func.actions
    if hasattr(func, citations):
        retval[citations] = func.citations
    if hasattr(func, detailed_description):
        retval[detailed_description] = func.detailed_description
    if hasattr(func, hazard_input):
        retval[hazard_input] = func.hazard_input
    if hasattr(func, exposure_input):
        retval[exposure_input] = func.exposure_input
    if hasattr(func, output):
        retval[output] = func.output
    if hasattr(func, limitation):
        retval[limitation] = func.limitation
    return retval
Ejemplo n.º 4
0
def get_documentation(func):
    """Collect documentaion of a impact function and return it as a dictionary

        Args:
            * func : name of function
        Returns:
            * Dictionary contains:
                author : string (identified by :author)
                synopsis : string (first line)
                rating : integer (identified by :rating)
                param_req : list of param (identified by :param requires)
                detail : detail description (function properties)
                citation : list of citation in string (function properties)
                limitation : string (function properties)
    """
    retval = {'unique_identifier': func}

    plugins_dict = dict([(pretty_function_name(p), p)
                         for p in FunctionProvider.plugins])
    if func not in plugins_dict.keys():
        return None
    else:
        func = plugins_dict[func]

    author_tag = ':author'
    rating_tag = ':rating'

    # attributes
    synopsis = 'synopsis'
    actions = 'actions'
    # citations must be a list
    citations = 'citations'
    detailed_description = 'detailed_description'
    permissible_hazard_input = 'permissible_hazard_input'
    permissible_exposure_input = 'permissible_exposure_input'
    limitation = 'limitation'

    if hasattr(func, '__doc__') and func.__doc__:
        doc_str = func.__doc__
        for line in doc_str.split('\n'):
            doc_line = remove_double_spaces(line)
            doc_line = doc_line.strip()

            if doc_line.startswith(author_tag):
                retval['author'] = remove_double_spaces(
                    doc_line[len(author_tag) + 1:])
            elif doc_line.startswith(rating_tag):
                retval['rating'] = doc_line[len(rating_tag) + 1:]
    retval['title'] = get_function_title(func)

    if hasattr(func, synopsis):
        retval[synopsis] = func.synopsis
    if hasattr(func, actions):
        retval[actions] = func.actions
    if hasattr(func, citations):
        retval[citations] = func.citations
    if hasattr(func, detailed_description):
        retval[detailed_description] = func.detailed_description
    if hasattr(func, permissible_hazard_input):
        retval[permissible_hazard_input] = func.permissible_hazard_input
    if hasattr(func, permissible_exposure_input):
        retval[permissible_exposure_input] = func.permissible_exposure_input
    if hasattr(func, limitation):
        retval[limitation] = func.limitation
    return retval