INNER CODE UNIT · Python

generate_collection_index

mitre-attack/attack-stix-data · util/generate-collection-index.py:17

def generate_collection_index(name, description, root_url, collection_index_id, folders):
    """Generates a collection index from the input data and returns the index as a dictionary

    :param str name: The name of the collection index
    :param str description: The description of the collection index
    :param str root_url: The root URL where the collections can be found; collection file paths will be appended to this to create the collection URL
    :param str collection_index_id: the id to assign to the collection index
    :param list of str folders: List of folders containing the collection JSON files to include in the index; cannot be used with files argument; will only match collections that end with a version number
    """
    version_regex = re.compile("(\w+-)+(\d\.?)+(-beta)?.json")
    files = []
    for folder in folders:
        files += list(map(lambda fname: os.path.join(folder, fname), filter(lambda fname: version_regex.match(fname), os.listdir(folder))))

    index_created = None
    index_modified = None
    collections = {} # STIX ID -> collection object

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…