-
Notifications
You must be signed in to change notification settings - Fork 34
Added line to replace Carriage Returns with newline #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Kudos, SonarCloud Quality Gate passed! |
|
Hi @dirwin5, thank you for this pull request. Could you give me an example of when the old syntax could be problematic in 9.5.5? I've just tried it in the new version of ICM and it seems to work as expected. Thanks |
|
Personally I would be against this PR. |
|
Hi @dfmore, I've attached an image showing the file exported using the old syntax (left) vs rtc data manually exported from the ICM UI (right) using ICM v9.5.5. There are a lot of blank lines with the old syntax export due to the Using the old syntax with newer versions of ICM, the export seems to follow the format on the right ok, as the exported data seems to have The screenshot shows the exported files opened using notepad on Windows 10. |
|
Mhm.... it could be that ruby replaces all Looking up online it seems there is a line ending character @dirwin5 can you check |
|
Hi @sancarn and @dfmore, sorry for the delayed response, I've been away for a few days. I tried replacing I tested adding
I believe ICM version 9.5.5 (and earlier) uses I have attached output files from both v9.5.5 and v2021.5.0 if you want to inspect the line endings. Note that these two exports are for different model networks so their content is different. Their formatting and line endings are visible however. |
EDIT: I think I misunderstood again... You can't import/export RTC correct? And I'd imagine if you do @dfmore If you could get the version that this change occurred that'd be great, then we can essentially add: if semver(Application.version) > "xxxx.xx.xxxx"
str.gsub(/\r?\n/,"\n")
endto the import script. |
|
Hi @sancarn, this only seems to affect the exported rtc file when using the ruby script. Import seems to be fine with the original code. The main reason I came across this issue is because I was using the ruby script to export rtc data from a model in ICM v9.5.5, and then using that rtc data in a separate external tool. There was a difference in file format which caused issues trying to read the data.
|
|
@dirwin5 I see! Those images really explain the story much better! So essentially Ruby pre 2021 (or pre some version) errornously exported RTC data with
My concern is, if you try to import network = WSApplication.current_network
row_object = network.row_object('hw_rtc',nil)
rtcdata = File.read("path/to/exported_rtc_v9.5.5_manual.rtc")
network.transaction_begin
row_object['rtc_data'] = rtcdata
row_object.write
network.transaction_commitDoes this work as expected? Because if Alternatively you could test: # Test me in ruby 9.5.5
network = WSApplication.current_network
row_object = network.row_object('hw_rtc',nil)
network.transaction_begin
row_object['rtc_data'] = row_object['rtc_data'].gsub(/\r\n/,"\n")
row_object.write
network.transaction_commit
p row_object['rtc_data']My concern/expectation is this might (if it works) accidentally keep Would you be able to test in 9.5.5? and perhaps include the result of the 2nd code (when ran in 9.5.5) in your response. If # Example 1: Export RTC from current network to a text file
if mode == 1
#FIX: Ensure fix line endings to standard ICM spec. Force \r\n line endings to \n. See PR #8.
File.write(path + exported_file, row_object['rtc_data'].gsub(/\r?\n/,"\n"))
puts "File \'#{exported_file}\' exported to path \'#{path}\'"
end
# Example 2: Import RTC from a file into current network
if mode == 2
imported_rtc = File.read(path + imported_file)
network.transaction_begin
#FIX: Version check before import and ensure line endings match spec for ruby at the time. See PR #8.
row_object['rtc_data'] = import_rtc.gsub(/\r?\n/, WSApplication.version <= SOMEVERSION ? "\r\n" : "\n")
row_object.write
network.transaction_commit
puts "RTC imported from file \'#{imported_file}\' on path \'#{path}\'"
end(The above example is mostly unchanged from yours with a small change to mode 2) Alternatively might be able to fix with #FIX: Version check before import and ensure line endings match spec for ruby at the time. See PR #8.
begin
row_object['rtc_data'] = import_rtc
rescue # Attempt with \r\n line endings instead of \n
row_object['rtc_data'] = import_rtc.gsub(/\r?\n/, "\r\n")
end |











rtc_string in ICM v9.5.5 has carriage returns rather than newline characters. Added line to replace these.