Exemple #1
0
    def cmd(args):
        """Handle subcommand."""
        (module, _, _) = syslloader.load(args.modules, args.validations,
                                         args.root)
        out = str(module)

        (open(args.output, 'w') if args.output else sys.stdout).write(out)
Exemple #2
0
    def cmd(args):
        """Handle subcommand."""
        (module, _, _) = syslloader.load(args.modules, args.validations,
                                         args.root)
        out = module.SerializeToString()

        (open(args.output, 'wb') if args.output else sys.stdout).write(out)
Exemple #3
0
    def cmd(args):
        """Handle subcommand."""
        (module, _, _) = syslloader.load(
            args.modules, args.validations, args.root)
        out = str(module)

        (open(args.output, 'w') if args.output else sys.stdout).write(out)
Exemple #4
0
    def cmd(args):
        """Handle subcommand."""
        (module, _, _) = syslloader.load(
            args.modules, args.validations, args.root)
        out = module.SerializeToString()

        (open(args.output, 'wb') if args.output else sys.stdout).write(out)
Exemple #5
0
def main(input_args=sys.argv[1:]):
    argp = argparse.ArgumentParser(
        description='sysl relational Java Model exporter')

    argp.add_argument(
        '--root', '-r', default='.',
        help='sysl system root directory')
    argp.add_argument(
        '--out', '-o', default='.',
        help='Output root directory')
    argp.add_argument(
        '--entities',
        help=(
            'Commalist of entities that are expected to have corresponding '
            'output files generated.  This is for verification only.  It doesn’t '
            'determine which files are output.'))
    argp.add_argument(
        '--package',
        help=(
            'Package expected to be used for generated classes. This is for '
            'verification only.  It doesn’t determine the package used.'))
    argp.add_argument(
        '--serializers', default='*_*',
        help='Control output of XML and JSON serialization code.')
    argp.add_argument(
        'mode',
        choices=[
            'model',
            'facade',
            'view',
            'xsd',
            'swagger',
            'spring-rest-service',
        ],
        help='Code generation mode')
    argp.add_argument(
        'module',
        help='Module to load')
    argp.add_argument(
        'app',
        help='Application to export')
    argp.add_argument('--version', '-v',
                      help='show version number (semver.org standard)',
                      action='version', version='%(prog)s ' + __version__)

    args = argp.parse_args(input_args)

    out = os.path.normpath(args.out)

    (module, _, _) = syslloader.load(args.module, True, args.root)

    entities = set(args.entities.split(',')) if args.entities else None

    export(args.mode, module, args.app, out, args.package, entities,
           args.serializers.split(',') if args.serializers else [])

    if entities:
        raise RuntimeError('Some entities not output as expected: ' +
                           ', '.join(sorted(entities)))
Exemple #6
0
    def cmd(args):
        """Handle subcommand."""
        (module, deps, _) = syslloader.load(
            args.modules, args.validations, args.root)

        if not args.exclude and args.project:
            args.exclude = {args.project}

        integration_views(module, deps, args)
Exemple #7
0
    def integration_view_helper(self, modulename, d):
        (module, deps, _) = syslloader.load(modulename, True, '.')

        args = ap.Namespace(**d)

        if not args.exclude and args.project:
            args.exclude = {args.project}

        return syslints.integration_views(module, deps, args)
Exemple #8
0
    def integration_view_helper(self, modulename, d):
        (module, deps, _) = syslloader.load(modulename, True, '.')

        args = ap.Namespace(**d)

        if not args.exclude and args.project:
            args.exclude = {args.project}

        return syslints.integration_views(module, deps, args)
Exemple #9
0
    def genAndCompare(self, sysl_module, model, xsd_comparison_file):
        outpath = tempfile.gettempdir()
        package_prefix = 'io.sysl.test.data'
        (module, _, _) = syslloader.load(sysl_module, True, '.')

        reljam.export('xsd', module, model, outpath, package_prefix, {}, [])
        expected = os.path.join('.', xsd_comparison_file)
        real = os.path.join(outpath, model + ".xsd")
        self.assertTrue(filesAreIdentical(expected, real))
Exemple #10
0
def main(input_args=sys.argv[1:]):
    argp = argparse.ArgumentParser(
        description='sysl relational Java Model exporter')

    argp.add_argument('--root',
                      '-r',
                      default='.',
                      help='sysl system root directory')
    argp.add_argument('--out', '-o', default='.', help='Output root directory')
    argp.add_argument(
        '--entities',
        help=
        ('Commalist of entities that are expected to have corresponding '
         'output files generated.  This is for verification only.  It doesn’t '
         'determine which files are output.'))
    argp.add_argument(
        '--package',
        help=('Package expected to be used for generated classes. This is for '
              'verification only.  It doesn’t determine the package used.'))
    argp.add_argument(
        '--serializers',
        default='*_*',
        help='Control output of XML and JSON serialization code.')
    argp.add_argument('mode',
                      choices=[
                          'model',
                          'facade',
                          'view',
                          'xsd',
                          'swagger',
                          'spring-rest-service',
                      ],
                      help='Code generation mode')
    argp.add_argument('module', help='Module to load')
    argp.add_argument('app', help='Application to export')
    argp.add_argument('--version',
                      '-v',
                      help='show version number (semver.org standard)',
                      action='version',
                      version='%(prog)s ' + __version__)

    args = argp.parse_args(input_args)

    out = os.path.normpath(args.out)

    (module, _, _) = syslloader.load(args.module, True, args.root)

    entities = set(args.entities.split(',')) if args.entities else None

    export(args.mode, module, args.app, out, args.package, entities,
           args.serializers.split(',') if args.serializers else [])

    if entities:
        raise RuntimeError('Some entities not output as expected: ' +
                           ', '.join(sorted(entities)))
Exemple #11
0
    def cmd(args):
        """Handle subcommand."""
        out = cStringIO.StringIO()
        fmt = args.target + ' : {}\n'

        for module in args.modules:
            (_, _, modules) = syslloader.load(
                [module], args.validations, args.root)

            print >>out, fmt.format(
                module, ' '.join(m + '.sysl' for m in modules))

        (open(args.output, 'w') if args.output else sys.stdout).write(out.getvalue())
Exemple #12
0
    def cmd(args):
        """Handle subcommand."""
        out = cStringIO.StringIO()
        fmt = args.target + ' : {}\n'

        for module in args.modules:
            (_, _, modules) = syslloader.load([module], args.validations,
                                              args.root)

            print >> out, fmt.format(module,
                                     ' '.join(m + '.sysl' for m in modules))

        (open(args.output, 'w') if args.output else sys.stdout).write(
            out.getvalue())
Exemple #13
0
 def setUp(self):
     self.outpath = tempfile.gettempdir()
     self.package_prefix = 'io.sysl.test.data.petshop.'
     self.entities = {'Employee', 'Breed', 'Pet', 'EmployeeTendsPet'}
     (self.module, _, _) = syslloader.load(
         '/test/data/petshop/petshop', True, '.')
     # export has the side effect of removing entities from the list, so the member list
     # is not passed in
     reljam.export('model', self.module, 'PetShopModel', self.outpath,
                   self.package_prefix +
                   'model', {'Employee', 'Breed',
                             'Pet', 'EmployeeTendsPet'},
                   ['json_out', 'xml_out'])
     reljam.export('facade', self.module, 'PetShopFacade', self.outpath,
                   self.package_prefix + 'facade', {'Employee', 'Breed', 'Pet', 'EmployeeTendsPet'}, [])
Exemple #14
0
 def setUp(self):
     self.outpath = tempfile.gettempdir()
     self.package_prefix = 'io.sysl.test.data.petshop.'
     self.entities = {'Employee', 'Breed', 'Pet', 'EmployeeTendsPet'}
     (self.module, _, _) = syslloader.load('/test/data/petshop/petshop',
                                           True, '.')
     # export has the side effect of removing entities from the list, so the member list
     # is not passed in
     reljam.export('model', self.module, 'PetShopModel', self.outpath,
                   self.package_prefix + 'model',
                   {'Employee', 'Breed', 'Pet', 'EmployeeTendsPet'},
                   ['json_out', 'xml_out'])
     reljam.export('facade', self.module, 'PetShopFacade', self.outpath,
                   self.package_prefix + 'facade',
                   {'Employee', 'Breed', 'Pet', 'EmployeeTendsPet'}, [])
Exemple #15
0
    def test_at_prefixed_attr(self):

        try:
            (module, _, _) = syslloader.load(
                '/test/data/test_at_prefixed_attr', True, '.')

            val_set = set(
                elt.s for elt in module.apps['TestData :: Top Level App'].endpoints['Second Level App'].attrs['bracketed_array_attr'].a.elt)
            self.assertTrue({'bval1', 'bval2'} & val_set)
            self.assertTrue('sla_attribute string' ==
                            module.apps['TestData :: Top Level App'].endpoints['Second Level App'].attrs['sla_attribute'].s)

            self.assertTrue(
                'test id' == module.apps['TestData :: Top Level App'].types['TestType'].attrs['id'].s)

        except (IOError, Exception) as e:
            self.fail(traceback.format_exc())
Exemple #16
0
def main():
    argp = argparse.ArgumentParser(
        description='sysl relational JavaScript Model exporter')

    argp.add_argument('--root', '-r', default='.',
                      help='sysl system root directory')
    argp.add_argument('--out', '-o', required=True, help='Output file')
    argp.add_argument('--indent', type=int, help='Indentation level')
    argp.add_argument('module', help='Module to load')
    argp.add_argument('app', help='Application to export')
    args = argp.parse_args()

    out = os.path.normpath(args.out)

    (module, _, _) = syslloader.load(args.module, True, args.root)

    export_model_js(module, args.app, out, args.indent)
Exemple #17
0
def main():
    argp = argparse.ArgumentParser(
        description='sysl relational JavaScript Model exporter')

    argp.add_argument('--root',
                      '-r',
                      default='.',
                      help='sysl system root directory')
    argp.add_argument('--out', '-o', required=True, help='Output file')
    argp.add_argument('--indent', type=int, help='Indentation level')
    argp.add_argument('module', help='Module to load')
    argp.add_argument('app', help='Application to export')
    args = argp.parse_args()

    out = os.path.normpath(args.out)

    (module, _, _) = syslloader.load(args.module, True, args.root)

    export_model_js(module, args.app, out, args.indent)
Exemple #18
0
    def test_set_of(self):

        try:
            (module, _, _) = syslloader.load('/test/data/test_data', True, '.')

            d = {
                'project': 'TestData :: Data Views',
                'output': path.join(self.outpath, 'test_set_of-data.png'),
                'plantuml': '',
                'verbose': '',
                'filter': ''}
            args = ap.Namespace(**d)

            out = sysldata.dataviews(module, args)

            setof_re = re.compile(r'_\d+\s+\*-- "0\.\.\*"\s+_\d+')

            self.assertTrue(setof_re.search(out[0]))

        except (IOError, Exception) as e:
            self.fail(traceback.format_exc())
Exemple #19
0
    def cmd(args):
        """Handle subcommand."""
        (module, _, _) = syslloader.load(args.modules, args.validations,
                                         args.root)

        out = dataviews(module, args)
Exemple #20
0
    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."""
            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:
            if not args.endpoint:
                raise Exception(
                    'sysl sd requires either one specific endpoint, ' +
                    'e.g. --endpoint "ATM <- GetBalance", or an output ' +
                    'pattern with %(epname), e.g. -o "out/%(epname).svg".')
            out = sequence_diag(module, SequenceDiagParams(
                # -s builds list of lists (idkw).
                endpoints=args.endpoint,
                epfmt=diagutil.parse_fmt(args.endpoint_format),
                appfmt=diagutil.parse_fmt(args.app_format),
                activations=args.activations,
                title=args.title,
                blackboxes=args.blackbox))
            diagutil.output_plantuml(args, out)
Exemple #21
0
    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."""
            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:
            if not args.endpoint:
                raise Exception(
                    'sysl sd requires either one specific endpoint, ' +
                    'e.g. --endpoint "ATM <- GetBalance", or an output ' +
                    'pattern with %(epname), e.g. -o "out/%(epname).svg".')
            out = sequence_diag(
                module,
                SequenceDiagParams(
                    # -s builds list of lists (idkw).
                    endpoints=args.endpoint,
                    epfmt=diagutil.parse_fmt(args.endpoint_format),
                    appfmt=diagutil.parse_fmt(args.app_format),
                    activations=args.activations,
                    title=args.title,
                    blackboxes=args.blackbox))
            diagutil.output_plantuml(args, out)
Exemple #22
0
    def cmd(args):
        """Handle subcommand."""
        (module, _, _) = syslloader.load(
            args.modules, args.validations, args.root)

        out = dataviews(module, args)