How to read values from property file using innosetup? - inno-setup

I'm trying to read values from demo.properties file using innnosetup.Here is my demo.properties file hibernate.connection.username=James
hibernate.connection.password=Jack
hibernate.connection.url=jdbc:jtds:sqlserver://8080/clientDB
hibernate.connection.driver_class=net.sourceforge.jtds.jdbc.Driver
I want to read this file and show values as James,Jack and 8080 in user interface.
Can anybody guide me how to get only those particular values?

Here's a guide:
Use Pascal-Script in the [code] section
Work with LoadStringsFromFile() (http://www.jrsoftware.org/ishelp/index.php?topic=isxfunc_loadstringsfromfile) to get the file content.
Iterate over the lines using a for loop
Use Pos() (http://www.jrsoftware.org/ishelp/topic_isxfunc_pos.htm) to find the position of the = sign
Use Copy() (http://www.jrsoftware.org/ishelp/topic_isxfunc_copy.htm) extract key and value from the current line using the position of =
In case you need more functions take a look here: http://www.jrsoftware.org/ishelp/index.php?topic=scriptfunctions
A problem close to yours has been solved here: Find and read specific string from config file with Pascal Script in Inno Setup

Related

Matlab writematrix in Excel gives error: Name cannot be the same as built-in name

I want to copy an Excel file to a different path through Matlab and then write in it also using Matlab. Somehow I get the error: Name cannot be the same as built-in name.
As I want to write multiple times in the file, I don't want to solve this problem manuelly each time, I want the code to run through without me having to do something constantly.
Is there any way I can solve this problem all at once through code? Does this happen because I copy the Excel file first?
The code looks like this:
path_source_template1 = 'Blabla1\Template1.xlsx';
timestamp = datestr(now);
timestamp = strrep(timestamp, ':', '-');
timestamp = strrep(timestamp, ' ', '-');
path_output = fullfile('Blabla2\',timestamp);
mkdir(fullfile(path_output));
path_output_template1 = strcat(path_output,'\Template1.xlsx');
copyfile(path_source_template1,path_output_template1);
Then I want to write in the Template1.xlsx:
writematrix(test,path_output_template1,'Sheet','Test','Range','A1',UseExcel=true,AutoFitWidth=false);
Then I get this error:
enter image description here
The input to the writematrix file uses the name, value format, so in this line:
writematrix(test,path_output_template1,'Sheet','Test','Range','A1',UseExcel=true,AutoFitWidth=false);
you should have:
..., 'Sheet','Test','Range','A1','UseExcel', true,'AutoFitWidth', false);
Disclaimer: I haven't tested this, but I'm fairly certain this will fix your problem.
The correct call to the writematrix would be:
writematrix(test,path_output_template1, 'Sheet','Test','Range','A1', 'UseExcel', true,'AutoFitWidth',false);
When writing datetime data to a spreadsheet file, you must set both 'PreserveFormat' and the 'UseExcel' Name-Value pair to true to preserve the existing cell formatting. You can check the documentation writematrix.
In order to answer to the error I tested the code locally in Matlab 2019b and works well setting the test variable in this example way: test = magic(5);.
Maybe the error could be in the data that you use in test variable or in that if you run the code iteratively very fast the path_output could exist, One way to improve this could be with a more accurate timestamp.

Attempting to append all content into file, last iteration is the only one filling text document

I'm trying to Create a file and append all the content being calculated into that file, but when I run the script the very last iteration is written inside the file and nothing else.
My code is on pastebin, it's too long, and I feel like you would have to see exactly how the iteration is happening.
Try to summarize it, Go through an array of model numbers, if the model number matches call the function that calculates that MAC_ADDRESS, when done calculating store all the content inside a the file.
I have tried two possible routes and both have failed, giving the same result. There is no error in the code (it runs) but it just doesn't store the content into the file properly there should be 97 different APs and it's storing only 1.
The difference between the first and second attempt,
1 attempt) I open/create file in the beginning of the script and close at the very end.
2 attempt) I open/create file and close per-iteration.
First Attempt:
https://pastebin.com/jCpLGMCK
#Beginning of code
File = open("All_Possibilities.txt", "a+")
#End of code
File.close()
Second Attempt:
https://pastebin.com/cVrXQaAT
#Per function
File = open("All_Possibilities.txt", "a+")
#per function
File.close()
If I'm not suppose to reference other websites, please let me know and I'll just paste the code in his post.
Rather than close(), please use with:
with open('All_Possibilities.txt', 'a') as file_out:
file_out.write('some text\n')
The documentation explains that you don't need + to append writes to a file.
You may want to add some debugging console print() statements, or use a debugger like pdb, to verify that the write() statement actually ran, and that the variable you were writing actually contained the text you thought it did.
You have several loops that could be a one-liner using readlines().
Please do this:
$ pip install flake8
$ flake8 *.py
That is, please run the flake8 lint utility against your source code,
and follow the advice that it offers you.
In particular, it would be much better to name your identifier file than to name it File.
The initial capital letter means something to humans reading your code -- it is
used when naming classes, rather than local variables. Good luck!

Skip element in BizTalk flat file assembly?

I've been tasked to map an input xml (actually an SAP idoc xml), and to generate a number of flat files. Each input xml may yield multiple output files (one output file per lot number), so I will be using xsl:key and the key() function in my mapping, based on the lot number
The thing is, the lot number itself will not be in the file itself, but the output file name needs to contain that lot number value.
So the question really is: can I map the lot number to the xml and have the flat file assembler skip it when it produces the file? Or is there another way the lot number can be applied as file name by the assembly without having it inside the file itself?
In your orchestration you can set a context property for each output message:
msgOutput(FILE.ReceivedFileName) = "DynamicStuff";
msgOutput then goes to the send shape.
In your send port you set the output file like this:
FixedStuff_%SourceFileName%.xml
The result:
FixedStuff_DynamicStuff.xml
If the value is not required in the message content, don't map it. That's it.
To insert at value in the file name, lot number in this case, you will need to promote that value to the FILE.ReceivedFileName Context Property. Then, you can use the %SourceFileName% Macro as part of the name setting in the Send Port. You can set FILE.ReceivedFileName by either Property Promotion or xpath() in an Orchestration.
Bonus: Sorting and Grouping in xslt is rather unwieldy, which is why I don't do that anymore. Instead, you can use SQL: BizTalk: Sorting and Grouping Flat File Data In SQL Instead of XSL

How to use machine-generated variables in cookiecutter

Is there a way to machine-generate some values, after the user has supplied some their values for the variables in cookiecutter.json?
The reason I ask is that:
one of the values I need to prompt for is rather hard for users to work out
but it's really easy for me to write some Python code to generate the right value
So I'd really like to be able to remove the user prompt, and calculate the value instead.
Things I've tried:
Searched online for an example pre_gen_project.py file to show how to do it
Read the cookiecutter Advanced Usage page
I'm using cookiecutter on the command line:
cookiecutter path_to_template
Am I missing any tricks?
I needed this exact capability just a few days ago. The solution I came up with was to write a wrapper script for cookiecutter, similar to what is mentioned in:
http://cookiecutter.readthedocs.io/en/latest/advanced_usage.html#calling-cookiecutter-functions-from-python
My script generates a random string for use in a Django project. I called my script cut-cut:
#! /usr/bin/env python
from cookiecutter.main import cookiecutter
import os
rstring = ''.join([c for c in os.urandom(1024)
if c.isalnum()])[:64]
cookiecutter(
'django-template', # path/url to cookiecutter template
extra_context={'secret': rstring},
)
So now I simply run cut-cut and step through the process as normal. The only difference is that the entry named secret in my cookiecutter.json file is prepopulated with the generated value in rstring from the script, provided via the extra_context passed.
You could modify the script to accept the template via the command line, but in my usage I always use the same template, thus I simply pass a hard coded value "django-template" as noted in the code above.

How to replace text box value into property file using NSIS script?

I have created nsi file using NSIS plugin in eclipse.I have read the property file value using following code,
${ConfigWrite} "C:\resource\conf.properties" "WEBSERVICE.URL" $0
Now i want to create one text box and copy the value of "WEBSERVICE.URL" into that textbox.If the user enter the input in textbox then it should replace the value of WEBSERVICE.URL in config property file.else it will take default value.can anyone hele me?
You should look at the examples of nsDialogs.
Look in the Examples\nsDialogs directory of your NSIS installation : the InstallOptions.nsi script should help you.

Resources