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..ed9c61fb3c1 --- /dev/null +++ b/components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/bytes.py @@ -0,0 +1,47 @@ +# 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 + +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 new file mode 100644 index 00000000000..1c203f178a5 --- /dev/null +++ b/components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/files.py @@ -0,0 +1,167 @@ +# 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 + +class Files: + FilesFacade = java.type("org.eclipse.dirigible.components.api.io.FilesFacade") + + @staticmethod + def exists(path): + return FilesFacade.exists(path) + + @staticmethod + def isExecutable(path): + return FilesFacade.isExecutable(path) + + @staticmethod + def isReadable(path): + return FilesFacade.isReadable(path) + + @staticmethod + def isWritable(path): + return FilesFacade.isWritable(path) + + @staticmethod + def isHidden(path): + return FilesFacade.isHidden(path) + + @staticmethod + def isDirectory(path): + return FilesFacade.isDirectory(path) + + @staticmethod + def isFile(path): + return FilesFacade.isFile(path) + + @staticmethod + def isSameFile(path1, path2): + return FilesFacade.isSameFile(path1, path2) + + @staticmethod + def getCanonicalPath(path): + return FilesFacade.getCanonicalPath(path) + + @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 new file mode 100644 index 00000000000..d99dffc08f9 --- /dev/null +++ b/components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/image.py @@ -0,0 +1,18 @@ +# 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 + +class Image: + ImageFacade = java.type("org.eclipse.dirigible.components.api.io.ImageFacade") + + @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 new file mode 100644 index 00000000000..7ba78215499 --- /dev/null +++ b/components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/streams.py @@ -0,0 +1,115 @@ +# 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: + @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 + +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..68091943d2e --- /dev/null +++ b/components/api/api-modules-python/src/main/resources/META-INF/dirigible/python-modules/dirigible/io/zip.py @@ -0,0 +1,127 @@ +# 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: + @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() + +def createZipOutputStream(outputStream): + native = ZipFacade.createZipOutputStream(outputStream.native) + 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