Skip to content

TM1Py and Graphviz Integration? #501

Description

@harveyca307

Has anyone tried to integrate TM1PY with something like GraphViz? I was watching a demo the other day for QubeDocs and thought it would be cool to develop a data flow chart using TM1PY and possibly Graphviz. I started writing a script to see if I could access the rules, and so far it looks ok.

Here is what I have so far:

"""
Usage:
    gv <instance_name>
    gv -h
    gv --version

Arguments:
    <instance_name>     TM1 Instance Name

Options:
    -h                  Show this screen
    --version           Show version information
"""

from configparser import ConfigParser
from getpass import getpass
from time import time

import keyring
from TM1py.Exceptions import *
from TM1py.Services import TM1Service
from docopt import docopt
from keyring.backends import Windows

keyring.set_keyring(Windows.WinVaultKeyring())


def get_tm1_config():
    config = ConfigParser()
    config.read(r'config.ini')
    return config


def main(instance: str):
    config = get_tm1_config()
    user_name = config[instance]["user"]
    password = keyring.get_password(instance, user_name)
    if not password:
        password = getpass(f"Enter password for {user_name} on {instance}: ")
    keyring.set_password(instance, user_name, password)
    config[instance]["password"] = password
    try:
        with TM1Service(**config[instance]) as tm1:
            for cube in tm1.cubes.get_all_names_with_rules():
                if not cube.startswith('}'):
                    rul = tm1.cubes.get(cube_name=cube)
                    rules = rul.rules
                    for rule in rules:
                        if rule.__contains__('DB('):
                            print(rule)
                # TODO Graphviz integration
        return True
    except TM1pyRestException as t:
        print(t)
        return False


if __name__ == "__main__":
    cmd_args = docopt(__doc__, version='1.0.0')
    instance_name = cmd_args['<instance_name>']
    start_time = time()
    success = main(instance=instance_name)
    if success:
        end_time = time()
        print(f"Complete in {round(end_time - start_time, 2)} seconds.")
        pass
    else:
        pass

I got to this point and realized that there must be a better way. Thoughts??

BTW: Big thanks to @rclapp for turning me on to docopt.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions