<commit_before>"""uml output plugin
1) download plantuml.sourceforge.net/
2) Invoke with:
>pyang -f uml <file.yang> > <file.uml>
>java -jar plantuml.jar <file.uml>

3) result in img/module.png

For huge models Java might spit out memory exceptions, increase heap with e.g. -Xmx256m flag to java

"""
# TODO:
# -elements with same name at same level, we assume the path is unique
# cleanup choice and case with function

import optparse
import sys
import datetime
import re

from pyang import plugin
from pyang import util
from pyang import grammar
from pyang import error
from pyang import syntax
from pyang import statements
from pyang.error import err_add
from pyang.statements import find_target_node


def pyang_plugin_init():
    plugin.register_plugin(UMLPlugin())

class UMLPlugin(plugin.PyangPlugin):
    def add_opts(self, optparser):
        optlist = [
            optparse.make_option("--uml-classes-only",
                                 action="store_true",
                                 dest="uml_classes_only",
                                 default = False,
                                 help="Generate UML with classes only, no attributes "),
            optparse.make_option("--uml-split-pages",
                                 dest="uml_pages_layout",
                                 help="Generate UML output split into pages (separate .png files), NxN, example 2x2 "),
            optparse.make_option("--uml-output-directory",
                                 dest="uml_outputdir",
                                 help="Put generated <modulename>.png or <title>.png file(s) in OUTPUTDIR (default img/) "),
            optparse.make_option("--uml-title",
                                 dest="uml_title",
                                 help="Set the title of the generated UML, including the output file name"),
            optparse.make_option("--uml-header",
                                 dest="uml_header",
                                 help="Set the page header of the generated UML"),
            optparse.make_option("--uml-footer",
                                 dest="uml_footer",
                                 help="Set the page footer of the generated UML"),
            optparse.make_option("--uml-long-identifiers",
                                 action="store_true",
                                 dest="uml_longids",
                                 default =False,
                                 help="Use the full schema identifiers for UML class names."),
            optparse.make_option("--uml-inline-groupings",
                                 action="store_true",
                                 dest="uml_inline",
                                 default =False,
                                 help="Inline groupings where they are used."),
            optparse.make_option("--uml-inline-augments",
                                 action="store_true",
                                 dest="uml_inline_augments",
                                 default =False,
                                 help="Inline groupings where they are used."),
            optparse.make_option("--uml-description",
                                 action="store_true",
                                 dest="uml_descr",
                                 default =False,
                                 help="Include description of structural nodes in diagram."),
            optparse.make_option("--uml-no",
                                 dest="uml_no",
                                 default = "",
                                 help="Suppress parts of the diagram. \nValid suppress values are: module, uses, leafref, identity, identityref, typedef, import, annotation, circles, stereotypes. Annotations suppresses YANG constructs represented as annotations such as config statements for containers and module info. Module suppresses module box around the diagram and module information. \nExample --uml-no=circles,stereotypes,typedef,import"),
            optparse.make_option("--uml-truncate",
                                 dest="uml_truncate",
                                 default = "",
                                 help="Leafref attributes and augment elements can have long paths making the classes too wide. \nThis option will only show the tail of the path. \nExample --uml-truncate=augment,leafref"),
            optparse.make_option("--uml-max-enums",
                                 dest="uml_max_enums",
                                 default = "3",
                                 help="The maximum number of enumerated values being rendered"),

            optparse.make_option("--uml-filter",
                                 action="store_true",
                                 dest="uml_gen_filter_file",
                                 default = False,
                                 help="Generate filter file, comment out lines with '-' and use with option '--filter-file' to filter the UML diagram"),
            optparse.make_option("--uml-filter-file",
                                 dest="uml_filter_file",
                                 help="NOT IMPLEMENTED: Only paths in the filter file will be included in the diagram"),
            ]
        if hasattr(optparser, 'uml_opts'):
            g = optparser.uml_opts<commit_msg>uml: s/groupings/augmentations in aug opt help<commit_after>"""uml output plugin
1) download plantuml.sourceforge.net/
2) Invoke with:
>pyang -f uml <file.yang> > <file.uml>
>java -jar plantuml.jar <file.uml>

3) result in img/module.png

For huge models Java might spit out memory exceptions, increase heap with e.g. -Xmx256m flag to java

"""
# TODO:
# -elements with same name at same level, we assume the path is unique
# cleanup choice and case with function

import optparse
import sys
import datetime
import re

from pyang import plugin
from pyang import util
from pyang import grammar
from pyang import error
from pyang import syntax
from pyang import statements
from pyang.error import err_add
from pyang.statements import find_target_node


def pyang_plugin_init():
    plugin.register_plugin(UMLPlugin())

class UMLPlugin(plugin.PyangPlugin):
    def add_opts(self, optparser):
        optlist = [
            optparse.make_option("--uml-classes-only",
                                 action="store_true",
                                 dest="uml_classes_only",
                                 default = False,
                                 help="Generate UML with classes only, no attributes "),
            optparse.make_option("--uml-split-pages",
                                 dest="uml_pages_layout",
                                 help="Generate UML output split into pages (separate .png files), NxN, example 2x2 "),
            optparse.make_option("--uml-output-directory",
                                 dest="uml_outputdir",
                                 help="Put generated <modulename>.png or <title>.png file(s) in OUTPUTDIR (default img/) "),
            optparse.make_option("--uml-title",
                                 dest="uml_title",
                                 help="Set the title of the generated UML, including the output file name"),
            optparse.make_option("--uml-header",
                                 dest="uml_header",
                                 help="Set the page header of the generated UML"),
            optparse.make_option("--uml-footer",
                                 dest="uml_footer",
                                 help="Set the page footer of the generated UML"),
            optparse.make_option("--uml-long-identifiers",
                                 action="store_true",
                                 dest="uml_longids",
                                 default =False,
                                 help="Use the full schema identifiers for UML class names."),
            optparse.make_option("--uml-inline-groupings",
                                 action="store_true",
                                 dest="uml_inline",
                                 default =False,
                                 help="Inline groupings where they are used."),
            optparse.make_option("--uml-inline-augments",
                                 action="store_true",
                                 dest="uml_inline_augments",
                                 default =False,
                                 help="Inline augmentations where they are used."),
            optparse.make_option("--uml-description",
                                 action="store_true",
                                 dest="uml_descr",
                                 default =False,
                                 help="Include description of structural nodes in diagram."),
            optparse.make_option("--uml-no",
                                 dest="uml_no",
                                 default = "",
                                 help="Suppress parts of the diagram. \nValid suppress values are: module, uses, leafref, identity, identityref, typedef, import, annotation, circles, stereotypes. Annotations suppresses YANG constructs represented as annotations such as config statements for containers and module info. Module suppresses module box around the diagram and module information. \nExample --uml-no=circles,stereotypes,typedef,import"),
            optparse.make_option("--uml-truncate",
                                 dest="uml_truncate",
                                 default = "",
                                 help="Leafref attributes and augment elements can have long paths making the classes too wide. \nThis option will only show the tail of the path. \nExample --uml-truncate=augment,leafref"),
            optparse.make_option("--uml-max-enums",
                                 dest="uml_max_enums",
                                 default = "3",
                                 help="The maximum number of enumerated values being rendered"),

            optparse.make_option("--uml-filter",
                                 action="store_true",
                                 dest="uml_gen_filter_file",
                                 default = False,
                                 help="Generate filter file, comment out lines with '-' and use with option '--filter-file' to filter the UML diagram"),
            optparse.make_option("--uml-filter-file",
                                 dest="uml_filter_file",
                                 help="NOT IMPLEMENTED: Only paths in the filter file will be included in the diagram"),
            ]
        if hasattr(optparser, 'uml_opts'):
            g = optparser.uml_opts
{'fraction_non_alphanumeric': 0.08363636363636363, 'fraction_numerical': 0.0016783216783216783, 'mean_word_length': 1.4125056230319388, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 92, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4585276', 'n_tokens_mistral': 2511, 'n_tokens_neox': 2466, 'n_words': 728}