Skip to content

Commit

Permalink
Improvements (#31)
Browse files Browse the repository at this point in the history
New commands support
  • Loading branch information
valentin-gauthier-geosiris authored Nov 8, 2023
1 parent f942ad5 commit e354b43
Show file tree
Hide file tree
Showing 7 changed files with 963 additions and 678 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ demos/
*.h5
*.xml
*.txt
output*
output*
*.log
91 changes: 62 additions & 29 deletions etpclient/etp/requester.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: Apache-2.0
#
import re
import zipfile
from zipfile import ZipFile
from lxml import etree
from io import BytesIO

Expand Down Expand Up @@ -71,6 +71,9 @@
from etptypes.energistics.etp.v12.protocol.store.get_data_objects import (
GetDataObjects,
)
from etptypes.energistics.etp.v12.protocol.store.get_data_objects_response import (
GetDataObjectsResponse,
)
from etptypes.energistics.etp.v12.protocol.store.delete_data_objects import (
DeleteDataObjects,
)
Expand Down Expand Up @@ -112,6 +115,7 @@
from etpproto.uri import *

from etpproto.connection import ETPConnection, CommunicationProtocol
from etpproto.uri import parse_uri

from etpclient.etp.h5_handler import generate_put_data_arrays

Expand Down Expand Up @@ -256,8 +260,11 @@ def get_scope(scope: str):


def get_resouces(uri: str = "eml:///", depth: int = 1, scope=None):
if not uri.startswith("eml:///"):
uri = f"eml:///dataspace('{uri}')"
if uri is not None:
if not uri.startswith("eml:///"):
uri = f"eml:///dataspace('{uri}')"
else:
uri = "eml:///"
return GetResources(
context=ContextInfo(
uri=uri,
Expand All @@ -277,8 +284,8 @@ def get_dataspaces():
return GetDataspaces()


def extractResqmlUuid(content: str):
return findUuid(content)
async def extractResqmlUuid(content: str):
return await findUuid(content)


XML_TYPE_REGXP = r"<([\w]+:)?([\w]+)"
Expand Down Expand Up @@ -624,27 +631,53 @@ async def put_data_array_sender(
print(e)


if __name__ == "__main__":

for pda in put_data_array(
["b710482d-0a57-4149-8196-a6beb978905e"],
"test-data/usecase1.epc",
"test-data/ALWYN_RESQML_FAULT_MBA_ACTIVITY.h5",
"coucou",
):
print("> ", pda.data_arrays["0"].uid.path_in_resource)

print("\n==== NO filter =====\n")

for pda in put_data_array(
[],
"D:/Geosiris/CLOUD/Resqml Tools/data/ALWYN_DEPTH/ALWYN-RESQML.epc",
"D:/Geosiris/CLOUD/Resqml Tools/data/ALWYN_DEPTH/ALWYN-RESQML.h5",
"coucou",
):
print(
"> ",
pda.data_arrays["0"].uid.uri,
" ==> ",
pda.data_arrays["0"].uid.path_in_resource,
)
async def download_dataspace(
ws, output_file_path: str, dataspace_name: str = None
):
get_res = get_resouces(uri=dataspace_name, depth=1, scope="sources")
result_get_res = await ws.send_and_wait(get_res)
# print("===>", result_get_res)

uri_list = []

for msg in result_get_res:
try:
uri_list += list(map(lambda r: r.uri, msg.body.resources))
except Exception as e:
print("Err ", {type(e).__name__}, e)

print(f"URIS to download : {uri_list}")

if len(uri_list) <= 0:
print("No Object to download")
return

all_in_one = False

result_get_do = []

if all_in_one:
get_do = get_data_object(uri_list, format="xml")
result_get_do = result_get_do + await ws.send_and_wait(get_do)
else:
for uri in uri_list:
get_do = get_data_object([uri], format="xml")
result_get_do = result_get_do + await ws.send_and_wait(get_do)

# print(result_get_do)

# TODO : ecrire epc
if not output_file_path.endswith(".zip"):
output_file_path = output_file_path + ".zip"

with ZipFile(output_file_path, "w") as zip_file:
for msg in result_get_do:
if isinstance(msg.body, GetDataObjectsResponse):
for _id, do in msg.body.data_objects.items():
obj_uri = parse_uri(do.resource.uri)
obj_path = f"{obj_uri.object_type}_{obj_uri.uuid}.xml"
print(f"Storing file : {obj_path}")
with zip_file.open(obj_path, "w") as xml_file:
xml_file.write(do.data)
else:
print(f"Not a dataobject :{type(msg.body)} : {msg.body}")
32 changes: 29 additions & 3 deletions etpclient/etp/serverprotocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
from etptypes.energistics.etp.v12.protocol.core.close_session import (
CloseSession,
)
from etptypes.energistics.etp.v12.protocol.core.acknowledge import Acknowledge
from etptypes.energistics.etp.v12.protocol.core.open_session import OpenSession
from etptypes.energistics.etp.v12.protocol.core.ping import Ping
from etptypes.energistics.etp.v12.protocol.core.pong import Pong
Expand Down Expand Up @@ -199,7 +200,6 @@ def print_protocol_exception(pe: ProtocolException):

@ETPConnection.on(CommunicationProtocol.CORE)
class myCoreProtocol(CoreHandler):

uuid: Uuid = pyUUID.uuid4()

async def on_open_session(
Expand Down Expand Up @@ -301,6 +301,15 @@ async def on_get_deleted_resources_response(

yield

async def on_acknowledge(
self,
msg: Acknowledge,
msg_header: MessageHeader,
client_info: Union[None, ClientInfo] = None,
) -> AsyncGenerator[Optional[Message], None]:
print(f"Message recieved {msg}")
yield


# ____ __
# / __ \____ _/ /_____ __________ ____ _________ _____
Expand Down Expand Up @@ -632,6 +641,7 @@ async def on_protocol_exception(
# /____/\___/_/ |___/\___/_/ \____/\__,_/ .___/____/
# /_/


# ATTENTION : A FAIRE EN DERNIER ! a cause de supportedProtocolList_fun()
@ETPConnection.dec_server_capabilities()
def computeCapability(supportedProtocolList_fun) -> ServerCapabilities:
Expand Down Expand Up @@ -666,16 +676,32 @@ def computeCapability(supportedProtocolList_fun) -> ServerCapabilities:
# 'SupportsGet': {'item': {'boolean': True}},
# 'SupportsPut': {'item': {'boolean': True}}
# )
# SupportedDataObject(
# qualified_type="eml20.*",
# data_object_capabilities={
# "SupportsDelete": DataValue(item=True),
# "SupportsPut": DataValue(item=True),
# "SupportsGet": DataValue(item=True),
# },
# ),
# SupportedDataObject(
# qualified_type="resqml20.*",
# data_object_capabilities={
# "SupportsDelete": DataValue(item=True),
# "SupportsPut": DataValue(item=True),
# "SupportsGet": DataValue(item=True),
# },
# ),
SupportedDataObject(
qualified_type="eml20.*",
qualified_type="witsml20.*",
data_object_capabilities={
"SupportsDelete": DataValue(item=True),
"SupportsPut": DataValue(item=True),
"SupportsGet": DataValue(item=True),
},
),
SupportedDataObject(
qualified_type="resqml20.*",
qualified_type="witsml21.*",
data_object_capabilities={
"SupportsDelete": DataValue(item=True),
"SupportsPut": DataValue(item=True),
Expand Down
Loading

0 comments on commit e354b43

Please sign in to comment.