Skip to content

Commit

Permalink
Merge pull request #29 from ni/peterilberg-log-file-properties
Browse files Browse the repository at this point in the history
Add methods to get/set log file description and test properties.
  • Loading branch information
chadallee authored Apr 25, 2023
2 parents 9680137 + 2bb2d04 commit 9a464f7
Show file tree
Hide file tree
Showing 15 changed files with 287 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Requirements
============
**niflexlogger-automation** has the following requirements:

* FlexLogger 2022 Q2+
* FlexLogger 2023 Q2+
* CPython 3.6 - 3.10. If you do not have Python installed on your computer, go to python.org/downloads to download and install it.

.. _installation_section:
Expand Down
26 changes: 26 additions & 0 deletions examples/Basic/get_log_file_description.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os
import sys

from flexlogger.automation import Application


def main(project_path):
"""Launch FlexLogger, open a project, and get the log file description."""
with Application.launch() as app:
project = app.open_project(path=project_path)
logging_specification = project.open_logging_specification_document()
log_file_description = logging_specification.get_log_file_description()
print("Log file description: " + log_file_description)
print("Press Enter to close the project...")
input()
project.close()
return 0


if __name__ == "__main__":
argv = sys.argv
if len(argv) < 2:
print("Usage: %s <path of project to open>" % os.path.basename(__file__))
sys.exit()
project_path_arg = argv[1]
sys.exit(main(project_path_arg))
28 changes: 28 additions & 0 deletions examples/Basic/get_test_properties.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import os
import sys

from flexlogger.automation import Application


def main(project_path):
"""Launch FlexLogger, open a project, and get all test properties."""
with Application.launch() as app:
project = app.open_project(path=project_path)
logging_specification = project.open_logging_specification_document()
test_properties = logging_specification.get_test_properties()
for test_property in test_properties:
prompt = "(prompt on start)" if test_property.prompt_on_start else ""
print(f'{test_property.name}: {test_property.value} {prompt}')
print("Press Enter to close the project...")
input()
project.close()
return 0


if __name__ == "__main__":
argv = sys.argv
if len(argv) < 2:
print("Usage: %s <path of project to open>" % os.path.basename(__file__))
sys.exit()
project_path_arg = argv[1]
sys.exit(main(project_path_arg))
3 changes: 1 addition & 2 deletions examples/Basic/set_data_rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


def main(project_path):
"""Launch FlexLogger, open a project, and sets the data rate values."""
"""Launch FlexLogger, open a project, and set the data rate values."""
with Application.launch() as app:
project = app.open_project(path=project_path)
channel_specification = project.open_channel_specification_document()
Expand All @@ -29,7 +29,6 @@ def main(project_path):

print("Data rate set. Press Enter to save and close the project...")
input()
project.save()
project.close()
return 0

Expand Down
26 changes: 26 additions & 0 deletions examples/Basic/set_log_file_description.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os
import sys

from flexlogger.automation import Application


def main(project_path):
"""Launch FlexLogger, open a project, and set the log file description."""
with Application.launch() as app:
project = app.open_project(path=project_path)
log_file_description = input("Enter the log file description: ")
logging_specification = project.open_logging_specification_document()
logging_specification.set_log_file_description(log_file_description)
print("Log file description set. Press Enter to close the project...")
input()
project.close()
return 0


if __name__ == "__main__":
argv = sys.argv
if len(argv) < 2:
print("Usage: %s <path of project to open>" % os.path.basename(__file__))
sys.exit()
project_path_arg = argv[1]
sys.exit(main(project_path_arg))
36 changes: 36 additions & 0 deletions examples/Basic/set_test_properties.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import os
import sys

from flexlogger.automation import Application
from flexlogger.automation import TestProperty


def main(project_path):
"""Launch FlexLogger, open a project, and set test properties."""
with Application.launch() as app:
project = app.open_project(path=project_path)
logging_specification = project.open_logging_specification_document()

test_properties = []
while True:
name = input("Enter the name of the test property to set the value of (empty line to exit): ")
if name == "":
break
value = input("Enter the test property value: ")
prompt_on_start = input("Enter if you want to prompt on start (y/n): ") == "y"
test_properties.append(TestProperty(name, value, prompt_on_start))

logging_specification.set_test_properties(test_properties)
print("Press Enter to close the project...")
input()
project.close()
return 0


if __name__ == "__main__":
argv = sys.argv
if len(argv) < 2:
print("Usage: %s <path of project to open>" % os.path.basename(__file__))
sys.exit()
project_path_arg = argv[1]
sys.exit(main(project_path_arg))
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package national_instruments.flex_logger.automation.protocols;

import "DiagramSdk/Automation/DiagramSdk.Automation.Protocols/Identifiers.proto";
import "google/protobuf/empty.proto";

// Service interface for a server side logging specification document.
service LoggingSpecificationDocument {
Expand All @@ -14,8 +15,14 @@ service LoggingSpecificationDocument {
rpc GetLogFileName(GetLogFileNameRequest) returns (GetLogFileNameResponse) {}
// RPC call to set the log file name
rpc SetLogFileName(SetLogFileNameRequest) returns (SetLogFileNameResponse) {}
// RPC call to get the description
rpc GetLogFileDescription(GetLogFileDescriptionRequest) returns (GetLogFileDescriptionResponse) {}
// RPC call to set the description
rpc SetLogFileDescription(SetLogFileDescriptionRequest) returns (google.protobuf.Empty) {}
// RPC call to get all test properties
rpc GetTestProperties(GetTestPropertiesRequest) returns (GetTestPropertiesResponse) {}
// RPC call to set all test properties
rpc SetTestProperties(SetTestPropertiesRequest) returns (google.protobuf.Empty) {}
// RPC call to get a specific test property
rpc GetTestProperty(GetTestPropertyRequest) returns (GetTestPropertyResponse) {}
// RPC call to set a specific test property
Expand Down Expand Up @@ -68,14 +75,34 @@ message GetLogFileNameResponse {
message SetLogFileNameRequest {
// The id for the logging specification document
national_instruments.diagram_sdk.automation.protocols.ElementIdentifier document_identifier = 1;
// The log file base path
// The log file name
string log_file_name = 2;
}

// Response object for a set log file name
message SetLogFileNameResponse {
}

// Request object for getting the log file description
message GetLogFileDescriptionRequest {
// The id for the logging specification document
national_instruments.diagram_sdk.automation.protocols.ElementIdentifier document_identifier = 1;
}

// Response object for a get log file description request
message GetLogFileDescriptionResponse {
// The log file description
string log_file_description = 1;
}

// Request object for setting the log file description
message SetLogFileDescriptionRequest {
// The id for the logging specification document
national_instruments.diagram_sdk.automation.protocols.ElementIdentifier document_identifier = 1;
// The log file description
string log_file_description = 2;
}

// Message that defines an individual test property
message TestProperty {
string property_name = 1;
Expand All @@ -95,6 +122,14 @@ message GetTestPropertiesResponse {
repeated TestProperty test_properties = 1;
}

// Request object for setting all test properties
message SetTestPropertiesRequest {
// The id for the logging specification document
national_instruments.diagram_sdk.automation.protocols.ElementIdentifier document_identifier = 1;
// The test properties for the logging specification document. Can be empty.
repeated TestProperty test_properties = 2;
}

// Request object for getting a specific test property
message GetTestPropertyRequest {
// The id for the logging specification document
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def _get_version(name: str) -> str:
script_dir = os.path.dirname(os.path.realpath(__file__))
script_dir = os.path.join(script_dir, name)
if not os.path.exists(os.path.join(script_dir, "VERSION")):
version = "0.1.4"
version = "0.1.5"
else:
with open(os.path.join(script_dir, "VERSION"), "r") as version_file:
version = version_file.read().rstrip()
Expand Down
73 changes: 73 additions & 0 deletions src/flexlogger/automation/_logging_specification_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,47 @@ def set_log_file_name(self, log_file_name: str) -> None:
self._raise_if_application_closed()
raise FlexLoggerError("Failed to set log file name") from error

def get_log_file_description(self) -> str:
"""Get the log file description.
Returns:
The description of the log file.
Raises:
FlexLoggerError: if getting the log file description fails.
"""
stub = LoggingSpecificationDocument_pb2_grpc.LoggingSpecificationDocumentStub(self._channel)
try:
response = stub.GetLogFileDescription(
LoggingSpecificationDocument_pb2.GetLogFileDescriptionRequest(
document_identifier=self._identifier
)
)
return response.log_file_description
except (RpcError, ValueError) as error:
self._raise_if_application_closed()
raise FlexLoggerError("Failed to get log file description") from error

def set_log_file_description(self, log_file_description: str) -> None:
"""Set the log file description.
Args:
log_file_description: The log file description.
Raises:
FlexLoggerError: if setting the log file description fails.
"""
stub = LoggingSpecificationDocument_pb2_grpc.LoggingSpecificationDocumentStub(self._channel)
try:
stub.SetLogFileDescription(
LoggingSpecificationDocument_pb2.SetLogFileDescriptionRequest(
document_identifier=self._identifier, log_file_description=log_file_description
)
)
except (RpcError, ValueError) as error:
self._raise_if_application_closed()
raise FlexLoggerError("Failed to set log file description") from error

def _convert_to_test_property(
self, test_property: LoggingSpecificationDocument_pb2.TestProperty
) -> TestProperty:
Expand All @@ -166,6 +207,15 @@ def _convert_to_test_property(
test_property.prompt_on_start,
)

def _convert_from_test_property(
self, test_property: TestProperty
) -> LoggingSpecificationDocument_pb2.TestProperty:
return LoggingSpecificationDocument_pb2.TestProperty(
property_name=test_property.name,
property_value=test_property.value,
prompt_on_start=test_property.prompt_on_start,
)

def get_test_properties(self) -> List[TestProperty]:
"""Get all test properties.
Expand All @@ -187,6 +237,29 @@ def get_test_properties(self) -> List[TestProperty]:
self._raise_if_application_closed()
raise FlexLoggerError("Failed to get test properties") from error

def set_test_properties(self, test_properties: List[TestProperty]) -> None:
"""Set test properties.
Args:
test_properties: A list of test properties to add or modify on this document.
Raises:
FlexLoggerError: if setting the test properties fails.
"""
if len(test_properties) == 0:
return
stub = LoggingSpecificationDocument_pb2_grpc.LoggingSpecificationDocumentStub(self._channel)
try:
stub.SetTestProperties(
LoggingSpecificationDocument_pb2.SetTestPropertiesRequest(
document_identifier=self._identifier,
test_properties=[self._convert_from_test_property(x) for x in test_properties]
)
)
except (RpcError, ValueError) as error:
self._raise_if_application_closed()
raise FlexLoggerError("Failed to set test properties") from error

def get_test_property(self, test_property_name: str) -> TestProperty:
"""Get the test property with the specified name.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<SourceFile Checksum="5844C38F9040070E4918066590AA245E615CB0C06EB6175AB1C7575CE2FC578CE58C54B38CC9AF405888291B70E8140AD86563CA48FB09B6ACA6462B33902A46" Timestamp="1D665F58F6AD0C1" xmlns="http://www.ni.com/PlatformFramework">
<SourceFile Checksum="D683DC20688C6F7507CD9790605353F3EAB65D82993FDFAEBBD45D660903FF14EB8254B1FB4E8E938A7B0625082C552071C918DC6DF155B958D4D9ABB3764736" Timestamp="1D94DB50B56411F" xmlns="http://www.ni.com/PlatformFramework">
<SourceModelFeatureSet>
<ParsableNamespace AssemblyFileVersion="8.3.0.2028" FeatureSetName="Lumberjack Core" Name="http://www.ni.com/Lumberjack.Core" OldestCompatibleVersion="8.1.0.49152" Version="8.1.0.49152" />
<ParsableNamespace AssemblyFileVersion="8.3.0.2028" FeatureSetName="Editor" Name="http://www.ni.com/PlatformFramework" OldestCompatibleVersion="8.1.0.49152" Version="8.1.0.49152" />
<ApplicationVersionInfo Build="8.3.0.2028" Name="FlexLogger" Version="20.3.0.0" />
<ParsableNamespace AssemblyFileVersion="9.8.0.613" FeatureSetName="Lumberjack Core" Name="http://www.ni.com/Lumberjack.Core" OldestCompatibleVersion="9.6.0.49152" Version="9.6.0.49152" />
<ParsableNamespace AssemblyFileVersion="9.8.0.613" FeatureSetName="Editor" Name="http://www.ni.com/PlatformFramework" OldestCompatibleVersion="8.1.0.49152" Version="8.1.0.49152" />
<ApplicationVersionInfo Build="9.8.0.613" Name="FlexLogger" Version="23.0.0.0" />
</SourceModelFeatureSet>
<LoggingSpecification xmlns="http://www.ni.com/Lumberjack.Core">
<LoggingConfigurationModel Id="3b412b908301474587f70def16479b5b">
<ProcessingElementModelOwner Id="646caa43f52446f7b6cf39e7b9d1088a">
<TriggeredLoggingProvider Id="72313a7a17de4ed6bb1b93b0e6f8099e" ModelTypeId="[string]CBA104E4-2D21-4AC7-915B-D7DCC1243DCE" StartTime="2020-07-29T17:12:02.774938699999999999951973139733496509506949223577976226806640625-05:00" />
<TdmsLoggingProvider DataReductionStrategy="Decimate" Id="19fe41c4dd6f4802a31edc115012cdc0" LogFileBasePath="&quot;C:\\MyDataGoesHere&quot;" LogFileName="MyData.tdms" ModelTypeId="[string]59163356-411F-436B-A6B6-82FB1EFB19E1">
<TriggeredLoggingProvider Id="72313a7a17de4ed6bb1b93b0e6f8099e" ModelTypeId="[string]CBA104E4-2D21-4AC7-915B-D7DCC1243DCE" StartTime="2020-07-30T00:12:02.774938699999999999951973139733496509506949223577976226806640625+02:00" />
<TdmsLoggingProvider DataReductionStrategy="Decimate" Id="19fe41c4dd6f4802a31edc115012cdc0" LogFileBackupPath="&quot;C:\\Users\\peteri\\Documents\\FlexLogger\\data\\backups&quot;" LogFileBasePath="&quot;C:\\MyDataGoesHere&quot;" LogFileDescription="This is the description of the log file." LogFileName="MyData.tdms" ModelTypeId="[string]59163356-411F-436B-A6B6-82FB1EFB19E1">
<UserDefinedMetadata Id="894f64eb8d574af2949ab9dd4b5f0764">
<UserDefinedMetadataItem DataType="String" Id="ca719d29575b42e99c5549d5847196a2" Name="Operator">
<p.Value>bparrott</p.Value>
Expand Down
Loading

0 comments on commit 9a464f7

Please sign in to comment.