{ "cells": [ { "cell_type": "markdown", "id": "aececd27", "metadata": { "papermill": { "duration": 0.001322, "end_time": "2026-03-19T15:28:16.868028", "exception": false, "start_time": "2026-03-19T15:28:16.866706", "status": "completed" }, "tags": [] }, "source": [ "(Extract Log File Example)=\n", "# Extract Log File Script Examples" ] }, { "cell_type": "markdown", "id": "8f03602b", "metadata": { "papermill": { "duration": 0.001233, "end_time": "2026-03-19T15:28:16.870892", "exception": false, "start_time": "2026-03-19T15:28:16.869659", "status": "completed" }, "tags": [] }, "source": [ "Download the [ExampleModel.fez](https://github.com/Rocscience/rs2-scripting/blob/main/docs/example_code/example_models/ExampleModel.fez) for this example." ] }, { "cell_type": "code", "execution_count": 1, "id": "efd68734", "metadata": { "execution": { "iopub.execute_input": "2026-03-19T15:28:16.874998Z", "iopub.status.busy": "2026-03-19T15:28:16.874662Z", "iopub.status.idle": "2026-03-19T15:28:16.887580Z", "shell.execute_reply": "2026-03-19T15:28:16.885804Z" }, "papermill": { "duration": 0.01711, "end_time": "2026-03-19T15:28:16.889232", "exception": false, "start_time": "2026-03-19T15:28:16.872122", "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Extracted File Path(s):\n", "C:\\Users\\GraceHu\\source\\repos\\RS2_Python_Client_Library\\docs\\example_code\\ExampleModel.lot\n", "C:\\Users\\GraceHu\\source\\repos\\RS2_Python_Client_Library\\docs\\example_code\\ExampleModel.log\n" ] } ], "source": [ "import os\n", "import zipfile\n", "\n", "def extract_files_from_fez(filePath, file_extensions):\n", " \"\"\"\n", " Extract specified file types from a .fez file.\n", "\n", " This function takes the path to a .fez file and a list of file extensions.\n", " It extracts files matching the given extensions from the .fez file without \n", " extracting the entire contents. The extracted file paths are returned in a list.\n", " \"\"\"\n", "\n", " all_extract_file_path = []\n", " with zipfile.ZipFile(filePath, 'r') as zip_ref:\n", " # Find all files in the zip that match the extensions\n", " extract_files = [f for f in zip_ref.namelist() if any(f.endswith(ext) for ext in file_extensions)]\n", "\n", " # If files are found, return the file path\n", " if extract_files:\n", " for file in extract_files:\n", " # extract the file with specified extension without unzipping the RS2 file\n", " zip_ref.extract(file, current_dir)\n", " \n", " # get the extracted file path \n", " extract_file_path = os.path.join(current_dir, file)\n", " all_extract_file_path.append(extract_file_path)\n", " \n", " return all_extract_file_path\n", " \n", "current_dir = os.path.dirname(os.path.abspath(\"\"))\n", "file_path = rf\"{current_dir}\\example_models\\ExampleModel.fez\"\n", "\n", "# Log files' file extensions\n", "log_extensions = {\".log\", \".low\", \".lot\"}\n", "\n", "# Call the function to extract log files\n", "file_paths = extract_files_from_fez(file_path, log_extensions)\n", "print(\"Extracted File Path(s):\")\n", "print(*file_paths, sep = '\\n')" ] } ], "metadata": { "kernelspec": { "display_name": "myenv", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.13.0" }, "papermill": { "default_parameters": {}, "duration": 4.100688, "end_time": "2026-03-19T15:28:19.680590", "environment_variables": {}, "exception": null, "input_path": "C:\\Users\\GraceHu\\source\\repos\\RS2_Python_Client_Library\\docs\\example_code\\support_functions\\extract_log_file_script_examples.ipynb", "output_path": "C:\\Users\\GraceHu\\source\\repos\\RS2_Python_Client_Library\\docs\\example_code\\support_functions\\extract_log_file_script_examples.ipynb", "parameters": {}, "start_time": "2026-03-19T15:28:15.579902", "version": "2.6.0" } }, "nbformat": 4, "nbformat_minor": 5 }