Example #1
0
def reverse_engineer(files, mode, graph, methods_list, prop_decorator,
                     version):
    """Pynsource CLI - Reverse engineer python source code into UML

    This command line tool doesn't actualy generate diagrams, but it does parse Python code into the 
    underlying 'pmodel' (parse model) that the Pynsource GUI graphic diagrammer uses.  Used for debugging.
    
    Examples of use:

        python3 ./src/pynsource-cli.py a.py b.py

        python3 ./src/pynsource-cli.py --graph src/common/command_pattern.py

        python3 ./src/pynsource-cli.py --methods-list src/common/*.py

    """

    if version:
        click.echo(f"Pynsource CLI version {APP_VERSION}")

    click.echo(f"Files to parse: {files}")
    # click.echo(graph)

    # Expansion of files seems to happen magically via bash - need to check with windows
    # But if running via pycharm wildcards are not expanded, so play it safe and glob
    globbed = []
    for param in files:
        files = glob.glob(param)
        globbed += files
    click.echo(globbed)

    if graph:
        displaymodel = DisplayModel(canvas=None)

    for f in globbed:
        pmodel, debuginfo = new_parser(f,
                                       options={
                                           "mode":
                                           mode,
                                           "TREAT_PROPERTY_DECORATOR_AS_PROP":
                                           prop_decorator
                                       })
        if pmodel.errors:
            print(pmodel.errors)

        if methods_list:  # Dump simple list of methods
            click.echo(dump_pmodel_methods(pmodel))

        else:  # Dump table of underlying pmodel
            assert f == pmodel.filename
            click.echo(f"Parse model for '{pmodel.filename}':")
            click.echo(dump_pmodel(pmodel))

            if graph:  # Dump table of display model
                displaymodel.build_graphmodel(pmodel)  # will append

    if graph:
        displaymodel.Dump(
            msg="Final display model Graph containing all parse models:")
Example #2
0
    def dump_parse_models(self):
        for pmodel in self.context.displaymodel.pmodels_i_have_seen:
            print("\nfilename", pmodel.filename)
            # print(dump_old_structure(pmodel))
            print(dump_pmodel(pmodel))

        # Also dump as list of methods
        print("")
        print("Simple List of Methods:")
        print("")
        for pmodel in self.context.displaymodel.pmodels_i_have_seen:
            print(dump_pmodel_methods(pmodel))
    def test_plantuml_sorted(self):
        # see also 'test_sorted_attributes' in src/tests/test_parse_bugs_incoming.py
        source = dedent("""
            class ParseMeTest:
                def __init__(self):
                    self.z = 1
                    self.a = 1
                def aa(self): pass
                def zz(self): pass
                def bb(self): pass
        """)
        options = None
        pmodel, plantuml = parse_source_gen_plantuml(source, options)

        t = dump_pmodel(pmodel)
        print(t)
    def test_sorted_attributes(self):
        # see also 'test_plantuml_sorted' in src/tests/test_parse_plantuml.py
        source_code = dedent("""
            class ParseMeTest:
                def __init__(self):
                    self.z = 1
                    self.a = 1
                def aa(self): pass
                def zz(self): pass
                def bb(self): pass
        """)
        pmodel, debuginfo = parse_source(source_code, options={"mode": 3})
        self.assertEqual(pmodel.errors, "")

        t = dump_pmodel(pmodel)
        print(t)
Example #5
0
def reverse_engineer(files, mode, graph, prop_decorator, version):
    """reverse engineer python source code"""

    if version:
        click.echo(f"Pynsource CLI version {APP_VERSION}")

    click.echo(f"Files to parse: {files}")
    # click.echo(graph)

    # Expansion of files seems to happen magically via bash - need to check with windows
    # But if running via pycharm wildcards are not expanded, so play it safe and glob
    globbed = []
    for param in files:
        files = glob.glob(param)
        globbed += files
    click.echo(globbed)

    if graph:
        displaymodel = DisplayModel(canvas=None)

    for f in globbed:
        pmodel, debuginfo = new_parser(f,
                                       options={
                                           "mode":
                                           mode,
                                           "TREAT_PROPERTY_DECORATOR_AS_PROP":
                                           prop_decorator
                                       })
        if pmodel.errors:
            print(pmodel.errors)
        click.echo(f"Parse model for '{f}':")
        click.echo(dump_pmodel(pmodel))

        if graph:
            displaymodel.build_graphmodel(pmodel)  # will append

    if graph:
        displaymodel.Dump(
            msg="Final display model Graph containing all parse models:")
Example #6
0
 def dump_parse_models(self):
     for pmodel in self.context.displaymodel.pmodels_i_have_seen:
         # print(dump_old_structure(pmodel))
         print(dump_pmodel(pmodel))