|
28 | 28 | import os |
29 | 29 | import urllib.request |
30 | 30 | import warnings |
| 31 | +from typing import Union |
| 32 | + |
31 | 33 | from ansys.dpf.core.examples.examples import find_files |
32 | 34 |
|
33 | 35 | EXAMPLE_REPO = "https://github.com/ansys/example-data/raw/master/" |
34 | 36 |
|
| 37 | +GITHUB_SOURCE_URL = ( |
| 38 | + "https://github.com/ansys/pydpf-core/raw/" |
| 39 | + "master/doc/source/examples/07-python-operators/plugins/" |
| 40 | +) |
| 41 | + |
35 | 42 |
|
36 | 43 | def delete_downloads(verbose=True): |
37 | 44 | """Delete all downloaded examples to free space or update the files""" |
@@ -1993,3 +2000,142 @@ def find_distributed_msup_folder( |
1993 | 2000 | return_local_path, |
1994 | 2001 | ) |
1995 | 2002 | return os.path.dirname(path) |
| 2003 | + |
| 2004 | + |
| 2005 | +def download_average_filter_plugin( |
| 2006 | + should_upload: bool = True, server=None, return_local_path=False |
| 2007 | +) -> Union[str, None]: |
| 2008 | + """Make the plugin available server side, if the server is remote the plugin is uploaded |
| 2009 | + server side. Returns the path of the plugin folder. |
| 2010 | +
|
| 2011 | + Parameters |
| 2012 | + ---------- |
| 2013 | + should_upload: |
| 2014 | + Whether the file should be uploaded server side when the server is remote. |
| 2015 | + server: |
| 2016 | + Server with channel connected to the remote or local instance. When |
| 2017 | + ``None``, attempts to use the global server. |
| 2018 | + return_local_path: |
| 2019 | + If ``True``, the local path is returned as is, without uploading, nor searching |
| 2020 | + for mounted volumes. |
| 2021 | +
|
| 2022 | + Returns |
| 2023 | + ------- |
| 2024 | + str |
| 2025 | + Path to the plugin folder. |
| 2026 | +
|
| 2027 | + Examples |
| 2028 | + -------- |
| 2029 | +
|
| 2030 | + >>> from ansys.dpf.core import examples |
| 2031 | + >>> path = examples.download_average_filter_plugin() |
| 2032 | +
|
| 2033 | + """ |
| 2034 | + file_list = [ |
| 2035 | + "average_filter_plugin/__init__.py", |
| 2036 | + "average_filter_plugin/operators.py", |
| 2037 | + "average_filter_plugin/operators_loader.py", |
| 2038 | + "average_filter_plugin/common.py", |
| 2039 | + ] |
| 2040 | + return _retrieve_plugin( |
| 2041 | + file_list=file_list, |
| 2042 | + should_upload=should_upload, |
| 2043 | + server=server, |
| 2044 | + return_local_path=return_local_path, |
| 2045 | + ) |
| 2046 | + |
| 2047 | + |
| 2048 | +def download_gltf_plugin( |
| 2049 | + should_upload: bool = True, server=None, return_local_path=False |
| 2050 | +) -> Union[str, None]: |
| 2051 | + """Make the plugin available server side, if the server is remote the plugin is uploaded |
| 2052 | + server side. Returns the path of the plugin folder. |
| 2053 | +
|
| 2054 | + Parameters |
| 2055 | + ---------- |
| 2056 | + should_upload: |
| 2057 | + Whether the file should be uploaded server side when the server is remote. |
| 2058 | + server: |
| 2059 | + Server with channel connected to the remote or local instance. When |
| 2060 | + ``None``, attempts to use the global server. |
| 2061 | + return_local_path: |
| 2062 | + If ``True``, the local path is returned as is, without uploading, nor searching |
| 2063 | + for mounted volumes. |
| 2064 | +
|
| 2065 | + Returns |
| 2066 | + ------- |
| 2067 | + str |
| 2068 | + Path to the plugin folder. |
| 2069 | +
|
| 2070 | + Examples |
| 2071 | + -------- |
| 2072 | +
|
| 2073 | + >>> from ansys.dpf.core import examples |
| 2074 | + >>> path = examples.download_gltf_plugin() |
| 2075 | +
|
| 2076 | + """ |
| 2077 | + file_list = [ |
| 2078 | + "gltf_plugin.xml", |
| 2079 | + "gltf_plugin/__init__.py", |
| 2080 | + "gltf_plugin/operators.py", |
| 2081 | + "gltf_plugin/operators_loader.py", |
| 2082 | + "gltf_plugin/requirements.txt", |
| 2083 | + "gltf_plugin/gltf_export.py", |
| 2084 | + "gltf_plugin/texture.png", |
| 2085 | + ] |
| 2086 | + return _retrieve_plugin( |
| 2087 | + file_list=file_list, |
| 2088 | + should_upload=should_upload, |
| 2089 | + server=server, |
| 2090 | + return_local_path=return_local_path, |
| 2091 | + ) |
| 2092 | + |
| 2093 | + |
| 2094 | +def download_easy_statistics( |
| 2095 | + should_upload: bool = True, server=None, return_local_path=False |
| 2096 | +) -> Union[str, None]: |
| 2097 | + """Make the plugin available server side, if the server is remote the plugin is uploaded |
| 2098 | + server side. Returns the path of the plugin folder. |
| 2099 | +
|
| 2100 | + Parameters |
| 2101 | + ---------- |
| 2102 | + should_upload: |
| 2103 | + Whether the file should be uploaded server side when the server is remote. |
| 2104 | + server: |
| 2105 | + Server with channel connected to the remote or local instance. When |
| 2106 | + ``None``, attempts to use the global server. |
| 2107 | + return_local_path: |
| 2108 | + If ``True``, the local path is returned as is, without uploading, nor searching |
| 2109 | + for mounted volumes. |
| 2110 | +
|
| 2111 | + Returns |
| 2112 | + ------- |
| 2113 | + str |
| 2114 | + Path to the plugin folder. |
| 2115 | +
|
| 2116 | + Examples |
| 2117 | + -------- |
| 2118 | +
|
| 2119 | + >>> from ansys.dpf.core import examples |
| 2120 | + >>> path = examples.download_easy_statistics() |
| 2121 | +
|
| 2122 | + """ |
| 2123 | + file_name = "easy_statistics.py" |
| 2124 | + EXAMPLE_FILE = GITHUB_SOURCE_URL + file_name |
| 2125 | + operator_file_path = _retrieve_file( |
| 2126 | + EXAMPLE_FILE, filename=file_name, directory="python_plugins" |
| 2127 | + ) |
| 2128 | + return find_files(operator_file_path, should_upload, server, return_local_path) |
| 2129 | + |
| 2130 | + |
| 2131 | +def _retrieve_plugin( |
| 2132 | + file_list: list[str], should_upload: bool = True, server=None, return_local_path=False |
| 2133 | +) -> Union[str, None]: |
| 2134 | + path = None |
| 2135 | + for file in file_list: |
| 2136 | + EXAMPLE_FILE = GITHUB_SOURCE_URL + file |
| 2137 | + operator_file_path = _retrieve_file(EXAMPLE_FILE, file, directory="python_plugins") |
| 2138 | + path = os.path.dirname( |
| 2139 | + find_files(operator_file_path, should_upload, server, return_local_path) |
| 2140 | + ) |
| 2141 | + return path |
0 commit comments