Any way to introspect the *.xml files?

Forum rules

This is a legacy forum which is locked for new topics. New topics should be started in one of the other forums under Extending Indigo

Posted on
Sat Jul 02, 2011 1:38 pm
Perry The Cynic offline
Posts: 836
Joined: Apr 07, 2008

Any way to introspect the *.xml files?

Is there any way for the python code of a plugin to read (or ask questions about) the XML configuration files in its bundle? Specifically, I'd like the Python code to enumerate all configured devices/actions/event types with their type-ids and major features.

Note that I'm not looking for "give me all devices" - indigo.devices does that just fine. I'm looking for "give me all the device types for this plugin" (specifically, mine own; but any plugin could play). Something simple like "here's a Dict containing your Devices.xml" would suffice.

Why? I'm building proxy classes in my Python code to represent my various Indigo-visible device types. This is prone to mistake, since the linkages (type-ids, method names) are by convention only. If I had sufficient information about Devices.xml, I could auto-generate those classes and eliminate the mistakes (and a bunch of rote work).

(You could also generate Python metaclasses from the XML definitions. But that's a bit more... interesting, and I don't know if it would interfere with your Boost foundation.)

Cheers
-- perry

Posted on
Sat Jul 02, 2011 6:28 pm
jay (support) offline
Site Admin
User avatar
Posts: 18225
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Any way to introspect the *.xml files?

The default behavior for the XML parsing is to have all the XML files parsed when the plugin starts up. The Devices.xml file is parsed and what we need for the UI is stored in a dictionary. You can reference that dictionary as self.devicesTypeDict[deviceTypeId]. We haven't documented it, but if you check out the plugin_base.py file that's in the IndigoHost application bundle you can see how it's constructed. We don't have any plans on changing that dict, but it's perhaps slightly more fluid at the moment since we're not final and we have a few plugins yet to build. I'd say you're pretty safe using it.

Alternatively, you could just parse the Devices.xml yourself. Python has a couple of different XML modules - we use minidom for parsing the XML files but you can use any of them you like.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Jul 20, 2011 5:22 pm
Perry The Cynic offline
Posts: 836
Joined: Apr 07, 2008

Re: Any way to introspect the *.xml files?

... and, for the record, there are plugin.eventsTypeDict and plugin.actionsTypeDict attributes too, with the obvious meaning. Handy.

I noticed that Plugin has getEventsDict, getActionsDict, and getDevicesDict methods. Should we use those in preference to reading the attributes directly, or is there some subtlety I should be aware of? (They seem to do the obvious.)

Cheers
-- perry

Posted on
Wed Jul 20, 2011 5:53 pm
jay (support) offline
Site Admin
User avatar
Posts: 18225
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Any way to introspect the *.xml files?

Yep, using those getters is the right way of doing it. Not in the docs yet but we'll get them there eventually.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests