Skip to content

Commit

Permalink
Merge pull request #30 from ni/get_project_name
Browse files Browse the repository at this point in the history
Enable users to get the project name from the python API
  • Loading branch information
ccaltagi authored May 31, 2023
2 parents 9a464f7 + b243b01 commit e2d222b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/Basic/get_project_file_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def main(project_path):
with Application.launch() as app:
project = app.open_project(path=project_path)
print("Project file path: " + str(project.project_file_path))
print("Project name: " + project.project_name)
print("Press Enter to close the project...")
input()
project.close()
Expand Down
11 changes: 11 additions & 0 deletions src/flexlogger/automation/_project.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os.path
import pathlib
from typing import Callable
from typing import Optional
Expand Down Expand Up @@ -175,3 +176,13 @@ def project_file_path(self) -> Optional[pathlib.Path]:
except (RpcError, ValueError) as error:
self._raise_if_application_closed()
raise FlexLoggerError("Failed to get project file path") from error

@property
def project_name(self) -> Optional[str]:
"""Get the project name
Returns: The project name if the file path exists, None otherwise
"""
project_path = self.project_file_path

return os.path.basename(os.path.splitext(project_path)[0])

0 comments on commit e2d222b

Please sign in to comment.