[Solved] [Python] Update property in a configuration file

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
OlivierR
Posts: 38
Joined: Sun Jul 25, 2010 3:13 pm

[Solved] [Python] Update property in a configuration file

Post by OlivierR »

Hello,

I would like to update a configuration file in the registry.

Here is the configuration file I would like to update:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<oor:component-data xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" oor:name="Linguistic" oor:package="org.openoffice.Office">
 <node oor:name="ServiceManager">
    <node oor:name="Dictionaries">
        <node oor:name="HunSpellDic_fr-multidict" oor:op="fuse">
            <prop oor:name="Locations" oor:type="oor:string-list">
                <value>vnd.sun.star.expand:$UNO_USER_PACKAGES_CACHE/uno_packages/lu68yh0.tmp_/multi-fr.oxt/dictionaries/fr-reforme1990.aff vnd.sun.star.expand:$UNO_USER_PACKAGES_CACHE/uno_packages/lu68yh0.tmp_/multi-fr.oxt/dictionaries/fr-reforme1990.dic</value>
            </prop>
            <prop oor:name="Format" oor:type="xs:string">
                <value>DICT_SPELL</value>
            </prop>
            <prop oor:name="Locales" oor:type="oor:string-list">
                <value>fr-FR fr-BE fr-CA fr-CH fr-LU fr-MC</value>
            </prop>
        </node>
        [...]
    </node>
 </node>  
</oor:component-data>
What I want to update is the URL of the dictionaries files in the property "Locations", a string list, in the node "HunSpellDic_fr-multidict".

Here is the code:

Code: Select all

xSettings = getConfigSetting("/org.openoffice.Office.Linguistic/ServiceManager/Dictionaries/HunSpellDic_fr-multidict", True)
result = xSettings.getByName("Locations")
xSettings.replaceByName("Locations", result)
xSettings.commitChanges()


def getConfigSetting (sNodeConfig, bForUpdate):
    if bForUpdate:
        sService = "com.sun.star.configuration.ConfigurationUpdateAccess"
    else:
        sService = "com.sun.star.configuration.ConfigurationAccess"
    
    xConfigProvider = createUnoService("com.sun.star.configuration.ConfigurationProvider")
    
    xPropertyValue = PropertyValue()
    xPropertyValue.Name = "nodepath"
    xPropertyValue.Value = sNodeConfig
    
    xSettings = xConfigProvider.createInstanceWithArguments(sService, (xPropertyValue,))
    return xSettings

def createUnoService (serviceName):
    sm = uno.getComponentContext().ServiceManager
    return sm.createInstanceWithContext(serviceName, uno.getComponentContext())
Here I just try to update with what I read in the property "Locations", but I get the error message :

Code: Select all

com.sun.star.lang.IllegalArgumentException configmgr inappropriate property value
In Python, result is a tuple of strings. I tried to pass it as a list, and it said that list object has no attribute getTypes.

How can I update a property of strings-list ?
Last edited by OlivierR on Mon Sep 24, 2012 2:41 pm, edited 1 time in total.
LibreOffice 6.4Windows 10
hanya
Volunteer
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: [Python] Update string-list property in a configuration

Post by hanya »

Hi,
If you faile with "any" type parameter, try to pass the value as uno.Any in general.

Code: Select all

uno.invoke(xSettings, "replaceByName", ("Locations", uno.Any("[]string", result)))
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
OlivierR
Posts: 38
Joined: Sun Jul 25, 2010 3:13 pm

Re: [Solved] [Python] update property in a configuration fil

Post by OlivierR »

Thank you very much, Hanya. :D
LibreOffice 6.4Windows 10
Post Reply