Community

Post

Importing a properties file into a dictionary

If you find yourself with a lot of properties files that you would like to load into dictionaries, you can use this CLI extension. Place it in the ext directory of your CLI installation and invoke the command as follows:

loadIntoDict("/tmp/my.properties", "myDict");

Note that the dictionary referenced, Environments/myDict must exist in the Deployit repository.

This is an expanded version of the script (import-export-dictionaries.cli) that also supports exporting an existing dictionary to a properties file. Some examples:

importIntoDict("myprops.properties", "myDict")

Import the contents of DEPLOYIT_CLI_HOME/myprops.properties into existing dictionary Environments/myDict, preserving existing values in the dictionary if there are entries with the same key in the properties file.

Import the contents of /my/directory/myprops.properties into existing dictionary Environments/Dev/myDict, overwriting existing values in the dictionary if there are entries with the same key in the properties file.

Import the contents of /my/directory/myprops.properties into existing dictionary Environments/Dev/myDict, overwriting existing values in the dictionary if there are entries with the same key in the properties file.

In other words, please pass True as the third argument if you wish to overwrite existing keys.

I currently use DeployIt release 3.8.3 and I'im currently using your script for test purposes. The import is successful with special characters like éèê as long as you encode the source property file in UTF-8. However, when you attempt to export these specific characters to a property file, they're replaced with "?".

I tried to force the CLI encoding, using -Dfile.encoding and -Dpython.console.encoding but this does not work. Actually the server response already contains the faultly substitutions.