Skip to content
This repository has been archived by the owner on Apr 12, 2021. It is now read-only.

Commit

Permalink
Add some extra options to grapher (#482)
Browse files Browse the repository at this point in the history
* Add some extra options to grapher

Signed-off-by: Michael McCracken <mike.mccracken@canonical.com>

* fixes

Signed-off-by: Michael McCracken <mike.mccracken@canonical.com>

* lint
  • Loading branch information
mikemccracken authored and Adam Stokes committed Oct 12, 2016
1 parent d9bb6d5 commit 4a4c040
Showing 1 changed file with 46 additions and 9 deletions.
55 changes: 46 additions & 9 deletions tools/graph-controllers.py 100644 → 100755
@@ -1,15 +1,34 @@
#!python3
#!/usr/bin/env python

import argparse
import os
import re
from subprocess import PIPE, run

controllers_use_re = re.compile("(\s*)\S*\s*controllers\.use\('(.*)'\).render")
scope_re = re.compile("^(\s*)def (\w*)\(")

default_name_map = dict(spellpicker="Spell Selection",
bundlereadme="Spell Readme",
controllerselect="Controller Selection",
clouds="Cloud Selection",
bootstrapwait="Bootstrap Wait",
deploy="Charm List View & Charm Configuration",
deploystatus="Deploy Status",
steps="Actions List",
summary="Deploy Summary",
lxdsetup="LXD Configuration",
newcloud="New Cloud Credentials Setup",
START="Start")

def get_graph_string(filelist):
s = "[ summary ] -> [ END ]\n"

def get_graph_string(filelist, opts):
s = ""

if opts.mapnames:
name_map = default_name_map
else:
name_map = {}

for fn in filelist:
if os.path.basename(fn) == 'app.py':
Expand All @@ -32,9 +51,15 @@ def get_graph_string(filelist):
use_indent = len(use_match.group(1))
if use_indent <= scope_indent:
scopes.pop()
label = ""
if not opts.nolabels:
label = "{}:{}".format(scopes[0], i + 1)
s += "[ {} ] - {} -> [ {} ]\n".format(
src, "{}:{}".format(scopes[0], i + 1),
use_match.group(2))
name_map.get(src, src), label,
name_map.get(use_match.group(2),
use_match.group(2)))
if opts.condense:
return "\n".join(set(s.splitlines()))
return s


Expand All @@ -47,16 +72,28 @@ def get_files(kind):
return fl


def run_graph_easy(graph_string):
p = run("graph-easy --as boxart", input=graph_string, shell=True,
def run_graph_easy(graph_string, name, opts):
p = run("graph-easy --output=controllers-{}.{}".format(name,
opts.fmt),
input=graph_string, shell=True,
stdout=PIPE, stderr=PIPE, universal_newlines=True)
print(p.stderr)
return p.stdout


def parse_args():
p = argparse.ArgumentParser()
p.add_argument("--nolabels", action="store_true")
p.add_argument("--condense", action="store_true")
p.add_argument("--mapnames", action="store_true")
p.add_argument("--fmt", default='boxart')
return p.parse_args()


if __name__ == "__main__":
opts = parse_args()
for t in ['gui', 'tui']:
fl = get_files(t)
s = get_graph_string(fl + [os.path.abspath('conjureup/app.py')])
s = get_graph_string(fl + [os.path.abspath('conjureup/app.py')], opts)
print(t)
print(run_graph_easy(s))
print(run_graph_easy(s, t, opts))

0 comments on commit 4a4c040

Please sign in to comment.