Post

7 followers Follow
4
Avatar

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.

XebiaLabs Support

Please sign in to leave a comment.

17 comments

0
Avatar

If you're looking to create a new dictionary before importing the values, this can be done using the following CLI command:

repository.create(factory.configurationItem("Environments/my-dict-name", "udm.Dictionary"))

XebiaLabs Support 0 votes
0
Avatar

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.

importIntoDict("/my/directory/myprops.properties", "Dev/myDict", True)

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.

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

Exports the contents of existing dictionary Environments/myDict into properties file DEPLOYIT_CLI_HOME/myprops.properties.

exportFromDict("Dev/myDict", "/my/directory/myprops.properties")

Exports the contents of existing dictionary Environments/Dev/myDict into properties file /my/directory/myprops.properties.

XebiaLabs Support 0 votes
0
Avatar

how can you export out a folder containing severl dictionaries ? do you have to do it one dictionary at a time ?

Mohamed El Hossary 0 votes
0
Avatar

Hi Mohamed

how can you export out a folder containing severl dictionaries ? do you have to do it one dictionary at a time ?

I assume you do not know the names of the dictionaries in advance, only the name of the folder(s)? In that case, you could use something like:

dictsInFolder = repository.search("udm.Dictionary", "Environments/my/folder/name")  
for dictId in dictsInFolder:
exportFomrDict(dictId, ...)

Hope that helps!

Andrew

XebiaLabs

XebiaLabs Support 0 votes
0
Avatar

Hi WEBi

That should work the same way as with a "regular" dictionary. If we have an encrypted dictionary Environments/my-encrypted-dict and a properties file my-secret-props.properties with contents

password=secret

then

importIntoDict("my-secret-props.properties", "my-encrypted-dict")

will populate the encrypted dictionary as expected:

encrypted-dict-with-value.PNG

Hope that helps!

Andrew

XebiaLabs

XebiaLabs Support 0 votes
0
Avatar

Hi,

 

I`m using DeployIt 3.9.3 on a server within our local network.

When I make a dictionary from the CL it wont show in the GUI. Same goes when I make an dictonairy in the GUI, it wont show in the CL.

Is there something i haven't done? I restarted the GUI multiple times and re-logged in the CL more than once.

~Jimmy

Jimmy Jansen 0 votes
0
Avatar

Hi Jimmy,

Can you send us the log output you get from the CLI and the one on the Deployit server? And can you also send us the commands you're trying to execute?

Regards,

Joris

XebiaLabs Support 0 votes
0
Avatar

This is really very good feature . It saves lot of time. Do we have any cli to import all properties file under one folder (this folder will have sub folders)? if we have it will same even more time.

-Nagesh

Nageswararao Korrapolu 0 votes
0
Avatar

How to Update DICT? If i run the Import its saying "Dictionary already contains key . Skipping."

Thanks

madhu

Duke Energy WEBi 0 votes
0
Avatar

Hi Madhu

See the above example:

importIntoDict("/my/directory/myprops.properties", "Dev/myDict", True)

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.

Regards

XebiaLabs Support

XebiaLabs Support 0 votes
0
Avatar

Hi,

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.

Any idea to circumvent this ?

Thanks.

Rgds,

Julien.

Julien AUBIN 0 votes
0
Avatar

Hi Julien,

What OS are your trying this on? In the case you're using Linux based OS, can you send me the output of the locale command?

Regards,

Joris

Joris De Winne 0 votes
0
Avatar

Hi Joris,

The OS is a french Windows 7, and DeployIt is hosted on a Windows Server (2008 I thing, not sure) but if I try with DeployIt hosted on my local Win7 the issue is also there.

Julien AUBIN 0 votes