diff --git a/.gitignore b/.gitignore index 0235885..5730b2a 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,6 @@ **/*.egg-info/ **/.DS_Store .vscode -.coverage \ No newline at end of file +.coverage +target +**/proto \ No newline at end of file diff --git a/README.adoc b/README.adoc index 641a20c..dd3b0cd 100644 --- a/README.adoc +++ b/README.adoc @@ -13,17 +13,46 @@ image:https://raw.githubusercontent.com/eclipse-uprotocol/uprotocol-spec/main/up == Getting Started +=== Prerequisites +Before proceeding with the setup of this project, ensure that the following prerequisites are met: + +* Maven is installed and configured in your environment. You can verify this by running the following command in your terminal: +[,bash] +---- +mvn -version +---- +If Maven is properly installed, you should see information about the Maven version and configuration. + === Importing the sdk - -Setup SDK local repository and install + +To set up SDK, follow the steps below: + +. Clone the code from the GitHub repository: ++ +[source] +---- +git clone https://github.com/eclipse-uprotocol/uprotocol-python.git +---- + +. Execute the `pull_and_compile_protos.py` script using the following command: ++ +[source] +---- +python pull_and_compile_protos.py +---- +This script automates the following tasks: + +1. **Cloning and Compilation of Protos:** + Clones the `up-core-api` protos from the specified repository URL, compiles them, and generates Python protofiles in the protos folder. + +. Install up-python ++ [source] ---- -$ git clone https://github.com/eclipse-uprotocol/uprotocol-python.git -$ cd uprotocol-python -$ pip install . +python -m pip install . ---- -*This will install the uprotocol-python, making its classes and modules available for import in your python code.* +*This will install the up-python, making its classes and modules available for import in your python code.* === Using The Sdk diff --git a/pull_and_compile_protos.py b/pull_and_compile_protos.py new file mode 100644 index 0000000..c5cce2c --- /dev/null +++ b/pull_and_compile_protos.py @@ -0,0 +1,124 @@ +# ------------------------------------------------------------------------- +# +# Copyright (c) 2023 General Motors GTO LLC +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# SPDX-FileType: SOURCE +# SPDX-FileCopyrightText: 2023 General Motors GTO LLC +# SPDX-License-Identifier: Apache-2.0 +# +# ------------------------------------------------------------------------- + +import os +import re +import shutil +import subprocess + +import git +from git import Repo + +REPO_URL = "https://github.com/eclipse-uprotocol/up-core-api.git" +PROTO_REPO_DIR = "target" +TAG_NAME = "uprotocol-core-api-1.5.6" +PROTO_OUTPUT_DIR = os.path.join("uprotocol", "proto") + + +def clone_or_pull(repo_url, PROTO_REPO_DIR): + try: + repo = Repo.clone_from(repo_url, PROTO_REPO_DIR) + print(f"Repository cloned successfully from {repo_url} to {PROTO_REPO_DIR}") + # Checkout the specific tag + repo.git.checkout(TAG_NAME) + except git.exc.GitCommandError as clone_error: + try: + git_pull_command = ["git", "pull", "origin", TAG_NAME] + subprocess.run(git_pull_command, cwd=PROTO_REPO_DIR, check=True) + print("Git pull successful after clone failure.") + except subprocess.CalledProcessError as pull_error: + print(f"Error during Git pull: {pull_error}") + + +def execute_maven_command(project_dir, command): + try: + with subprocess.Popen(command, cwd=os.path.join(os.getcwd(), project_dir), shell=True, stdout=subprocess.PIPE, + stderr=subprocess.PIPE, text=True) as process: + stdout, stderr = process.communicate() + print(stdout) + + if process.returncode != 0: + print(f"Error: {stderr}") + else: + print("Maven command executed successfully.") + src_directory = os.path.join(os.getcwd(), project_dir, "target", "generated-sources", "protobuf", + "python") + # if not os.path.exists(PROTO_OUTPUT_DIR): + # os.makedirs(PROTO_OUTPUT_DIR) + + shutil.copytree(src_directory, PROTO_OUTPUT_DIR, dirs_exist_ok=True) + process_python_protofiles(PROTO_OUTPUT_DIR) + except Exception as e: + print(f"Error executing Maven command: {e}") + + +def replace_in_file(file_path, search_pattern, replace_pattern): + with open(file_path, 'r') as file: + file_content = file.read() + + updated_content = re.sub(search_pattern, replace_pattern, file_content) + + with open(file_path, 'w') as file: + file.write(updated_content) + + +def process_python_protofiles(directory): + for root, dirs, files in os.walk(directory): + create_init_py(root) + for file in files: + if file.endswith('.py'): + file_path = os.path.join(root, file) + replace_in_file(file_path, r'import uri_pb2', 'import uprotocol.proto.uri_pb2') + replace_in_file(file_path, r'import uuid_pb2', 'import uprotocol.proto.uuid_pb2') + replace_in_file(file_path, r'import uprotocol_options_pb2', + 'import uprotocol.proto.uprotocol_options_pb2') + replace_in_file(file_path, r'import uattributes_pb2', 'import uprotocol.proto.uattributes_pb2') + replace_in_file(file_path, r'import upayload_pb2', 'import uprotocol.proto.upayload_pb2') + replace_in_file(file_path, r'import ustatus_pb2', 'import uprotocol.proto.ustatus_pb2') + replace_in_file(file_path, r'import upayload_pb2', 'import uprotocol.proto.upayload_pb2') + replace_in_file(file_path, r'import umessage_pb2', 'import uprotocol.proto.umessage_pb2') + + +def create_init_py(directory): + init_file_path = os.path.join(directory, "__init__.py") + + # Check if the file already exists + if not os.path.exists(init_file_path): + # Create an empty __init__.py file + with open(init_file_path, "w"): + pass + + +def execute(): + clone_or_pull(REPO_URL, PROTO_REPO_DIR) + + # Execute mvn compile-python + maven_command = "mvn protobuf:compile-python" + execute_maven_command(PROTO_REPO_DIR, maven_command) + + +if __name__ == "__main__": + execute() diff --git a/setup.cfg b/setup.cfg index 1240532..7748c20 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,11 +1,11 @@ [metadata] -name = uprotocol-python +name = up-python author = Neelam Kushwah author_email = neelam.kushwah@gm.com description = UProtocol Python SDK -version = 1 +version = 1.5.2 keywords = - uprotocol + up python [options] @@ -14,6 +14,5 @@ packages = find: zip_safe = False install_requires = cloudevents -; googleapis-common-protos>=1.56.4 diff --git a/tests/test_cloudevent/test_datamodel/test_ucloudevent.py b/tests/test_cloudevent/test_datamodel/test_ucloudevent.py index 3f67d55..3d34001 100644 --- a/tests/test_cloudevent/test_datamodel/test_ucloudevent.py +++ b/tests/test_cloudevent/test_datamodel/test_ucloudevent.py @@ -26,7 +26,7 @@ from uprotocol.proto.uri_pb2 import UUri, UEntity, UResource from uprotocol.uri.serializer.longuriserializer import LongUriSerializer -from uprotocol.proto.cloudevents_pb2 import CloudEvent +from uprotocol.cloudevent.cloudevents_pb2 import CloudEvent from uprotocol.proto.uattributes_pb2 import UMessageType, UPriority from uprotocol.cloudevent.factory.cloudeventfactory import CloudEventFactory from uprotocol.proto.ustatus_pb2 import UCode @@ -77,81 +77,81 @@ class TestUCloudEvent(unittest.TestCase): def test_extract_source_from_cloudevent(self): cloud_event = build_cloud_event_for_test() source = UCloudEvent.get_source(cloud_event) - self.assertEquals("/body.access//door.front_left#Door", source) + self.assertEqual("/body.access//door.front_left#Door", source) def test_extract_sink_from_cloudevent_when_sink_exists(self): sink = "//bo.cloud/petapp/1/rpc.response" cloud_event = build_cloud_event_for_test() cloud_event.__setitem__("sink", sink) - self.assertEquals(sink, UCloudEvent.get_sink(cloud_event)) + self.assertEqual(sink, UCloudEvent.get_sink(cloud_event)) def test_extract_sink_from_cloudevent_when_sink_does_not_exist(self): cloud_event = build_cloud_event_for_test() - self.assertEquals(None, UCloudEvent.get_sink(cloud_event)) + self.assertEqual(None, UCloudEvent.get_sink(cloud_event)) def test_extract_requestId_from_cloudevent_when_requestId_exists(self): cloud_event = build_cloud_event_for_test() cloud_event.__setitem__("reqid", "somereqid") - self.assertEquals("somereqid", UCloudEvent.get_request_id(cloud_event)) + self.assertEqual("somereqid", UCloudEvent.get_request_id(cloud_event)) def test_extract_requestId_from_cloudevent_when_requestId_does_not_exist(self): cloud_event = build_cloud_event_for_test() - self.assertEquals(None, UCloudEvent.get_request_id(cloud_event)) + self.assertEqual(None, UCloudEvent.get_request_id(cloud_event)) def test_extract_requestId_from_cloudevent_when_requestId_value_is_null(self): cloud_event = build_cloud_event_for_test() cloud_event.__setitem__("reqid", None) - self.assertEquals(None, UCloudEvent.get_request_id(cloud_event)) + self.assertEqual(None, UCloudEvent.get_request_id(cloud_event)) def test_extract_hash_from_cloudevent_when_hash_exists(self): cloud_event = build_cloud_event_for_test() - self.assertEquals("somehash", UCloudEvent.get_hash(cloud_event)) + self.assertEqual("somehash", UCloudEvent.get_hash(cloud_event)) def test_extract_hash_from_cloudevent_when_hash_does_not_exist(self): cloud_event = build_cloud_event_for_test() cloud_event.__delitem__("hash") - self.assertEquals(None, UCloudEvent.get_hash(cloud_event)) + self.assertEqual(None, UCloudEvent.get_hash(cloud_event)) def test_extract_priority_from_cloudevent_when_priority_exists(self): cloud_event = build_cloud_event_for_test() - self.assertEquals(UPriority.Name(UPriority.UPRIORITY_CS1), UCloudEvent.get_priority(cloud_event)) + self.assertEqual(UPriority.Name(UPriority.UPRIORITY_CS1), UCloudEvent.get_priority(cloud_event)) def test_extract_priority_from_cloudevent_when_priority_does_not_exist(self): cloud_event = build_cloud_event_for_test() cloud_event.__delitem__("priority") - self.assertEquals(None, UCloudEvent.get_priority(cloud_event)) + self.assertEqual(None, UCloudEvent.get_priority(cloud_event)) def test_extract_ttl_from_cloudevent_when_ttl_exists(self): cloud_event = build_cloud_event_for_test() - self.assertEquals(3, UCloudEvent.get_ttl(cloud_event)) + self.assertEqual(3, UCloudEvent.get_ttl(cloud_event)) def test_extract_ttl_from_cloudevent_when_ttl_does_not_exists(self): cloud_event = build_cloud_event_for_test() cloud_event.__delitem__("ttl") - self.assertEquals(None, UCloudEvent.get_ttl(cloud_event)) + self.assertEqual(None, UCloudEvent.get_ttl(cloud_event)) def test_extract_token_from_cloudevent_when_token_exists(self): cloud_event = build_cloud_event_for_test() - self.assertEquals("someOAuthToken", UCloudEvent.get_token(cloud_event)) + self.assertEqual("someOAuthToken", UCloudEvent.get_token(cloud_event)) def test_extract_token_from_cloudevent_when_token_does_not_exists(self): cloud_event = build_cloud_event_for_test() cloud_event.__delitem__("token") - self.assertEquals(None, UCloudEvent.get_token(cloud_event)) + self.assertEqual(None, UCloudEvent.get_token(cloud_event)) def test_cloudevent_has_platform_error_when_platform_error_exists(self): cloud_event = build_cloud_event_for_test() cloud_event.__setitem__("commstatus", UCode.ABORTED) - self.assertEquals(10, UCloudEvent.get_communication_status(cloud_event)) + self.assertEqual(10, UCloudEvent.get_communication_status(cloud_event)) def test_cloudevent_has_platform_error_when_platform_error_does_not_exist(self): cloud_event = build_cloud_event_for_test() - self.assertEquals(UCode.OK, UCloudEvent.get_communication_status(cloud_event)) + self.assertEqual(UCode.OK, UCloudEvent.get_communication_status(cloud_event)) def test_extract_platform_error_from_cloudevent_when_platform_error_exists_in_wrong_format(self): cloud_event = build_cloud_event_for_test() cloud_event.__setitem__("commstatus", "boom") - self.assertEquals(UCode.OK, UCloudEvent.get_communication_status(cloud_event)) + self.assertEqual(UCode.OK, UCloudEvent.get_communication_status(cloud_event)) def test_cloudevent_is_not_expired_cd_when_no_ttl_configured(self): cloud_event = build_cloud_event_for_test() @@ -210,13 +210,15 @@ def test_from_message_with_valid_message(self): self.assertIsNotNone(u_message) cloud_event1 = UCloudEvent.fromMessage(u_message) self.assertIsNotNone(cloud_event1) - self.assertEquals(cloud_event, cloud_event1) - self.assertEquals(cloud_event.get_data(), cloud_event1.get_data()) - self.assertEquals(UCloudEvent.get_source(cloud_event), UCloudEvent.get_source(cloud_event1)) - self.assertEquals(UCloudEvent.get_specversion(cloud_event), UCloudEvent.get_specversion(cloud_event1)) - self.assertEquals(UCloudEvent.get_priority(cloud_event), UCloudEvent.get_priority(cloud_event1)) - self.assertEquals(UCloudEvent.get_id(cloud_event), UCloudEvent.get_id(cloud_event1)) - self.assertEquals(UCloudEvent.get_type(cloud_event), UCloudEvent.get_type(cloud_event1)) + cloud_event.__delitem__("time") + cloud_event1.__delitem__("time") + self.assertEqual(cloud_event, cloud_event1) + self.assertEqual(cloud_event.get_data(), cloud_event1.get_data()) + self.assertEqual(UCloudEvent.get_source(cloud_event), UCloudEvent.get_source(cloud_event1)) + self.assertEqual(UCloudEvent.get_specversion(cloud_event), UCloudEvent.get_specversion(cloud_event1)) + self.assertEqual(UCloudEvent.get_priority(cloud_event), UCloudEvent.get_priority(cloud_event1)) + self.assertEqual(UCloudEvent.get_id(cloud_event), UCloudEvent.get_id(cloud_event1)) + self.assertEqual(UCloudEvent.get_type(cloud_event), UCloudEvent.get_type(cloud_event1)) def test_to_from_message_from_request_cloudevent(self): # additional attributes @@ -229,26 +231,28 @@ def test_to_from_message_from_request_cloudevent(self): u_cloud_event_attributes) result = UCloudEvent.toMessage(cloud_event) self.assertIsNotNone(result) - self.assertEquals(UCloudEvent.get_ttl(cloud_event), result.attributes.ttl) - self.assertEquals(UCloudEvent.get_token(cloud_event), result.attributes.token) - self.assertEquals(UCloudEvent.get_sink(cloud_event), + self.assertEqual(UCloudEvent.get_ttl(cloud_event), result.attributes.ttl) + self.assertEqual(UCloudEvent.get_token(cloud_event), result.attributes.token) + self.assertEqual(UCloudEvent.get_sink(cloud_event), LongUriSerializer().serialize(result.attributes.sink)) - self.assertEquals(UCloudEvent.get_payload(cloud_event).SerializeToString(), result.payload.value) - self.assertEquals(UCloudEvent.get_source(cloud_event), - LongUriSerializer().serialize(result.source)) - self.assertEquals(UCloudEvent.get_priority(cloud_event), + self.assertEqual(UCloudEvent.get_payload(cloud_event).SerializeToString(), result.payload.value) + self.assertEqual(UCloudEvent.get_source(cloud_event), + LongUriSerializer().serialize(result.attributes.source)) + self.assertEqual(UCloudEvent.get_priority(cloud_event), UPriority.Name(result.attributes.priority)) cloud_event1 = UCloudEvent.fromMessage(result) - self.assertEquals(cloud_event, cloud_event1) - self.assertEquals(cloud_event.get_data(), cloud_event1.get_data()) - self.assertEquals(UCloudEvent.get_source(cloud_event), UCloudEvent.get_source(cloud_event1)) - self.assertEquals(UCloudEvent.get_sink(cloud_event), UCloudEvent.get_sink(cloud_event1)) - self.assertEquals(UCloudEvent.get_specversion(cloud_event), UCloudEvent.get_specversion(cloud_event1)) - self.assertEquals(UCloudEvent.get_priority(cloud_event), UCloudEvent.get_priority(cloud_event1)) - self.assertEquals(UCloudEvent.get_id(cloud_event), UCloudEvent.get_id(cloud_event1)) - self.assertEquals(UCloudEvent.get_type(cloud_event), UCloudEvent.get_type(cloud_event1)) - self.assertEquals(UCloudEvent.get_request_id(cloud_event), UCloudEvent.get_request_id(cloud_event1)) + cloud_event.__delitem__("time") + cloud_event1.__delitem__("time") + self.assertEqual(cloud_event, cloud_event1) + self.assertEqual(cloud_event.get_data(), cloud_event1.get_data()) + self.assertEqual(UCloudEvent.get_source(cloud_event), UCloudEvent.get_source(cloud_event1)) + self.assertEqual(UCloudEvent.get_sink(cloud_event), UCloudEvent.get_sink(cloud_event1)) + self.assertEqual(UCloudEvent.get_specversion(cloud_event), UCloudEvent.get_specversion(cloud_event1)) + self.assertEqual(UCloudEvent.get_priority(cloud_event), UCloudEvent.get_priority(cloud_event1)) + self.assertEqual(UCloudEvent.get_id(cloud_event), UCloudEvent.get_id(cloud_event1)) + self.assertEqual(UCloudEvent.get_type(cloud_event), UCloudEvent.get_type(cloud_event1)) + self.assertEqual(UCloudEvent.get_request_id(cloud_event), UCloudEvent.get_request_id(cloud_event1)) def test_to_from_message_from_request_cloudevent_without_attributes(self): # additional attributes @@ -261,21 +265,21 @@ def test_to_from_message_from_request_cloudevent_without_attributes(self): result = UCloudEvent.toMessage(cloud_event) self.assertIsNotNone(result) self.assertFalse(result.attributes.HasField('ttl')) - self.assertEquals(UCloudEvent.get_sink(cloud_event), + self.assertEqual(UCloudEvent.get_sink(cloud_event), LongUriSerializer().serialize(result.attributes.sink)) - self.assertEquals(UCloudEvent.get_payload(cloud_event).SerializeToString(), result.payload.value) - self.assertEquals(UCloudEvent.get_source(cloud_event), LongUriSerializer().serialize(result.source)) - self.assertEquals(result.attributes.priority, 0) + self.assertEqual(UCloudEvent.get_payload(cloud_event).SerializeToString(), result.payload.value) + self.assertEqual(UCloudEvent.get_source(cloud_event), LongUriSerializer().serialize(result.attributes.source)) + self.assertEqual(result.attributes.priority, 0) cloud_event1 = UCloudEvent.fromMessage(result) - self.assertEquals(cloud_event.get_data(), cloud_event1.get_data()) - self.assertEquals(UCloudEvent.get_source(cloud_event),UCloudEvent.get_source(cloud_event1)) - self.assertEquals(UCloudEvent.get_sink(cloud_event),UCloudEvent.get_sink(cloud_event1)) - self.assertEquals(UCloudEvent.get_specversion(cloud_event),UCloudEvent.get_specversion(cloud_event1)) - self.assertEquals(UCloudEvent.get_priority(cloud_event),UCloudEvent.get_priority(cloud_event1)) - self.assertEquals(UCloudEvent.get_id(cloud_event),UCloudEvent.get_id(cloud_event1)) - self.assertEquals(UCloudEvent.get_type(cloud_event),UCloudEvent.get_type(cloud_event1)) - self.assertEquals(UCloudEvent.get_request_id(cloud_event),UCloudEvent.get_request_id(cloud_event1)) + self.assertEqual(cloud_event.get_data(), cloud_event1.get_data()) + self.assertEqual(UCloudEvent.get_source(cloud_event),UCloudEvent.get_source(cloud_event1)) + self.assertEqual(UCloudEvent.get_sink(cloud_event),UCloudEvent.get_sink(cloud_event1)) + self.assertEqual(UCloudEvent.get_specversion(cloud_event),UCloudEvent.get_specversion(cloud_event1)) + self.assertEqual(UCloudEvent.get_priority(cloud_event),UCloudEvent.get_priority(cloud_event1)) + self.assertEqual(UCloudEvent.get_id(cloud_event),UCloudEvent.get_id(cloud_event1)) + self.assertEqual(UCloudEvent.get_type(cloud_event),UCloudEvent.get_type(cloud_event1)) + self.assertEqual(UCloudEvent.get_request_id(cloud_event),UCloudEvent.get_request_id(cloud_event1)) def test_to_from_message_from_UCP_cloudevent(self): # additional attributes @@ -289,7 +293,7 @@ def test_to_from_message_from_UCP_cloudevent(self): result = UCloudEvent.toMessage(cloud_event) self.assertIsNotNone(result) - self.assertEquals(UPriority.UPRIORITY_CS4,result.attributes.priority) + self.assertEqual(UPriority.UPRIORITY_CS4,result.attributes.priority) cloud_event1 = UCloudEvent.fromMessage(result) - self.assertEquals(UCloudEvent.get_priority(cloud_event1),UPriority.Name(result.attributes.priority)) + self.assertEqual(UCloudEvent.get_priority(cloud_event1),UPriority.Name(result.attributes.priority)) diff --git a/tests/test_cloudevent/test_factory/test_cloudeventfactory.py b/tests/test_cloudevent/test_factory/test_cloudeventfactory.py index a4b1e2c..448d8e0 100644 --- a/tests/test_cloudevent/test_factory/test_cloudeventfactory.py +++ b/tests/test_cloudevent/test_factory/test_cloudeventfactory.py @@ -35,7 +35,7 @@ from uprotocol.cloudevent.factory.ucloudevent import UCloudEvent from uprotocol.cloudevent.serialize.base64protobufserializer import Base64ProtobufSerializer from uprotocol.cloudevent.serialize.cloudeventtojsonserializer import CloudEventToJsonSerializer -from uprotocol.proto.cloudevents_pb2 import CloudEvent +from uprotocol.cloudevent.cloudevents_pb2 import CloudEvent from uprotocol.proto.uattributes_pb2 import UMessageType, UPriority from uprotocol.proto.uri_pb2 import UUri, UEntity, UResource from uprotocol.proto.ustatus_pb2 import UCode diff --git a/tests/test_cloudevent/test_serialize/test_cloudeventtojsonserializer.py b/tests/test_cloudevent/test_serialize/test_cloudeventtojsonserializer.py index a4a58e2..57cefcf 100644 --- a/tests/test_cloudevent/test_serialize/test_cloudeventtojsonserializer.py +++ b/tests/test_cloudevent/test_serialize/test_cloudeventtojsonserializer.py @@ -34,7 +34,7 @@ from uprotocol.cloudevent.factory.ucloudevent import UCloudEvent from uprotocol.cloudevent.serialize.cloudeventserializers import CloudEventSerializers from uprotocol.cloudevent.serialize.cloudeventtojsonserializer import CloudEventToJsonSerializer -from uprotocol.proto.cloudevents_pb2 import CloudEvent +from uprotocol.cloudevent.cloudevents_pb2 import CloudEvent from uprotocol.proto.uattributes_pb2 import UPriority, UMessageType protoContentType = CloudEventFactory.PROTOBUF_CONTENT_TYPE diff --git a/tests/test_cloudevent/test_serialize/test_cloudeventtoprotobufserializer.py b/tests/test_cloudevent/test_serialize/test_cloudeventtoprotobufserializer.py index 638cb92..b44522c 100644 --- a/tests/test_cloudevent/test_serialize/test_cloudeventtoprotobufserializer.py +++ b/tests/test_cloudevent/test_serialize/test_cloudeventtoprotobufserializer.py @@ -36,7 +36,7 @@ from uprotocol.cloudevent.serialize.base64protobufserializer import Base64ProtobufSerializer from uprotocol.cloudevent.serialize.cloudeventserializers import CloudEventSerializers from uprotocol.cloudevent.serialize.cloudeventtoprotobufserializer import CloudEventToProtobufSerializer -from uprotocol.proto.cloudevents_pb2 import CloudEvent +from uprotocol.cloudevent.cloudevents_pb2 import CloudEvent from uprotocol.proto.uattributes_pb2 import UPriority, UMessageType from uprotocol.proto.uri_pb2 import UUri, UEntity, UResource from uprotocol.uri.serializer.longuriserializer import LongUriSerializer diff --git a/tests/test_cloudevent/test_validator/test_cloudeventvalidator.py b/tests/test_cloudevent/test_validator/test_cloudeventvalidator.py index 228cf2f..b791685 100644 --- a/tests/test_cloudevent/test_validator/test_cloudeventvalidator.py +++ b/tests/test_cloudevent/test_validator/test_cloudeventvalidator.py @@ -34,7 +34,7 @@ from uprotocol.cloudevent.factory.cloudeventfactory import CloudEventFactory from uprotocol.cloudevent.factory.ucloudevent import UCloudEvent from uprotocol.cloudevent.validate.cloudeventvalidator import CloudEventValidator, Validators -from uprotocol.proto.cloudevents_pb2 import CloudEvent +from uprotocol.cloudevent.cloudevents_pb2 import CloudEvent from uprotocol.proto.uattributes_pb2 import UPriority, UMessageType from uprotocol.proto.uri_pb2 import UUri, UEntity, UResource from uprotocol.proto.ustatus_pb2 import UCode diff --git a/tests/test_rpc/test_rpc.py b/tests/test_rpc/test_rpc.py index 6c1001e..6507a87 100644 --- a/tests/test_rpc/test_rpc.py +++ b/tests/test_rpc/test_rpc.py @@ -29,7 +29,7 @@ from concurrent.futures import Future from google.protobuf.any_pb2 import Any from google.protobuf.wrappers_pb2 import Int32Value -from uprotocol.proto.cloudevents_pb2 import CloudEvent +from uprotocol.cloudevent.cloudevents_pb2 import CloudEvent from uprotocol.proto.uattributes_pb2 import UPriority from uprotocol.proto.upayload_pb2 import UPayload, UPayloadFormat from uprotocol.proto.uri_pb2 import UUri, UEntity diff --git a/uprotocol/proto/cloudevents_pb2.py b/uprotocol/cloudevent/cloudevents_pb2.py similarity index 100% rename from uprotocol/proto/cloudevents_pb2.py rename to uprotocol/cloudevent/cloudevents_pb2.py diff --git a/uprotocol/cloudevent/factory/ucloudevent.py b/uprotocol/cloudevent/factory/ucloudevent.py index b3dafc6..78af030 100644 --- a/uprotocol/cloudevent/factory/ucloudevent.py +++ b/uprotocol/cloudevent/factory/ucloudevent.py @@ -410,7 +410,7 @@ def fromMessage(message: UMessage) -> CloudEvent: attributes = message.attributes data = bytearray() json_attributes = {"id": LongUuidSerializer.instance().serialize(attributes.id), - "source": LongUriSerializer().serialize(message.source), + "source": LongUriSerializer().serialize(message.attributes.source), "type": UCloudEvent.get_event_type(attributes.type)} contenttype = UCloudEvent.get_content_type_from_upayload_format(message.payload.format) if contenttype: @@ -453,6 +453,8 @@ def toMessage(event: CloudEvent) -> UMessage: value=UCloudEvent.get_payload(event).SerializeToString()) attributes = UAttributes(id=LongUuidSerializer.instance().deserialize(UCloudEvent.get_id(event)), type=UCloudEvent.get_message_type(UCloudEvent.get_type(event))) + attributes.source.CopyFrom(source) + if UCloudEvent.has_communication_status_problem(event): attributes.commstatus = UCloudEvent.get_communication_status(event) priority = UCloudEvent.get_priority(event) @@ -483,4 +485,4 @@ def toMessage(event: CloudEvent) -> UMessage: if plevel is not None: attributes.permission_level = plevel - return UMessage(attributes=attributes, payload=payload, source=source) + return UMessage(attributes=attributes, payload=payload) diff --git a/uprotocol/cloudevent/serialize/cloudeventtoprotobufserializer.py b/uprotocol/cloudevent/serialize/cloudeventtoprotobufserializer.py index b594871..df50921 100644 --- a/uprotocol/cloudevent/serialize/cloudeventtoprotobufserializer.py +++ b/uprotocol/cloudevent/serialize/cloudeventtoprotobufserializer.py @@ -27,7 +27,7 @@ from cloudevents.http import CloudEvent from uprotocol.cloudevent.serialize.cloudeventserializer import CloudEventSerializer -from uprotocol.proto import cloudevents_pb2 +from uprotocol.cloudevent import cloudevents_pb2 # ToDo- convert cloud event to cloudevent proto diff --git a/uprotocol/proto/__init__.py b/uprotocol/proto/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/uprotocol/proto/uattributes_pb2.py b/uprotocol/proto/uattributes_pb2.py deleted file mode 100644 index c98292d..0000000 --- a/uprotocol/proto/uattributes_pb2.py +++ /dev/null @@ -1,32 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by the protocol buffer compiler. DO NOT EDIT! -# source: uattributes.proto -"""Generated protocol buffer code.""" -from google.protobuf import descriptor as _descriptor -from google.protobuf import descriptor_pool as _descriptor_pool -from google.protobuf import symbol_database as _symbol_database -from google.protobuf.internal import builder as _builder -# @@protoc_insertion_point(imports) - -_sym_db = _symbol_database.Default() - - -import uprotocol.proto.uri_pb2 as uri__pb2 -import uprotocol.proto.uuid_pb2 as uuid__pb2 - - -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x11uattributes.proto\x12\x0cuprotocol.v1\x1a\turi.proto\x1a\nuuid.proto\"\xf8\x02\n\x0bUAttributes\x12\x1e\n\x02id\x18\x01 \x01(\x0b\x32\x12.uprotocol.v1.UUID\x12(\n\x04type\x18\x02 \x01(\x0e\x32\x1a.uprotocol.v1.UMessageType\x12%\n\x04sink\x18\x03 \x01(\x0b\x32\x12.uprotocol.v1.UUriH\x00\x88\x01\x01\x12)\n\x08priority\x18\x04 \x01(\x0e\x32\x17.uprotocol.v1.UPriority\x12\x10\n\x03ttl\x18\x05 \x01(\x05H\x01\x88\x01\x01\x12\x1d\n\x10permission_level\x18\x06 \x01(\x05H\x02\x88\x01\x01\x12\x17\n\ncommstatus\x18\x07 \x01(\x05H\x03\x88\x01\x01\x12&\n\x05reqid\x18\x08 \x01(\x0b\x32\x12.uprotocol.v1.UUIDH\x04\x88\x01\x01\x12\x12\n\x05token\x18\t \x01(\tH\x05\x88\x01\x01\x42\x07\n\x05_sinkB\x06\n\x04_ttlB\x13\n\x11_permission_levelB\r\n\x0b_commstatusB\x08\n\x06_reqidB\x08\n\x06_token*\x7f\n\x0cUMessageType\x12\x1d\n\x19UMESSAGE_TYPE_UNSPECIFIED\x10\x00\x12\x19\n\x15UMESSAGE_TYPE_PUBLISH\x10\x01\x12\x19\n\x15UMESSAGE_TYPE_REQUEST\x10\x02\x12\x1a\n\x16UMESSAGE_TYPE_RESPONSE\x10\x03*\xab\x01\n\tUPriority\x12\x19\n\x15UPRIORITY_UNSPECIFIED\x10\x00\x12\x11\n\rUPRIORITY_CS0\x10\x01\x12\x11\n\rUPRIORITY_CS1\x10\x02\x12\x11\n\rUPRIORITY_CS2\x10\x03\x12\x11\n\rUPRIORITY_CS3\x10\x04\x12\x11\n\rUPRIORITY_CS4\x10\x05\x12\x11\n\rUPRIORITY_CS5\x10\x06\x12\x11\n\rUPRIORITY_CS6\x10\x07\x42.\n\x18org.eclipse.uprotocol.v1B\x10UAttributesProtoP\x01\x62\x06proto3') - -_globals = globals() -_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) -_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'uattributes_pb2', _globals) -if _descriptor._USE_C_DESCRIPTORS == False: - _globals['DESCRIPTOR']._options = None - _globals['DESCRIPTOR']._serialized_options = b'\n\030org.eclipse.uprotocol.v1B\020UAttributesProtoP\001' - _globals['_UMESSAGETYPE']._serialized_start=437 - _globals['_UMESSAGETYPE']._serialized_end=564 - _globals['_UPRIORITY']._serialized_start=567 - _globals['_UPRIORITY']._serialized_end=738 - _globals['_UATTRIBUTES']._serialized_start=59 - _globals['_UATTRIBUTES']._serialized_end=435 -# @@protoc_insertion_point(module_scope) diff --git a/uprotocol/proto/umessage_pb2.py b/uprotocol/proto/umessage_pb2.py deleted file mode 100644 index f183abe..0000000 --- a/uprotocol/proto/umessage_pb2.py +++ /dev/null @@ -1,29 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by the protocol buffer compiler. DO NOT EDIT! -# source: umessage.proto -"""Generated protocol buffer code.""" -from google.protobuf import descriptor as _descriptor -from google.protobuf import descriptor_pool as _descriptor_pool -from google.protobuf import symbol_database as _symbol_database -from google.protobuf.internal import builder as _builder -# @@protoc_insertion_point(imports) - -_sym_db = _symbol_database.Default() - - -import uprotocol.proto.uattributes_pb2 as uattributes__pb2 -import uprotocol.proto.upayload_pb2 as upayload__pb2 -import uprotocol.proto.uri_pb2 as uri__pb2 - - -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0eumessage.proto\x12\x0cuprotocol.v1\x1a\x11uattributes.proto\x1a\x0eupayload.proto\x1a\turi.proto\"\x86\x01\n\x08UMessage\x12\"\n\x06source\x18\x01 \x01(\x0b\x32\x12.uprotocol.v1.UUri\x12-\n\nattributes\x18\x02 \x01(\x0b\x32\x19.uprotocol.v1.UAttributes\x12\'\n\x07payload\x18\x03 \x01(\x0b\x32\x16.uprotocol.v1.UPayloadB+\n\x18org.eclipse.uprotocol.v1B\rUMessageProtoP\x01\x62\x06proto3') - -_globals = globals() -_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) -_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'umessage_pb2', _globals) -if _descriptor._USE_C_DESCRIPTORS == False: - _globals['DESCRIPTOR']._options = None - _globals['DESCRIPTOR']._serialized_options = b'\n\030org.eclipse.uprotocol.v1B\rUMessageProtoP\001' - _globals['_UMESSAGE']._serialized_start=79 - _globals['_UMESSAGE']._serialized_end=213 -# @@protoc_insertion_point(module_scope) diff --git a/uprotocol/proto/upayload_pb2.py b/uprotocol/proto/upayload_pb2.py deleted file mode 100644 index c9d638d..0000000 --- a/uprotocol/proto/upayload_pb2.py +++ /dev/null @@ -1,28 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by the protocol buffer compiler. DO NOT EDIT! -# source: upayload.proto -"""Generated protocol buffer code.""" -from google.protobuf import descriptor as _descriptor -from google.protobuf import descriptor_pool as _descriptor_pool -from google.protobuf import symbol_database as _symbol_database -from google.protobuf.internal import builder as _builder -# @@protoc_insertion_point(imports) - -_sym_db = _symbol_database.Default() - - - - -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0eupayload.proto\x12\x0cuprotocol.v1\"\x86\x01\n\x08UPayload\x12\x13\n\treference\x18\x01 \x01(\x06H\x00\x12\x0f\n\x05value\x18\x02 \x01(\x0cH\x00\x12\x13\n\x06length\x18\x03 \x01(\x05H\x01\x88\x01\x01\x12,\n\x06\x66ormat\x18\x04 \x01(\x0e\x32\x1c.uprotocol.v1.UPayloadFormatB\x06\n\x04\x64\x61taB\t\n\x07_length*\xd8\x01\n\x0eUPayloadFormat\x12\x1f\n\x1bUPAYLOAD_FORMAT_UNSPECIFIED\x10\x00\x12\x1c\n\x18UPAYLOAD_FORMAT_PROTOBUF\x10\x01\x12\x18\n\x14UPAYLOAD_FORMAT_JSON\x10\x02\x12\x1a\n\x16UPAYLOAD_FORMAT_SOMEIP\x10\x03\x12\x1e\n\x1aUPAYLOAD_FORMAT_SOMEIP_TLV\x10\x04\x12\x17\n\x13UPAYLOAD_FORMAT_RAW\x10\x05\x12\x18\n\x14UPAYLOAD_FORMAT_TEXT\x10\x06\x42+\n\x18org.eclipse.uprotocol.v1B\rUPayloadProtoP\x01\x62\x06proto3') - -_globals = globals() -_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) -_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'upayload_pb2', _globals) -if _descriptor._USE_C_DESCRIPTORS == False: - _globals['DESCRIPTOR']._options = None - _globals['DESCRIPTOR']._serialized_options = b'\n\030org.eclipse.uprotocol.v1B\rUPayloadProtoP\001' - _globals['_UPAYLOADFORMAT']._serialized_start=170 - _globals['_UPAYLOADFORMAT']._serialized_end=386 - _globals['_UPAYLOAD']._serialized_start=33 - _globals['_UPAYLOAD']._serialized_end=167 -# @@protoc_insertion_point(module_scope) diff --git a/uprotocol/proto/uri_pb2.py b/uprotocol/proto/uri_pb2.py deleted file mode 100644 index 5b475e4..0000000 --- a/uprotocol/proto/uri_pb2.py +++ /dev/null @@ -1,34 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by the protocol buffer compiler. DO NOT EDIT! -# source: uri.proto -"""Generated protocol buffer code.""" -from google.protobuf import descriptor as _descriptor -from google.protobuf import descriptor_pool as _descriptor_pool -from google.protobuf import symbol_database as _symbol_database -from google.protobuf.internal import builder as _builder -# @@protoc_insertion_point(imports) - -_sym_db = _symbol_database.Default() - - - - -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\turi.proto\x12\x0cuprotocol.v1\"\x85\x01\n\x04UUri\x12+\n\tauthority\x18\x01 \x01(\x0b\x32\x18.uprotocol.v1.UAuthority\x12%\n\x06\x65ntity\x18\x02 \x01(\x0b\x32\x15.uprotocol.v1.UEntity\x12)\n\x08resource\x18\x03 \x01(\x0b\x32\x17.uprotocol.v1.UResource\"B\n\nUAuthority\x12\x0e\n\x04name\x18\x01 \x01(\tH\x00\x12\x0c\n\x02ip\x18\x02 \x01(\x0cH\x00\x12\x0c\n\x02id\x18\x03 \x01(\x0cH\x00\x42\x08\n\x06remote\"\x8b\x01\n\x07UEntity\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0f\n\x02id\x18\x02 \x01(\rH\x00\x88\x01\x01\x12\x1a\n\rversion_major\x18\x03 \x01(\rH\x01\x88\x01\x01\x12\x1a\n\rversion_minor\x18\x04 \x01(\rH\x02\x88\x01\x01\x42\x05\n\x03_idB\x10\n\x0e_version_majorB\x10\n\x0e_version_minor\"w\n\tUResource\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x15\n\x08instance\x18\x02 \x01(\tH\x00\x88\x01\x01\x12\x14\n\x07message\x18\x03 \x01(\tH\x01\x88\x01\x01\x12\x0f\n\x02id\x18\x04 \x01(\rH\x02\x88\x01\x01\x42\x0b\n\t_instanceB\n\n\x08_messageB\x05\n\x03_id\"-\n\tUUriBatch\x12 \n\x04uris\x18\x01 \x03(\x0b\x32\x12.uprotocol.v1.UUriB\'\n\x18org.eclipse.uprotocol.v1B\tUUriProtoP\x01\x62\x06proto3') - -_globals = globals() -_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) -_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'uri_pb2', _globals) -if _descriptor._USE_C_DESCRIPTORS == False: - _globals['DESCRIPTOR']._options = None - _globals['DESCRIPTOR']._serialized_options = b'\n\030org.eclipse.uprotocol.v1B\tUUriProtoP\001' - _globals['_UURI']._serialized_start=28 - _globals['_UURI']._serialized_end=161 - _globals['_UAUTHORITY']._serialized_start=163 - _globals['_UAUTHORITY']._serialized_end=229 - _globals['_UENTITY']._serialized_start=232 - _globals['_UENTITY']._serialized_end=371 - _globals['_URESOURCE']._serialized_start=373 - _globals['_URESOURCE']._serialized_end=492 - _globals['_UURIBATCH']._serialized_start=494 - _globals['_UURIBATCH']._serialized_end=539 -# @@protoc_insertion_point(module_scope) diff --git a/uprotocol/proto/ustatus_pb2.py b/uprotocol/proto/ustatus_pb2.py deleted file mode 100644 index 30b68f2..0000000 --- a/uprotocol/proto/ustatus_pb2.py +++ /dev/null @@ -1,29 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by the protocol buffer compiler. DO NOT EDIT! -# source: ustatus.proto -"""Generated protocol buffer code.""" -from google.protobuf import descriptor as _descriptor -from google.protobuf import descriptor_pool as _descriptor_pool -from google.protobuf import symbol_database as _symbol_database -from google.protobuf.internal import builder as _builder -# @@protoc_insertion_point(imports) - -_sym_db = _symbol_database.Default() - - -from google.protobuf import any_pb2 as google_dot_protobuf_dot_any__pb2 - - -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\rustatus.proto\x12\x0cuprotocol.v1\x1a\x19google/protobuf/any.proto\"u\n\x07UStatus\x12!\n\x04\x63ode\x18\x01 \x01(\x0e\x32\x13.uprotocol.v1.UCode\x12\x14\n\x07message\x18\x02 \x01(\tH\x00\x88\x01\x01\x12%\n\x07\x64\x65tails\x18\x03 \x03(\x0b\x32\x14.google.protobuf.AnyB\n\n\x08_message*\xb8\x02\n\x05UCode\x12\x06\n\x02OK\x10\x00\x12\r\n\tCANCELLED\x10\x01\x12\x0b\n\x07UNKNOWN\x10\x02\x12\x14\n\x10INVALID_ARGUMENT\x10\x03\x12\x15\n\x11\x44\x45\x41\x44LINE_EXCEEDED\x10\x04\x12\r\n\tNOT_FOUND\x10\x05\x12\x12\n\x0e\x41LREADY_EXISTS\x10\x06\x12\x15\n\x11PERMISSION_DENIED\x10\x07\x12\x13\n\x0fUNAUTHENTICATED\x10\x10\x12\x16\n\x12RESOURCE_EXHAUSTED\x10\x08\x12\x17\n\x13\x46\x41ILED_PRECONDITION\x10\t\x12\x0b\n\x07\x41\x42ORTED\x10\n\x12\x10\n\x0cOUT_OF_RANGE\x10\x0b\x12\x11\n\rUNIMPLEMENTED\x10\x0c\x12\x0c\n\x08INTERNAL\x10\r\x12\x0f\n\x0bUNAVAILABLE\x10\x0e\x12\r\n\tDATA_LOSS\x10\x0f\x42*\n\x18org.eclipse.uprotocol.v1B\x0cUStatusProtoP\x01\x62\x06proto3') - -_globals = globals() -_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) -_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'ustatus_pb2', _globals) -if _descriptor._USE_C_DESCRIPTORS == False: - _globals['DESCRIPTOR']._options = None - _globals['DESCRIPTOR']._serialized_options = b'\n\030org.eclipse.uprotocol.v1B\014UStatusProtoP\001' - _globals['_UCODE']._serialized_start=178 - _globals['_UCODE']._serialized_end=490 - _globals['_USTATUS']._serialized_start=58 - _globals['_USTATUS']._serialized_end=175 -# @@protoc_insertion_point(module_scope) diff --git a/uprotocol/proto/uuid_pb2.py b/uprotocol/proto/uuid_pb2.py deleted file mode 100644 index d321cd4..0000000 --- a/uprotocol/proto/uuid_pb2.py +++ /dev/null @@ -1,26 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by the protocol buffer compiler. DO NOT EDIT! -# source: uuid.proto -"""Generated protocol buffer code.""" -from google.protobuf import descriptor as _descriptor -from google.protobuf import descriptor_pool as _descriptor_pool -from google.protobuf import symbol_database as _symbol_database -from google.protobuf.internal import builder as _builder -# @@protoc_insertion_point(imports) - -_sym_db = _symbol_database.Default() - - - - -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\nuuid.proto\x12\x0cuprotocol.v1\" \n\x04UUID\x12\x0b\n\x03msb\x18\x01 \x01(\x06\x12\x0b\n\x03lsb\x18\x02 \x01(\x06\x42\'\n\x18org.eclipse.uprotocol.v1B\tUUIRProtoP\x01\x62\x06proto3') - -_globals = globals() -_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) -_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'uuid_pb2', _globals) -if _descriptor._USE_C_DESCRIPTORS == False: - _globals['DESCRIPTOR']._options = None - _globals['DESCRIPTOR']._serialized_options = b'\n\030org.eclipse.uprotocol.v1B\tUUIRProtoP\001' - _globals['_UUID']._serialized_start=28 - _globals['_UUID']._serialized_end=60 -# @@protoc_insertion_point(module_scope)