当前位置: 首页>>代码示例>>Python>>正文


Python XOSProcessor.process方法代码示例

本文整理汇总了Python中xosgenx.generator.XOSProcessor.process方法的典型用法代码示例。如果您正苦于以下问题:Python XOSProcessor.process方法的具体用法?Python XOSProcessor.process怎么用?Python XOSProcessor.process使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在xosgenx.generator.XOSProcessor的用法示例。


在下文中一共展示了XOSProcessor.process方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_pure_policies

# 需要导入模块: from xosgenx.generator import XOSProcessor [as 别名]
# 或者: from xosgenx.generator.XOSProcessor import process [as 别名]
    def test_pure_policies(self):
        xproto = """
policy my_policy < exists x:a=b >
"""

        proto = """
option my_policy = "policy:< exists x:a=b >";
"""
        target = XProtoTestHelpers.write_tmp_target(
            """
{{ policies }}
"""
        )

        args_xproto = XOSProcessorArgs()
        args_xproto.inputs = xproto
        args_xproto.target = target
        xproto_gen = XOSProcessor.process(args_xproto)

        args_proto = XOSProcessorArgs()
        args_proto.inputs = proto
        args_proto.target = target
        args_proto.rev = True
        proto_gen = XOSProcessor.process(args_proto)

        self.assertEqual(proto_gen, xproto_gen)
开发者ID:opencord,项目名称:xos,代码行数:28,代码来源:test_pure_proto.py

示例2: generate_service_models

# 需要导入模块: from xosgenx.generator import XOSProcessor [as 别名]
# 或者: from xosgenx.generator.XOSProcessor import process [as 别名]
def generate_service_models(service_dir, service_dest_dir, service_name):
    """
    Generate the django code starting from xProto for a given service.
    :param service_dir: string (path to the folder)
    :param service_name: string (name of the service)
    :return: void
    """
    sync_dir = os.path.join(service_dir, "xos/synchronizer/models")
    xprotos = find_xproto_in_folder(sync_dir)
    decls = find_decls_models(sync_dir)
    log.debug("Generating models for %s from files %s" % (service_name, ", ".join(xprotos)))
    out_dir = os.path.join(service_dest_dir, service_name)
    if not os.path.isdir(out_dir):
        os.mkdir(out_dir)

    args = XOSProcessorArgs(
        output=out_dir,
        files=xprotos,
        target="service.xtarget",
        write_to_file="target",
    )
    XOSProcessor.process(args)

    security_args = XOSProcessorArgs(
        output=out_dir,
        target="django-security.xtarget",
        dest_file="security.py",
        write_to_file="single",
        files=xprotos,
    )

    XOSProcessor.process(security_args)

    init_py_filename = os.path.join(out_dir, "__init__.py")
    if not os.path.exists(init_py_filename):
        open(init_py_filename, "w").write("# created by dynamicbuild")

    # copy over models.py files from the service
    if len(decls) > 0:
        for file in decls:
            fn = os.path.basename(file)
            src_fn = file
            dest_fn = os.path.join(out_dir, fn)
            log.debug("Copying models.py from %s to %s" % (src_fn, dest_fn))
            shutil.copyfile(src_fn, dest_fn)

    # copy existing migrations from the service, otherwise they won't be incremental
    src_dir = os.path.join(service_dir, "xos", "synchronizer", "migrations")
    if os.path.isdir(src_dir):
        dest_dir = os.path.join(out_dir, "migrations")
        if os.path.isdir(dest_dir):
            shutil.rmtree(dest_dir)  # empty the folder, we'll copy everything again
        shutil.copytree(src_dir, dest_dir)
开发者ID:opencord,项目名称:xos,代码行数:55,代码来源:main.py

示例3: _test_field_graph

# 需要导入模块: from xosgenx.generator import XOSProcessor [as 别名]
# 或者: from xosgenx.generator.XOSProcessor import process [as 别名]
    def _test_field_graph(self):
        xproto = """
message VRouterDevice (PlCoreBase){
     optional string name = 1 [help_text = "device friendly name", max_length = 20, null = True, db_index = False, blank = True, unique_with="openflow_id"];
     required string openflow_id = 2 [help_text = "device identifier in ONOS", max_length = 20, null = False, db_index = False, blank = False, unique_with="name"];
     required string config_key = 3 [default = "basic", max_length = 32, blank = False, help_text = "configuration key", null = False, db_index = False, unique_with="driver"];
     required string driver = 4 [help_text = "driver type", max_length = 32, null = False, db_index = False, blank = False, unique_with="vrouter_service"];
     required manytoone vrouter_service->VRouterService:devices = 5 [db_index = True, null = False, blank = False];
     required string A = 6 [unique_with="B"];
     required string B = 7 [unique_with="C"];
     required string C = 8 [unique_with="A"];
     required string D = 9;
     required string E = 10 [unique_with="F,G"];
     required string F = 11;
     required string G = 12;
}
"""
        target = XProtoTestHelpers.write_tmp_target(
            """
{{ xproto_field_graph_components(proto.messages.0.fields, proto.messages.0) }}
"""
        )

        args = XOSProcessorArgs(inputs=xproto, target=target)
        output = XOSProcessor.process(args)
        output = eval(output)
        self.assertIn({"A", "B", "C"}, output)
        self.assertIn({"openflow_id", "name"}, output)
        self.assertIn({"config_key", "vrouter_service", "driver"}, output)
        self.assertIn({"E", "F", "G"}, output)

        union = reduce(lambda acc, x: acc | x, output)
        self.assertNotIn("D", union)
开发者ID:opencord,项目名称:xos,代码行数:35,代码来源:test_field_graph.py

示例4: test_singularize

# 需要导入模块: from xosgenx.generator import XOSProcessor [as 别名]
# 或者: from xosgenx.generator.XOSProcessor import process [as 别名]
    def test_singularize(self):
        proto = """
  message TestSingularize {
      // The following field has an explicitly specified singular
      required int many = 1 [singular = "one"];
      // The following fields have automatically computed singulars
      required int sheep = 2;
      required int slices = 2;
      required int networks = 2;
      required int omf_friendlies = 2;
  }
"""

        target = XProtoTestHelpers.write_tmp_target(
            """
{% for m in proto.messages.0.fields -%}
{{ xproto_singularize(m) }},
{%- endfor %}
"""
        )
        args = XOSProcessorArgs()
        args.inputs = proto
        args.target = target
        output = XOSProcessor.process(args)
        self.assertEqual(
            "one,sheep,slice,network,omf_friendly", output.lstrip().rstrip().rstrip(",")
        )
开发者ID:opencord,项目名称:xos,代码行数:29,代码来源:test_target.py

示例5: test_pluralize

# 需要导入模块: from xosgenx.generator import XOSProcessor [as 别名]
# 或者: from xosgenx.generator.XOSProcessor import process [as 别名]
    def test_pluralize(self):
        proto = """
  message TestPluralize {
      // The following field has an explicitly specified plural
      required int anecdote = 1 [plural = "data"];
      // The following fields have automatically computed plurals
      required int sheep = 2;
      required int slice = 2;
      required int network = 2;
      required int omf_friendly = 2;
  }
"""

        target = XProtoTestHelpers.write_tmp_target(
            """
{% for m in proto.messages.0.fields -%}
{{ xproto_pluralize(m) }},
{%- endfor %}
"""
        )
        args = XOSProcessorArgs()
        args.inputs = proto
        args.target = target
        output = XOSProcessor.process(args)
        self.assertEqual(
            "data,sheep,slices,networks,omf_friendlies",
            output.lstrip().rstrip().rstrip(","),
        )
开发者ID:opencord,项目名称:xos,代码行数:30,代码来源:test_target.py

示例6: test_one_to_many_in_modeldef

# 需要导入模块: from xosgenx.generator import XOSProcessor [as 别名]
# 或者: from xosgenx.generator.XOSProcessor import process [as 别名]
    def test_one_to_many_in_modeldef(self):
        xproto = """
option app_label = "test";

message ServiceDependency {
    required manytoone provider_service->Service:provided_dependencies = 1;
    required manytoone subscriber_service->Service:subscribed_dependencies = 2;
}

message Service {
    required string name = 1;
}
"""

        args = XOSProcessorArgs()
        args.inputs = xproto
        args.target = "modeldefs.xtarget"
        output = XOSProcessor.process(args)
        # Service deps model
        self.assertIn(
            "{model: Service, type: manytoone, on_field: provider_service}", output
        )
        self.assertIn(
            "{model: Service, type: manytoone, on_field: provider_service}", output
        )

        # Service model
        self.assertIn(
            "{model: ServiceDependency, type: onetomany, on_field: provider_service}",
            output,
        )
        self.assertIn(
            "{model: ServiceDependency, type: onetomany, on_field: provider_service}",
            output,
        )
开发者ID:opencord,项目名称:xos,代码行数:37,代码来源:test_translator.py

示例7: test_basic_proto

# 需要导入模块: from xosgenx.generator import XOSProcessor [as 别名]
# 或者: from xosgenx.generator.XOSProcessor import process [as 别名]
    def test_basic_proto(self):
        xtarget = XProtoTestHelpers.write_tmp_target("{{ proto }}")

        xproto = """
message Person {
  required string name = 1;
  required int32 id = 2;  // Unique ID number for this person.
  optional string email = 3 [symphony = "da da da dum"];

  enum PhoneType {
    MOBILE = 0;
    HOME = 1;
    WORK = 2;
  }

  required  string number = 1;
  optional PhoneType type = 2;

  repeated PhoneNumber phones = 4;
}
"""
        args = XOSProcessorArgs()
        args.inputs = xproto
        args.target = xtarget
        output = XOSProcessor.process(args)
        self.assertIn("PhoneNumber", output)
开发者ID:opencord,项目名称:xos,代码行数:28,代码来源:test_parse.py

示例8: test_django_with_attic

# 需要导入模块: from xosgenx.generator import XOSProcessor [as 别名]
# 或者: from xosgenx.generator.XOSProcessor import process [as 别名]
    def test_django_with_attic(self):
        """
        [XOS-GenX] Generate django output from test.xproto
        """
        args = XOSProcessorArgs(
            files=[TEST_XPROTO, VROUTER_XPROTO],
            target="django.xtarget",
            attic=TEST_ATTICS,
            output=OUTPUT_DIR,
            dest_extension="py",
            write_to_file="model",
        )
        output = XOSProcessor.process(args)

        # xosmodel has custom header attic
        self.assertIn("from core.models.xosbase import *", output["XOSModel"])
        self.assertIn("class XOSModel_decl(XOSBase):", output["XOSModel"])

        # vrouter port use the default header
        self.assertIn("from core.models.xosbase import *", output["VRouterPort"])
        self.assertIn("class VRouterPort_decl(XOSBase):", output["VRouterPort"])

        # verify files
        xosmodel = OUTPUT_DIR + "/xosmodel.py"
        self.assertTrue(os.path.isfile(xosmodel))
        xmf = open(xosmodel).read()
        self.assertIn("from core.models.xosbase import *", xmf)
        self.assertIn("class XOSModel_decl(XOSBase):", xmf)

        vrouterport = OUTPUT_DIR + "/vrouterport.py"
        self.assertTrue(os.path.isfile(vrouterport))
        vrpf = open(vrouterport).read()
        self.assertIn("from core.models.xosbase import *", vrpf)
        self.assertIn("class VRouterPort_decl(XOSBase):", vrpf)
开发者ID:opencord,项目名称:xos,代码行数:36,代码来源:test_generator.py

示例9: test_instance_container

# 需要导入模块: from xosgenx.generator import XOSProcessor [as 别名]
# 或者: from xosgenx.generator.XOSProcessor import process [as 别名]
    def test_instance_container(self):
        xproto = """
    policy test_policy < (obj.isolation = "container" | obj.isolation = "container_vm" ) -> (obj.image.kind = "container") >
"""
        args = XOSProcessorArgs()
        args.inputs = xproto
        args.target = self.target

        output = XOSProcessor.process(args)

        obj = FakeObject()
        obj.isolation = "container"
        obj.kind = "not a container"

        exec(output)  # This loads the generated function, which should look like this:

        """
        def policy_output_validator(obj, ctx):
            i4 = (obj.isolation == 'container')
            i5 = (self.isolation == 'container_vm')
            i2 = (i4 or i5)
            i3 = (obj.image.kind == 'container')
            i1 = (i2 or i3)
            return i1
        """

        with self.assertRaises(Exception):
            policy_output_validator(obj, {})
开发者ID:opencord,项目名称:xos,代码行数:30,代码来源:test_xos_validation.py

示例10: test_bin

# 需要导入模块: from xosgenx.generator import XOSProcessor [as 别名]
# 或者: from xosgenx.generator.XOSProcessor import process [as 别名]
    def test_bin(self):
        xproto = """
    policy output < (ctx.is_admin = True | obj.empty = True) | False>
"""

        args = XOSProcessorArgs()
        args.inputs = xproto
        args.target = self.target

        output = XOSProcessor.process(args)
        exec(output)  # This loads the generated function, which should look like this:

        """
        def policy_output_validator(obj, ctx):
            i2 = (ctx.is_admin == True)
            i3 = (obj.empty == True)
            i1 = (i2 or i3)
            if (not i1):
                raise Exception('Necessary Failure')
        """

        obj = FakeObject()
        obj.empty = False

        ctx = FakeObject()
        ctx.is_admin = False

        with self.assertRaises(Exception):
            verdict = policy_output_validator(obj, ctx)
开发者ID:opencord,项目名称:xos,代码行数:31,代码来源:test_general_validation.py

示例11: test_controller_network_policy

# 需要导入模块: from xosgenx.generator import XOSProcessor [as 别名]
# 或者: from xosgenx.generator.XOSProcessor import process [as 别名]
    def test_controller_network_policy(self):
        xproto = """
    policy test_policy <
         ctx.user.is_admin
         | (exists Privilege:
             Privilege.accessor_id = ctx.user.id
             & Privilege.accessor_type = "User"
             & Privilege.object_type = "Slice"
             & Privilege.object_id = obj.owner.id)
         | (exists Privilege:
             Privilege.accessor_id = ctx.user.id
             & Privilege.accessor_type = "User"
             & Privilege.object_type = "Site"
             & Privilege.object_id = obj.owner.site.id
             & Privilege.permission = "role:admin") >
"""
        args = XOSProcessorArgs()
        args.inputs = xproto
        args.target = self.target

        output = XOSProcessor.process(args)
        exec(output)  # This loads the generated function, which should look like this:

        """
        def policy_output_enforcer(obj, ctx):
            i2 = ctx.user.is_admin
            i4 = Privilege.objects.filter(Q(accessor_id=ctx.user.id), Q(accessor_type='User'), Q(object_type='Slice'), Q(object_id=obj.owner.id))[0]
            i5 = Privilege.objects.filter(Q(accessor_id=ctx.user.id), Q(accessor_type='User'), Q(object_type='Site'), Q(object_id=obj.owner.site.id), Q(permission='role:admin'))[0]
            i3 = (i4 or i5)
            i1 = (i2 or i3)
            return i1
        """

        # FIXME: Test this policy by executing it
        self.assertTrue(policy_output_enforcer is not None)
开发者ID:opencord,项目名称:xos,代码行数:37,代码来源:test_xos_security.py

示例12: test_call_policy

# 需要导入模块: from xosgenx.generator import XOSProcessor [as 别名]
# 或者: from xosgenx.generator.XOSProcessor import process [as 别名]
    def test_call_policy(self):
        xproto = """
    policy sub_policy < ctx.user = obj.user >
    policy output < *sub_policy(child) >
"""

        args = XOSProcessorArgs(inputs=xproto, target=self.target)

        output = XOSProcessor.process(args)

        exec(
            output, globals()
        )  # This loads the generated function, which should look like this:

        """
        def policy_sub_policy_validator(obj, ctx):
            i1 = (ctx.user == obj.user)
            if (not i1):
                raise ValidationError('Necessary Failure')

        def policy_output_validator(obj, ctx):
            i1 = policy_sub_policy_validator(obj.child, ctx)
            if (not i1):
                raise ValidationError('Necessary Failure')
        """

        obj = FakeObject()
        obj.child = FakeObject()
        obj.child.user = 1

        ctx = FakeObject()
        ctx.user = 1

        with self.assertRaises(Exception):
            verdict = policy_output_enforcer(obj, ctx)
开发者ID:opencord,项目名称:xos,代码行数:37,代码来源:test_general_validation.py

示例13: test_field_numbers

# 需要导入模块: from xosgenx.generator import XOSProcessor [as 别名]
# 或者: from xosgenx.generator.XOSProcessor import process [as 别名]
    def test_field_numbers(self):
        args = XOSProcessorArgs(
            files=[REVERSEFIELDTEST_XPROTO], target=FIELDTEST_TARGET
        )
        output = XOSProcessor.process(args)

        def _assert_field(modelname, fieldname, id):
            self.assertIn("%s,%s,%s" % (modelname, fieldname, id), output)

        # rel_int1s_ids is the reverse link from RelatedToIntermediate1. It gets the related id with no offset, so it
        # will be assigned 1001. rel_leaf1as_ids inherits from Intermediate1, so its reverse links will all be offset
        # by 100
        _assert_field("Leaf1a", "rel_int1s_ids", 1001)
        _assert_field("Leaf1a", "rel_leaf1as_ids", 1101)

        # rel_int2s_ids is the reverse link from RelatedToIntermediate1. It gets the related id with no offset, so it
        # will be assigned 1001. rel_leaf1bs_ids inherits from Intermediate1, so its reverse links will all be offset
        # by 100
        _assert_field("Leaf1b", "rel_int1s_ids", 1001)
        _assert_field("Leaf1b", "rel_leaf1bs_ids", 1101)

        # There are no reverse numbers specified for Intermediate2 or Leaf2, so xproto will fall back to automatic
        # numbering starting at 1900.
        _assert_field("Leaf2", "rel_int2s_ids", 1900)
        _assert_field("Leaf2", "rel_leaf2s_ids", 1901)
开发者ID:opencord,项目名称:xos,代码行数:27,代码来源:test_generator.py

示例14: test_package_fqn

# 需要导入模块: from xosgenx.generator import XOSProcessor [as 别名]
# 或者: from xosgenx.generator.XOSProcessor import process [as 别名]
    def test_package_fqn(self):
        args = XOSProcessorArgs()
        target = XProtoTestHelpers.write_tmp_target(
            """
  {% for m in proto.messages %}
  {{ m.name }},{{ m.package }},{{ m.fqn }}
  {% endfor %}
"""
        )

        xproto = """
package xos.core;

message Port (PlCoreBase,ParameterMixin) {
     required manytoone network->Network:links = 1 [db_index = True, null = False, blank = False];
     optional manytoone instance->Instance:ports = 2 [db_index = True, null = True, blank = True];
     optional string ip = 3 [max_length = 39, content_type = "ip", blank = True, help_text = "Instance ip address", null = True, db_index = False];
     optional string port_id = 4 [help_text = "Neutron port id", max_length = 256, null = True, db_index = False, blank = True];
     optional string mac = 5 [help_text = "MAC address associated with this port", max_length = 256, null = True, db_index = False, blank = True];
     required bool xos_created = 6 [default = False, null = False, db_index = False, blank = True];
}
"""
        args = XOSProcessorArgs()
        args.inputs = xproto
        args.target = target

        output = XOSProcessor.process(args)

        self.assertIn("Port,xos.core,xos.core.Port", output)
开发者ID:opencord,项目名称:xos,代码行数:31,代码来源:test_package.py

示例15: test_bin

# 需要导入模块: from xosgenx.generator import XOSProcessor [as 别名]
# 或者: from xosgenx.generator.XOSProcessor import process [as 别名]
    def test_bin(self):
        xproto = """
    policy output < ctx.is_admin = True | obj.empty = True>
"""

        args = XOSProcessorArgs(inputs=xproto, target=self.target)
        output = XOSProcessor.process(args)
        exec(output, globals())  # This loads the generated function, which should look like this:

        """
        def output_security_check(obj, ctx):
            i2 = (ctx.is_admin == True)
            i3 = (obj.empty == True)
            i1 = (i2 or i3)
            return i1
        """

        obj = FakeObject()
        obj.empty = True

        ctx = FakeObject()
        ctx.is_admin = True

        verdict = output_security_check(obj, ctx)

        self.assertTrue(verdict)
开发者ID:opencord,项目名称:xos,代码行数:28,代码来源:test_general_security.py


注:本文中的xosgenx.generator.XOSProcessor.process方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。