From 9b67a15fd1844d5f6a2a7b98b43a7791a2e77175 Mon Sep 17 00:00:00 2001 From: Andreas Legner Date: Thu, 16 Apr 2026 12:32:00 +0200 Subject: [PATCH] Fixes --- README.md | 151 +++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 116 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index c86645d..8fe6b63 100644 --- a/README.md +++ b/README.md @@ -27,48 +27,135 @@ Installation Quickstart ```python -from os.path import join, dirname +import json +from os.path import join import os from dotenv import load_dotenv from iLibrary import Library -# Load ENV file and get the connection settings -dotenv_path = join(dirname(__file__), '.env') +#load ENV file and get the Connection Settings +dotenv_path = join('.env') load_dotenv(dotenv_path) DB_DRIVER = os.environ.get("DB_DRIVER") DB_USER = os.environ.get("DB_USER") DB_PASSWORD = os.environ.get("DB_PASSWORD") DB_SYSTEM = os.environ.get("DB_SYSTEM") -with Library(DB_USER, DB_PASSWORD, DB_SYSTEM, DB_DRIVER) as lib: - print(lib.getLibraryInfo('QGPL', wantJson=True)) - print(lib.getFileInfo('QGPL')) -``` -Save a library to SAVF and optionally download it -```python -from os.path import dirname - -with Library(DB_USER, DB_PASSWORD, DB_SYSTEM, DB_DRIVER) as lib: - ok = lib.saveLibrary( - library='MYLIB', - saveFileName='MYLIBSAVE', - description='Backup', - localPath=dirname(__file__), - remPath='/home/MYUSER/', - getZip=True - ) - print('Saved:', ok) + + +# ---------------------------------------------------- +# make a Savefile from a library +# ---------------------------------------------------- +def getSaveFile(): + + # Flag to enable/disable Mapepire connection mode + USE_MAPEPIRE = False + + + PORT = 22 #for the Pub400.com use the Port 2222 + LIBRARY = '' + SAVE_FILE_NAME = 'FOO' + LOCAL_PATH = 'YOUR_LOCAL_PATH' + DESCRIPTION = 'Saved from iLibrary' + try: + # Establish a connection to the IBM i system using the User class + # The context manager ensures the connection is properly opened and closed + with Library(DB_USER, DB_PASSWORD, DB_SYSTEM, DB_DRIVER, mapepire=USE_MAPEPIRE) as l: + + # Call the method to save the Library + # The result is returned as a JSON string + raw_result = l.saveLibrary( + library=LIBRARY, + saveFileName=SAVE_FILE_NAME, + description=DESCRIPTION, + localPath=LOCAL_PATH, + port=PORT + ) + + # Parse the JSON string into a Python object (list/dictionary) + data = json.loads(raw_result) + + # Pretty-print the parsed data with indentation for readability + print(json.dumps(data, indent=4)) + + # Handle any exceptions that occur during connection or data retrieval + except Exception as e: + # Print the error message for debugging + print(e) + + + +# ---------------------------------------------------- +# Get library information about all libraries from +# IBM i Server using iLibrary +# ---------------------------------------------------- +def getAllLibraries(): + # Flag to enable/disable Mapepire connection mode + USE_MAPEPIRE = False + + try: + # Establish a connection to the IBM i system using the User class + # The context manager ensures the connection is properly opened and closed + with Library(DB_USER, DB_PASSWORD, DB_SYSTEM, DB_DRIVER, mapepire=USE_MAPEPIRE) as l: + + # Call the method to get all libraries on the system + # The result is returned as a JSON string + raw_result = l.getAllLibraries() + + # Parse the JSON string into a Python object (list/dictionary) + data = json.loads(raw_result) + + # Pretty-print the parsed data with indentation for readability + print(json.dumps(data, indent=4)) + + # Handle any exceptions that occur during connection or data retrieval + except Exception as e: + # Print the error message for debugging + print(e) + + + + +# ---------------------------------------------------- +# Get single library information from IBM i Server +# using iLibrary +# ---------------------------------------------------- +def getSingleLibraryInfo(): + # Flag to enable/disable Mapepire connection mode + USE_MAPEPIRE = False + LIBRARY = '' + try: + # Establish a connection to the IBM i system using the User class + # The context manager ensures the connection is properly opened and closed + with Library(DB_USER, DB_PASSWORD, DB_SYSTEM, DB_DRIVER, mapepire=USE_MAPEPIRE) as l: + + # Call the method to show singe information about the Library + # The result is returned as a JSON string + raw_result = l.getLibraryInfo( + library=LIBRARY + ) + + # Parse the JSON string into a Python object (list/dictionary) + data = json.loads(raw_result) + + # Pretty-print the parsed data with indentation for readability + print(json.dumps(data, indent=4)) + + # Handle any exceptions that occur during connection or data retrieval + except Exception as e: + # Print the error message for debugging + print(e) + +if __name__ == '__main__': + getSaveFile() + getAllLibraries() + getSingleLibraryInfo() ``` -API overview -- Library(db_user, db_password, db_host, db_driver) - - __enter__ / __exit__ for connection lifecycle - - iclose(): manually close the connection -- getLibraryInfo(library: str, wantJson: bool = True) -> str | tuple -- getFileInfo(library: str, qFiles: bool = False) -> str -- saveLibrary(library: str, saveFileName: str, ..., getZip: bool = False, ...) -> bool -- removeFile(library: str, saveFileName: str) -> bool + +More Examples: +- see the folder Examples Configuration - Environment variables expected: @@ -77,12 +164,6 @@ Configuration - DB_PASSWORD - DB_SYSTEM -Documentation -- Installation guide: [[docs/installation.md]] -- Usage examples: [[docs/usage.md]] -- Full API reference: [[docs/api.md]] -- Troubleshooting: [[docs/troubleshooting.md]] - Contributing - Please run tests or the sample script before submitting changes.