Skip to content

Commit 6f476b7

Browse files
support downloading project archive; suppress console window (#145)
Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent 7bde80d commit 6f476b7

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
support downloading project archive; suppress console window

doc/source/user-guide.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ directly to the Workbench server. You should specify the path relative to the
160160
161161
client.upload_file_from_example_repo("pymechanical-integration/agdb/two_pipes.agdb")
162162
163+
There is a convenience function to save the current Workbench project on the server, archive
164+
the project, and then download the project archive to the client.
165+
.. code-block:: python
166+
167+
wb.download_project_archive(archive_name="my_project_archive")
168+
163169
All methods for uploading and downloading files display a progress bar by default. You can
164170
turn off the progress bar with an optional argument:
165171

src/ansys/workbench/core/public_api.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class LaunchWorkbench(ClientWrapper):
108108
def __init__(
109109
self,
110110
show_gui=True,
111-
version="242",
111+
version=None,
112112
client_workdir=None,
113113
server_workdir=None,
114114
host=None,
@@ -118,6 +118,8 @@ def __init__(
118118
self._wmi_connection = None
119119
self._process_id = -1
120120

121+
if not version:
122+
version = "242"
121123
if (
122124
len(version) != 3
123125
or not version.isdigit()
@@ -163,7 +165,7 @@ def __launch_server(self, show_gui, host, version, server_workdir, username, pas
163165
# use forward slash only to avoid escaping as command line argument
164166
server_workdir = server_workdir.replace("\\", "/")
165167
workdir_arg = ",WorkingDirectory='" + server_workdir + "'"
166-
ui_or_not = " -I" if show_gui else " --start-and-wait"
168+
ui_or_not = " -I" if show_gui else " --start-and-wait -nowindow"
167169
command = (
168170
executable
169171
+ ui_or_not

src/ansys/workbench/core/workbench_client.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,28 @@ def download_file(self, file_name, show_progress=True, target_dir=None):
381381
pbar.close()
382382
return file_name
383383

384+
def download_project_archive(self, archive_name, show_progress=True):
385+
"""Create and download the project archive.
386+
387+
Parameters
388+
----------
389+
archive_name : str
390+
Name of the project archive to use, without the file extension.
391+
show_progress : bool, default: True
392+
Whether to show a progress bar during the download.
393+
"""
394+
if not re.match(r"^\w+$", archive_name):
395+
logging.error("archive name should contain only alphanumeric characters")
396+
return
397+
script = f"""import os
398+
wd = GetServerWorkingDirectory()
399+
if os.path.basename(GetProjectFile()).StartsWith("wbnew."):
400+
Save(FilePath=os.path.join(wd, "{archive_name}.wbpj"), Overwrite=True)
401+
Archive(FilePath=os.path.join(wd, "{archive_name}.wbpz"))
402+
"""
403+
self.run_script_string(script)
404+
self.download_file(archive_name + ".wbpz", show_progress=show_progress)
405+
384406
def __python_logging(self, log_level, msg):
385407
"""Log a message with the given log level.
386408

0 commit comments

Comments
 (0)