From 01dfda358f10153685934a093856494608c221a5 Mon Sep 17 00:00:00 2001 From: Vladimir Mutafov Date: Mon, 13 Nov 2023 16:46:37 +0200 Subject: [PATCH 1/2] feat: python io api --- .../python-modules/dirigible/io/__init__.py | 12 ++ .../python-modules/dirigible/io/bytes.py | 38 ++++++ .../python-modules/dirigible/io/files.py | 129 ++++++++++++++++++ .../python-modules/dirigible/io/image.py | 16 +++ .../python-modules/dirigible/io/streams.py | 98 +++++++++++++ .../python-modules/dirigible/io/zip.py | 104 ++++++++++++++ 6 files changed, 397 insertions(+) create mode 100644 components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/__init__.py create mode 100644 components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/bytes.py create mode 100644 components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/files.py create mode 100644 components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/image.py create mode 100644 components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/streams.py create mode 100644 components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/zip.py diff --git a/components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/__init__.py b/components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/__init__.py new file mode 100644 index 00000000000..35bcd56029e --- /dev/null +++ b/components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/__init__.py @@ -0,0 +1,12 @@ +from .bytes import * as Bytes +bytes = Bytes +''' +from .request import Request +from .request import Request +from .request import Request +from .response import Response + +request = Request +response = Response +''' + diff --git a/components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/bytes.py b/components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/bytes.py new file mode 100644 index 00000000000..937cca1fe7c --- /dev/null +++ b/components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/bytes.py @@ -0,0 +1,38 @@ +# Copyright (c) 2023 SAP SE or an SAP affiliate company and Eclipse Dirigible contributors +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v2.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v20.html +# SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and Eclipse Dirigible contributors +# SPDX-License-Identifier: EPL-2.0 + +from java.lang import String, Byte +import java.lang.reflect.Array as JArray +from org.eclipse.dirigible.components.api.io import BytesFacade + +def toJavaBytes(bytes): + internalBytes = JArray.newInstance(Byte.TYPE, len(bytes)) + for i in range(len(bytes)): + internalBytes[i] = bytes[i] + return internalBytes + +def toJavaScriptBytes(internalBytes): + bytes = [] + for i in range(internalBytes.length): + bytes.append(internalBytes[i]) + return bytes + +def textToByteArray(text): + javaString = String(text) + native = BytesFacade.textToByteArray(text) + return toJavaScriptBytes(native) + +def byteArrayToText(data): + native = toJavaBytes(data) + return "".join(map(chr, toJavaScriptBytes(native)) + +def intToByteArray(value, byteOrder): + return BytesFacade.intToByteArray(value, byteOrder) + +def byteArrayToInt(data, byteOrder): + return BytesFacade.byteArrayToInt(data, byteOrder) diff --git a/components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/files.py b/components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/files.py new file mode 100644 index 00000000000..8916a4a9147 --- /dev/null +++ b/components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/files.py @@ -0,0 +1,129 @@ +# Copyright (c) 2023 SAP SE or an SAP affiliate company and Eclipse Dirigible contributors +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v2.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v20.html +# SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and Eclipse Dirigible contributors +# SPDX-License-Identifier: EPL-2.0 + +import streams +import bytes +import java + +FilesFacade = java.type("org.eclipse.dirigible.components.api.io.FilesFacade") + +def exists(path): + return FilesFacade.exists(path) + +def isExecutable(path): + return FilesFacade.isExecutable(path) + +def isReadable(path): + return FilesFacade.isReadable(path) + +def isWritable(path): + return FilesFacade.isWritable(path) + +def isHidden(path): + return FilesFacade.isHidden(path) + +def isDirectory(path): + return FilesFacade.isDirectory(path) + +def isFile(path): + return FilesFacade.isFile(path) + +def isSameFile(path1, path2): + return FilesFacade.isSameFile(path1, path2) + +def getCanonicalPath(path): + return FilesFacade.getCanonicalPath(path) + +def getName(path): + return FilesFacade.getName(path) + +def getParentPath(path): + return FilesFacade.getParentPath(path) + +def readBytes(path): + native = FilesFacade.readBytes(path) + data = bytes.toPythonBytes(native) + return data + +def readBytesNative(path): + return FilesFacade.readBytes(path) + +def readText(path): + return FilesFacade.readText(path) + +def writeBytes(path, data): + native = bytes.toJavaBytes(data) + FilesFacade.writeBytesNative(path, native) + +def writeBytesNative(path, data): + FilesFacade.writeBytesNative(path, data) + +def writeText(path, text): + FilesFacade.writeText(path, text) + +def getLastModified(path): + return FilesFacade.getLastModified(path) + +def setLastModified(path, time): + FilesFacade.setLastModified(path, time.getMilliseconds()) + +def getOwner(path): + return FilesFacade.getOwner(path) + +def setOwner(path, owner): + FilesFacade.setOwner(path, owner) + +def getPermissions(path): + return FilesFacade.getPermissions(path) + +def setPermissions(path, permissions): + FilesFacade.setPermissions(path, permissions) + +def size(path): + return FilesFacade.size(path) + +def createFile(path): + FilesFacade.createFile(path) + +def createDirectory(path): + FilesFacade.createDirectory(path) + +def copy(source, target): + FilesFacade.copy(source, target) + +def move(source, target): + FilesFacade.move(source, target) + +def deleteFile(path): + FilesFacade.deleteFile(path) + +def deleteDirectory(path, forced): + FilesFacade.deleteDirectory(path, forced) + +def createTempFile(prefix, suffix): + return FilesFacade.createTempFile(prefix, suffix) + +def createTempDirectory(prefix): + return FilesFacade.createTempDirectory(prefix) + +def createInputStream(path): + native = FilesFacade.createInputStream(path) + return streams.InputStream(native) + +def createOutputStream(path): + native = FilesFacade.createOutputStream(path) + return streams.OutputStream(native) + +def traverse(path): + return FilesFacade.traverse(path) + +def list(path): + return list(map(lambda e: e['path'], JSON.parse(FilesFacade.list(path))) + +def find(path, pattern): + return JSON.parse(FilesFacade.find(path, pattern)) diff --git a/components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/image.py b/components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/image.py new file mode 100644 index 00000000000..f6d4b2e44b9 --- /dev/null +++ b/components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/image.py @@ -0,0 +1,16 @@ +# Copyright (c) 2023 SAP SE or an SAP affiliate company and Eclipse Dirigible contributors +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v2.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v20.html +# SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and Eclipse Dirigible contributors +# SPDX-License-Identifier: EPL-2.0 + +import streams +import java + +ImageFacade = java.type("org.eclipse.dirigible.components.api.io.ImageFacade") + +def resize(original, imageType, width, height): + native = ImageFacade.resize(original, imageType, width, height) + return streams.InputStream(native) diff --git a/components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/streams.py b/components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/streams.py new file mode 100644 index 00000000000..745f8f73e2c --- /dev/null +++ b/components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/streams.py @@ -0,0 +1,98 @@ +# Copyright (c) 2023 SAP SE or an SAP affiliate company and Eclipse Dirigible contributors +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v2.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v20.html +# SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and Eclipse Dirigible contributors +# SPDX-License-Identifier: EPL-2.0 + +import bytes +import java + +StreamsFacade = java.type("org.eclipse.dirigible.components.api.io.StreamsFacade") + +class InputStream: + def __init__(self, native): + self.native = native + + def read(self): + return StreamsFacade.read(self.native) + + def readBytes(self): + native = StreamsFacade.readBytes(self.native) + return bytes.toPythonBytes(native) + + def readBytesNative(self): + return StreamsFacade.readBytes(self.native) + + def readText(self): + return StreamsFacade.readText(self.native) + + def close(self): + StreamsFacade.close(self.native) + + def isValid(self): + return self.native is not None + +class OutputStream: + def __init__(self, native): + self.native = native + + def write(self, byte): + StreamsFacade.write(self.native, byte) + + def writeBytes(self, data): + native = bytes.toJavaBytes(data) + StreamsFacade.writeBytes(self.native, native) + + def writeBytesNative(self, data): + StreamsFacade.writeBytes(self.native, data) + + def writeText(self, text): + StreamsFacade.writeText(self.native, text) + + def close(self): + StreamsFacade.close(self.native) + + def getBytes(self): + native = StreamsFacade.getBytes(self.native) + data = bytes.toPythonBytes(native) + return data + + def getBytesNative(self): + native = StreamsFacade.getBytes(self.native) + return native + + def getText(self): + value = StreamsFacade.getText(self.native) + return value + + def isValid(self): + return self.native is not None + +def copy(input, output): + StreamsFacade.copy(input.native, output.native) + +def copyLarge(input, output): + StreamsFacade.copyLarge(input.native, output.native) + +def getResourceAsByteArrayInputStream(path): + native = StreamsFacade.getResourceAsByteArrayInputStream(path) + return InputStream(native) + +def createByteArrayInputStream(data): + array = bytes.toJavaBytes(data) + native = StreamsFacade.createByteArrayInputStream(array) + return InputStream(native) + +def createByteArrayOutputStream(): + native = StreamsFacade.createByteArrayOutputStream() + return OutputStream(native) + +def createInputStream(native): + inputStream = InputStream(native) + return inputStream + +def createOutputStream(native): + outputStream = OutputStream(native) + return outputStream diff --git a/components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/zip.py b/components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/zip.py new file mode 100644 index 00000000000..ff870f015db --- /dev/null +++ b/components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/zip.py @@ -0,0 +1,104 @@ +# Copyright (c) 2023 SAP SE or an SAP affiliate company and Eclipse Dirigible contributors +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v2.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v20.html +# SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and Eclipse Dirigible contributors +# SPDX-License-Identifier: EPL-2.0 + +import bytes +import java + +ZipFacade = java.type("org.eclipse.dirigible.components.api.io.ZipFacade") + +def zip(sourcePath, zipTargetPath): + ZipFacade.exportZip(sourcePath, zipTargetPath) + +def unzip(zipPath, targetPath): + ZipFacade.importZip(zipPath, targetPath) + +def createZipInputStream(inputStream): + native = ZipFacade.createZipInputStream(inputStream.native) + return ZipInputStream(native) + +class ZipInputStream: + def __init__(self, native): + self.native = native + + def getNextEntry(self): + native = self.native.getNextEntry() + zipEntry = ZipEntry(native) + return zipEntry + + def read(self): + native = ZipFacade.readNative(self.native) + return bytes.toPythonBytes(native) + + def readNative(self): + return ZipFacade.readNative(self.native) + + def readText(self): + return ZipFacade.readText(self.native) + + def close(self): + self.native.close() + +def createZipOutputStream(outputStream): + native = ZipFacade.createZipOutputStream(outputStream.native) + return ZipOutputStream(native) + +class ZipOutputStream: + def __init__(self, native): + self.native = native + + def createZipEntry(self, name): + nativeNext = ZipFacade.createZipEntry(name) + zipEntry = ZipEntry(nativeNext) + self.native.putNextEntry(nativeNext) + return zipEntry + + def write(self, data): + native = bytes.toJavaBytes(data) + ZipFacade.writeNative(self.native, native) + + def writeNative(self, data): + ZipFacade.writeNative(self.native, data) + + def writeText(self, text): + ZipFacade.writeText(self.native, text) + + def closeEntry(self): + self.native.closeEntry() + + def close(self): + self.native.finish() + self.native.flush() + self.native.close() + +class ZipEntry: + def __init__(self, native): + self.native = native + + def getName(self): + return self.native.getName() + + def getSize(self): + return self.native.getSize() + + def getCompressedSize(self): + return self.native.getCompressedSize() + + def getTime(self): + return self.native.getTime() + + def getCrc(self): + return self.native.getCrc() + + def getComment(self): + return self.native.getComment() + + def isDirectory(self): + return self.native.isDirectory() + + def isValid(self): + return self.native is not None From 8b320a5b393addbe3fd184e77a67a0352abb2356 Mon Sep 17 00:00:00 2001 From: MrGoblings Date: Tue, 14 Nov 2023 13:22:41 +0200 Subject: [PATCH 2/2] fix: changed the imports from io apis --- .../python-modules/dirigible/io/bytes.py | 65 +++-- .../python-modules/dirigible/io/files.py | 252 ++++++++++-------- .../python-modules/dirigible/io/image.py | 10 +- .../python-modules/dirigible/io/streams.py | 17 ++ .../python-modules/dirigible/io/zip.py | 23 ++ 5 files changed, 228 insertions(+), 139 deletions(-) diff --git a/components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/bytes.py b/components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/bytes.py index 937cca1fe7c..ed9c61fb3c1 100644 --- a/components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/bytes.py +++ b/components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/bytes.py @@ -8,31 +8,40 @@ from java.lang import String, Byte import java.lang.reflect.Array as JArray -from org.eclipse.dirigible.components.api.io import BytesFacade - -def toJavaBytes(bytes): - internalBytes = JArray.newInstance(Byte.TYPE, len(bytes)) - for i in range(len(bytes)): - internalBytes[i] = bytes[i] - return internalBytes - -def toJavaScriptBytes(internalBytes): - bytes = [] - for i in range(internalBytes.length): - bytes.append(internalBytes[i]) - return bytes - -def textToByteArray(text): - javaString = String(text) - native = BytesFacade.textToByteArray(text) - return toJavaScriptBytes(native) - -def byteArrayToText(data): - native = toJavaBytes(data) - return "".join(map(chr, toJavaScriptBytes(native)) - -def intToByteArray(value, byteOrder): - return BytesFacade.intToByteArray(value, byteOrder) - -def byteArrayToInt(data, byteOrder): - return BytesFacade.byteArrayToInt(data, byteOrder) + +import java + +class Bytes: + BytesFacade = java.type('org.eclipse.dirigible.components.api.io') + @staticmethod + def toJavaBytes(bytes): + internalBytes = JArray.newInstance(Byte.TYPE, len(bytes)) + for i in range(len(bytes)): + internalBytes[i] = bytes[i] + return internalBytes + + @staticmethod + def toJavaScriptBytes(internalBytes): + bytes = [] + for i in range(internalBytes.length): + bytes.append(internalBytes[i]) + return bytes + + @staticmethod + def textToByteArray(text): + javaString = String(text) + native = BytesFacade.textToByteArray(text) + return toJavaScriptBytes(native) + + @staticmethod + def byteArrayToText(data): + native = toJavaBytes(data) + return "".join(map(chr, toJavaScriptBytes(native))) + + @staticmethod + def intToByteArray(value, byteOrder): + return BytesFacade.intToByteArray(value, byteOrder) + + @staticmethod + def byteArrayToInt(data, byteOrder): + return BytesFacade.byteArrayToInt(data, byteOrder) diff --git a/components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/files.py b/components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/files.py index 8916a4a9147..1c203f178a5 100644 --- a/components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/files.py +++ b/components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/files.py @@ -10,120 +10,158 @@ import bytes import java -FilesFacade = java.type("org.eclipse.dirigible.components.api.io.FilesFacade") +class Files: + FilesFacade = java.type("org.eclipse.dirigible.components.api.io.FilesFacade") -def exists(path): - return FilesFacade.exists(path) + @staticmethod + def exists(path): + return FilesFacade.exists(path) -def isExecutable(path): - return FilesFacade.isExecutable(path) + @staticmethod + def isExecutable(path): + return FilesFacade.isExecutable(path) -def isReadable(path): - return FilesFacade.isReadable(path) + @staticmethod + def isReadable(path): + return FilesFacade.isReadable(path) -def isWritable(path): - return FilesFacade.isWritable(path) + @staticmethod + def isWritable(path): + return FilesFacade.isWritable(path) -def isHidden(path): - return FilesFacade.isHidden(path) + @staticmethod + def isHidden(path): + return FilesFacade.isHidden(path) -def isDirectory(path): - return FilesFacade.isDirectory(path) + @staticmethod + def isDirectory(path): + return FilesFacade.isDirectory(path) -def isFile(path): - return FilesFacade.isFile(path) + @staticmethod + def isFile(path): + return FilesFacade.isFile(path) -def isSameFile(path1, path2): - return FilesFacade.isSameFile(path1, path2) + @staticmethod + def isSameFile(path1, path2): + return FilesFacade.isSameFile(path1, path2) -def getCanonicalPath(path): - return FilesFacade.getCanonicalPath(path) + @staticmethod + def getCanonicalPath(path): + return FilesFacade.getCanonicalPath(path) -def getName(path): - return FilesFacade.getName(path) - -def getParentPath(path): - return FilesFacade.getParentPath(path) - -def readBytes(path): - native = FilesFacade.readBytes(path) - data = bytes.toPythonBytes(native) - return data - -def readBytesNative(path): - return FilesFacade.readBytes(path) - -def readText(path): - return FilesFacade.readText(path) - -def writeBytes(path, data): - native = bytes.toJavaBytes(data) - FilesFacade.writeBytesNative(path, native) - -def writeBytesNative(path, data): - FilesFacade.writeBytesNative(path, data) - -def writeText(path, text): - FilesFacade.writeText(path, text) - -def getLastModified(path): - return FilesFacade.getLastModified(path) - -def setLastModified(path, time): - FilesFacade.setLastModified(path, time.getMilliseconds()) - -def getOwner(path): - return FilesFacade.getOwner(path) - -def setOwner(path, owner): - FilesFacade.setOwner(path, owner) - -def getPermissions(path): - return FilesFacade.getPermissions(path) - -def setPermissions(path, permissions): - FilesFacade.setPermissions(path, permissions) - -def size(path): - return FilesFacade.size(path) - -def createFile(path): - FilesFacade.createFile(path) - -def createDirectory(path): - FilesFacade.createDirectory(path) - -def copy(source, target): - FilesFacade.copy(source, target) - -def move(source, target): - FilesFacade.move(source, target) - -def deleteFile(path): - FilesFacade.deleteFile(path) - -def deleteDirectory(path, forced): - FilesFacade.deleteDirectory(path, forced) - -def createTempFile(prefix, suffix): - return FilesFacade.createTempFile(prefix, suffix) - -def createTempDirectory(prefix): - return FilesFacade.createTempDirectory(prefix) - -def createInputStream(path): - native = FilesFacade.createInputStream(path) - return streams.InputStream(native) - -def createOutputStream(path): - native = FilesFacade.createOutputStream(path) - return streams.OutputStream(native) - -def traverse(path): - return FilesFacade.traverse(path) - -def list(path): - return list(map(lambda e: e['path'], JSON.parse(FilesFacade.list(path))) - -def find(path, pattern): - return JSON.parse(FilesFacade.find(path, pattern)) + @staticmethod + def getName(path): + return FilesFacade.getName(path) + + @staticmethod + def getParentPath(path): + return FilesFacade.getParentPath(path) + + @staticmethod + def readBytes(path): + native = FilesFacade.readBytes(path) + data = bytes.toPythonBytes(native) + return data + + @staticmethod + def readBytesNative(path): + return FilesFacade.readBytes(path) + + @staticmethod + def readText(path): + return FilesFacade.readText(path) + + @staticmethod + def writeBytes(path, data): + native = bytes.toJavaBytes(data) + FilesFacade.writeBytesNative(path, native) + + @staticmethod + def writeBytesNative(path, data): + FilesFacade.writeBytesNative(path, data) + + @staticmethod + def writeText(path, text): + FilesFacade.writeText(path, text) + + @staticmethod + def getLastModified(path): + return FilesFacade.getLastModified(path) + + @staticmethod + def setLastModified(path, time): + FilesFacade.setLastModified(path, time.getMilliseconds()) + + @staticmethod + def getOwner(path): + return FilesFacade.getOwner(path) + + @staticmethod + def setOwner(path, owner): + FilesFacade.setOwner(path, owner) + + @staticmethod + def getPermissions(path): + return FilesFacade.getPermissions(path) + + @staticmethod + def setPermissions(path, permissions): + FilesFacade.setPermissions(path, permissions) + + @staticmethod + def size(path): + return FilesFacade.size(path) + + @staticmethod + def createFile(path): + FilesFacade.createFile(path) + + @staticmethod + def createDirectory(path): + FilesFacade.createDirectory(path) + + @staticmethod + def copy(source, target): + FilesFacade.copy(source, target) + + @staticmethod + def move(source, target): + FilesFacade.move(source, target) + + @staticmethod + def deleteFile(path): + FilesFacade.deleteFile(path) + + @staticmethod + def deleteDirectory(path, forced): + FilesFacade.deleteDirectory(path, forced) + + @staticmethod + def createTempFile(prefix, suffix): + return FilesFacade.createTempFile(prefix, suffix) + + @staticmethod + def createTempDirectory(prefix): + return FilesFacade.createTempDirectory(prefix) + + @staticmethod + def createInputStream(path): + native = FilesFacade.createInputStream(path) + return streams.InputStream(native) + + @staticmethod + def createOutputStream(path): + native = FilesFacade.createOutputStream(path) + return streams.OutputStream(native) + + @staticmethod + def traverse(path): + return FilesFacade.traverse(path) + + @staticmethod + def list(path): + return list(map(lambda e: e['path'], JSON.parse(FilesFacade.list(path)))) + + @staticmethod + def find(path, pattern): + return JSON.parse(FilesFacade.find(path, pattern)) diff --git a/components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/image.py b/components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/image.py index f6d4b2e44b9..d99dffc08f9 100644 --- a/components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/image.py +++ b/components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/image.py @@ -9,8 +9,10 @@ import streams import java -ImageFacade = java.type("org.eclipse.dirigible.components.api.io.ImageFacade") +class Image: + ImageFacade = java.type("org.eclipse.dirigible.components.api.io.ImageFacade") -def resize(original, imageType, width, height): - native = ImageFacade.resize(original, imageType, width, height) - return streams.InputStream(native) + @staticmethod + def resize(original, imageType, width, height): + native = ImageFacade.resize(original, imageType, width, height) + return streams.InputStream(native) diff --git a/components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/streams.py b/components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/streams.py index 745f8f73e2c..7ba78215499 100644 --- a/components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/streams.py +++ b/components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/streams.py @@ -12,61 +12,78 @@ StreamsFacade = java.type("org.eclipse.dirigible.components.api.io.StreamsFacade") class InputStream: + @staticmethod def __init__(self, native): self.native = native + @staticmethod def read(self): return StreamsFacade.read(self.native) + @staticmethod def readBytes(self): native = StreamsFacade.readBytes(self.native) return bytes.toPythonBytes(native) + @staticmethod def readBytesNative(self): return StreamsFacade.readBytes(self.native) + @staticmethod def readText(self): return StreamsFacade.readText(self.native) + @staticmethod def close(self): StreamsFacade.close(self.native) + @staticmethod def isValid(self): return self.native is not None class OutputStream: + @staticmethod def __init__(self, native): self.native = native + @staticmethod def write(self, byte): StreamsFacade.write(self.native, byte) + @staticmethod def writeBytes(self, data): native = bytes.toJavaBytes(data) StreamsFacade.writeBytes(self.native, native) + @staticmethod def writeBytesNative(self, data): StreamsFacade.writeBytes(self.native, data) + @staticmethod def writeText(self, text): StreamsFacade.writeText(self.native, text) + @staticmethod def close(self): StreamsFacade.close(self.native) + @staticmethod def getBytes(self): native = StreamsFacade.getBytes(self.native) data = bytes.toPythonBytes(native) return data + @staticmethod def getBytesNative(self): native = StreamsFacade.getBytes(self.native) return native + @staticmethod def getText(self): value = StreamsFacade.getText(self.native) return value + @staticmethod def isValid(self): return self.native is not None diff --git a/components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/zip.py b/components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/zip.py index ff870f015db..68091943d2e 100644 --- a/components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/zip.py +++ b/components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/zip.py @@ -9,6 +9,7 @@ import bytes import java + ZipFacade = java.type("org.eclipse.dirigible.components.api.io.ZipFacade") def zip(sourcePath, zipTargetPath): @@ -22,24 +23,30 @@ def createZipInputStream(inputStream): return ZipInputStream(native) class ZipInputStream: + @staticmethod def __init__(self, native): self.native = native + @staticmethod def getNextEntry(self): native = self.native.getNextEntry() zipEntry = ZipEntry(native) return zipEntry + @staticmethod def read(self): native = ZipFacade.readNative(self.native) return bytes.toPythonBytes(native) + @staticmethod def readNative(self): return ZipFacade.readNative(self.native) + @staticmethod def readText(self): return ZipFacade.readText(self.native) + @staticmethod def close(self): self.native.close() @@ -48,57 +55,73 @@ def createZipOutputStream(outputStream): return ZipOutputStream(native) class ZipOutputStream: + @staticmethod def __init__(self, native): self.native = native + @staticmethod def createZipEntry(self, name): nativeNext = ZipFacade.createZipEntry(name) zipEntry = ZipEntry(nativeNext) self.native.putNextEntry(nativeNext) return zipEntry + @staticmethod def write(self, data): native = bytes.toJavaBytes(data) ZipFacade.writeNative(self.native, native) + @staticmethod def writeNative(self, data): ZipFacade.writeNative(self.native, data) + @staticmethod def writeText(self, text): ZipFacade.writeText(self.native, text) + @staticmethod def closeEntry(self): self.native.closeEntry() + @staticmethod def close(self): self.native.finish() self.native.flush() self.native.close() class ZipEntry: + @staticmethod def __init__(self, native): self.native = native + @staticmethod def getName(self): return self.native.getName() + @staticmethod def getSize(self): return self.native.getSize() + @staticmethod def getCompressedSize(self): return self.native.getCompressedSize() + @staticmethod def getTime(self): return self.native.getTime() + @staticmethod def getCrc(self): return self.native.getCrc() + @staticmethod def getComment(self): return self.native.getComment() + @staticmethod def isDirectory(self): return self.native.isDirectory() + @staticmethod def isValid(self): return self.native is not None