def dataviews(module, args): """Generate a set of data views.""" out = [] parts = re.match(ur'^(.*?)(?:\s*<-\s*(.*?))?$', args.project) (appname, epname) = parts.groups() app = module.apps.get(appname) if epname is not None: endpts = [app.endpoints.get(epname)] else: endpts = app.endpoints.itervalues() out_fmt = diagutil.parse_fmt(args.output) for endpt in endpts: types = [] for stmt in endpt.stmt: appname = stmt.action.action for (name, typespec) in module.apps.get(appname).types.iteritems(): if typespec.WhichOneof('type') == 'tuple': types.append((appname, name, typespec)) args.output = out_fmt(appname=appname, epname=endpt.name, eplongname=endpt.long_name, **diagutil.attr_fmt_vars(app.attrs, endpt.attrs)) out.append(_generate_view(module, appname, types)) diagutil.output_plantuml(args, out[-1]) return out
def integration_views(module, deps, args): """Generate an integration view.""" def find_matching_apps(integrations): """Yield all apps that match the integrations.""" exclude = set(args.exclude) app_re = re.compile(r'^(?:{})(?: *::|$)'.format( '|'.join(integrations))) for ((app1, _), (app2, _)) in deps: if not ({app1, app2} & exclude): for app in [app1, app2]: if app_re.match(app) and 'human' not in syslx.patterns( module.apps[app].attrs): yield app def find_apps(matching_apps): """Yield all apps that are relevant to this view.""" exclude = set(args.exclude) for ((app1, _), (app2, _)) in deps: if not ({app1, app2} & exclude) and ({app1, app2} & matching_apps): for app in [app1, app2]: if 'human' not in syslx.patterns(module.apps[app].attrs): yield app out_fmt = diagutil.parse_fmt(args.output) # The "project" app that specifies the required view of the integrations app = module.apps[args.project] out = [] # Interate over each endpoint within the selected project for endpt in app.endpoints.itervalues(): # build the set of excluded items exclude_attr = endpt.attrs.get('exclude') exclude = set(e.s for e in exclude_attr.a.elt) if exclude_attr else set() integrations = [] # endpt.stmt's "action" will conatain the "apps" whose integration is to be drawn # each one of these will be placed into the "integrations" list for s in endpt.stmt: assert s.WhichOneof('stmt') == 'action', str(s) integrations.append(s.action.action) # include the requested "app" and all the apps upon which the requested "app" # depends in the app set matching_apps = set(find_matching_apps(integrations)) apps = set(find_apps(matching_apps)) - exclude # the meaning of integrations is overloaded in this context: above it means # it is the list of apps whose integration is to be drawn, here it means the # actual integrations between the apps that are in the "apps" set and are not excluded def find_integrations(): """Return all integrations between relevant apps.""" return {((app1, ep1), (app2, ep2)) for ((app1, ep1), (app2, ep2)) in deps if ({app1, app2} <= apps and not ({app1, app2} & exclude)) and not ({ep1, ep2} & {'.. * <- *'})} args.output = out_fmt(appname=args.project, epname=endpt.name, eplongname=endpt.long_name, **diagutil.attr_fmt_vars(app.attrs, endpt.attrs)) if args.filter and not re.match(args.filter, args.output): continue print args.project, matching_apps out.append( _generate_view(module, args, find_integrations(), matching_apps, app, apps, endpt)) diagutil.output_plantuml(args, out[-1]) return out
def output_sd(args, params): """Generate and output a sequence diagram.""" # pdb.set_trace() out = sequence_diag(module, params) diagutil.output_plantuml(args, out)
def cmd(args): """Handle subcommand.""" (module, _, _) = syslloader.load(args.modules, args.validations, args.root) def output_sd(args, params): """Generate and output a sequence diagram.""" # pdb.set_trace() out = sequence_diag(module, params) diagutil.output_plantuml(args, out) epfilters = os.getenv('SYSL_SD_FILTERS', '*').split(',') # TODO: Find a cleaner way to trigger multi-output. if '%(epname)' in args.output: out_fmt = diagutil.parse_fmt(args.output) for appname in args.app: app = module.apps[appname] bbs = [[e.s for e in bbox.a.elt] for bbox in syslx.View(app.attrs)['blackboxes'].a.elt] seqtitle = diagutil.parse_fmt( syslx.View(app.attrs)['seqtitle'].s or args.seqtitle) epfmt = diagutil.parse_fmt( syslx.View(app.attrs)['epfmt'].s or args.endpoint_format) appfmt = diagutil.parse_fmt( syslx.View(app.attrs)['appfmt'].s or args.app_format) for (name, endpt) in sorted(app.endpoints.iteritems(), key=lambda kv: kv[1].name): if not any( fnmatch.fnmatch(name, filt) for filt in epfilters): continue attrs = { u'@' + name: value.s for (name, value) in endpt.attrs.iteritems() } args.output = out_fmt(appname=appname, epname=name, eplongname=endpt.long_name, **attrs) if args.filter and not re.match(args.filter, args.output): continue bbs2 = [[ e.s for e in bbox.a.elt ] for bbox in syslx.View(endpt.attrs)['blackboxes'].a.elt] varrefs = diagutil.attr_fmt_vars( app.attrs, endpt.attrs, epname=endpt.name, eplongname=endpt.long_name) out = sequence_diag( module, SequenceDiagParams(endpoints=[ ' :: '.join(s.call.target.part) + ' <- ' + s.call.endpoint for s in endpt.stmt if s.WhichOneof('stmt') == 'call' ], epfmt=epfmt, appfmt=appfmt, activations=args.activations, title=seqtitle(**varrefs).replace( '\n', r'\n'), blackboxes=bbs + bbs2)) diagutil.output_plantuml(args, out) else: out = sequence_diag( module, SequenceDiagParams( endpoints=[i[0] for i in args.endpoint ], # -s builds list of lists (idkw). epfmt=diagutil.parse_fmt(args.endpoint_format), appfmt=diagutil.parse_fmt(args.app_format), activations=args.activations, title=args.title, blackboxes=args.blackboxes)) diagutil.output_plantuml(args, out)