Skip to content

InfoTree API: Usage improvements

OpSocket requested to merge fix/tree into develop

This merge request follows #7 (closed)

pyInfoTree init

We can now init an infotree from a json string or a python dictionnary as the unique optional argument initial when calling the type.

>>> from pyquid import InfoTree
>>> x, y, z = InfoTree(), InfoTree({ "a": 1 }), InfoTree('{"b": 2}')
>>> print(x, y, z, sep='\n')
null
{
  "a" : 1
}
{
  "b" : 2
}

repr() and str()

This magic occurs because repr() returns the representation of the object and str() returns the representation of the object encoded as json

>>> repr(x)
'<pyquid.InfoTree object at 0x7f41196bf540>'
>>> repr(y)
'<pyquid.InfoTree object at 0x7f41195c7510>'
>>> repr(z)
'<pyquid.InfoTree object at 0x7f4119633d50>'
>>> str(x)
'null'
>>> str(y)
'{\n  "a" : 1\n}'
>>> str(z)
'{\n  "b" : 2\n}'

sw.class_doc() and sw.classes_doc()

Both functions are now reconciled with the python data types.

>>> sw.class_doc('dummy')
{'class': 'dummy', 'name': 'dummy', 'category': 'test', 'tags': [], 'description': 'Dummy plugin for testing/example purpose', 'license': 'LGPL', 'author': 'Nicolas Bouillot'}
>>> sw.classes_doc()
{'classes': [{'id': 'OSCsink', 'class': 'OSCsink', 'name': 'OSCsink', 'category': 'network', 'tags': ['reader'], 'description': 'Receives OSC messages and updates associated property', 'license': 'LGPL', 'author': 'Nicolas Bouillot'}, {'id': 'OSCsrc', 'class': 'OSCsrc', 'name': 'OSCsrc', 'category': 'network', 'tags': ['writer'], 'description': 'Receive OSC messages and write to shmdata', 'license': 'LGPL', 'author': 'Nicolas Bouillot'}, {'id': 'SOAPcontrolServer', 'class': 'SOAPcontrolServer', 'name': 'SOAPcontrolServer', 'category': 'control', 'tags': [], 'description': 'Control switcher through SOAP webservices', 'license': 'GPL', 'author': 'Nicolas Bouillot'}, {'id': 'audioenc', 'class': 'audioenc', 'name': 'audioenc', 'category': 'audio', 'tags': ['writer', 'reader'], 'description': 'Encode raw audio stream', 'license': 'LGPL', 'author': 'Nicolas Bouillot'}, {'id': 'audiotestsrc', 'class': 'audiotestsrc', 'name': 'audiotestsrc', 'category': 'audio', 'tags': ['writer'], 'description': 'Creates audio test signals', 'license': 'LGPL', 'author': 'Nicolas Bouillot'}, {'id': 'avplayer', 'class': 'avplayer', 'name': 'avplayer', 'category': 'audio/video', 'tags': ['writer'], 'description': 'Replays and controls a recorded shmdata audio/video file', 'license': 'LGPL', 'author': 'Jérémie Soria'}, {'id': 'avrec', 'class': 'avrec', 'name': 'avrec', 'category': 'audio/video', 'tags': ['reader'], 'description': 'Records connected audio/video shmdata', 'license': 'LGPL', 'author': 'Jérémie Soria'}, {'id': 'cropper', 'class': 'cropper', 'name': 'cropper', 'category': 'video', 'tags': ['reader', 'writer'], 'description': 'Plugin for cropping video sources', 'license': 'LGPL', 'author': 'Francis Lecavalier'}, {'id': 'custom-save', 'class': 'custom-save', 'name': 'custom-save', 'category': 'test', 'tags': [], 'description': 'Custom Save plugin for testing/example purpose', 'license': 'LGPL', 'author': 'Nicolas Bouillot'}, {'id': 'decoder', 'class': 'decoder', 'name': 'decoder', 'category': 'other', 'tags': ['writer', 'reader'], 'description': 'Generic shmdata decoder', 'license': 'LGPL', 'author': 'Nicolas Bouillot'}, {'id': 'dummy', 'class': 'dummy', 'name': 'dummy', 'category': 'test', 'tags': [], 'description': 'Dummy plugin for testing/example purpose', 'license': 'LGPL', 'author': 'Nicolas Bouillot'}, {'id': 'dummysink', 'class': 'dummysink', 'name': 'dummysink', 'category': 'utils', 'tags': [], 'description': 'Quiddity for testing the reading of shmdata', 'license': 'LGPL', 'author': 'Nicolas Bouillot'}, {'id': 'emptyquid', 'class': 'emptyquid', 'name': 'emptyquid', 'category': 'utils', 'tags': [], 'description': 'Quiddity for user data saving', 'license': 'LGPL', 'author': 'Nicolas Bouillot'}, {'id': 'executor', 'class': 'executor', 'name': 'executor', 'category': 'utils', 'tags': ['reader'], 'description': 'Plugin for launching command lines', 'license': 'LGPL', 'author': 'Francis Lecavalier'}, {'id': 'extshmsrc', 'class': 'extshmsrc', 'name': 'extshmsrc', 'category': 'other', 'tags': ['writer'], 'description': 'Import an external shmdata writer', 'license': 'LGPL', 'author': 'Nicolas Bouillot'}, {'id': 'filesrc', 'class': 'filesrc', 'name': 'filesrc', 'category': 'file', 'tags': ['writer'], 'description': 'File decoding to one or more shmdata', 'license': 'LGPL', 'author': 'Nicolas Bouillot'}, {'id': 'glfwin', 'class': 'glfwin', 'name': 'glfwin', 'category': 'video', 'tags': ['reader', 'device', 'occasional-writer'], 'description': 'Video window with fullscreen', 'license': 'LGPL', 'author': 'Jérémie Soria'}, {'id': 'gst', 'class': 'gst', 'name': 'gst', 'category': 'video', 'tags': [], 'description': 'Plugin implementing a simple Gst pipeline', 'license': 'LGPL', 'author': 'Hantz-Carly F. Vius'}, {'id': 'httpsdpdec', 'class': 'httpsdpdec', 'name': 'httpsdpdec', 'category': 'network', 'tags': ['writer'], 'description': 'Decode an SDP-described stream delivered through http and make shmdata', 'license': 'LGPL', 'author': 'Nicolas Bouillot'}, {'id': 'jackserver', 'class': 'jackserver', 'name': 'jackserver', 'category': 'audio', 'tags': [], 'description': 'Run a Jack audio server', 'license': 'LGPL', 'author': 'Nicolas Bouillot'}, {'id': 'jacksink', 'class': 'jacksink', 'name': 'jacksink', 'category': 'audio', 'tags': ['reader', 'device'], 'description': 'Audio display', 'license': 'LGPL', 'author': 'Nicolas Bouillot'}, {'id': 'jacksrc', 'class': 'jacksrc', 'name': 'jacksrc', 'category': 'audio', 'tags': ['writer', 'device'], 'description': 'Get audio from jack', 'license': 'LGPL', 'author': 'Nicolas Bouillot'}, {'id': 'ladspa', 'class': 'ladspa', 'name': 'ladspa', 'category': 'audio', 'tags': ['reader', 'writer'], 'description': 'Choice of LADSPA plugins', 'license': 'LGPL', 'author': 'Jérémie Soria'}, {'id': 'ltcdiff', 'class': 'ltcdiff', 'name': 'ltcdiff', 'category': 'time', 'tags': ['reader', 'writer'], 'description': 'Computes the absolute time between two timecode shmdata', 'license': 'LGPL', 'author': 'Jérémie Soria'}, {'id': 'ltcsource', 'class': 'ltcsource', 'name': 'ltcsource', 'category': 'audio', 'tags': ['reader', 'writer'], 'description': 'Generate an LTC timecode audio track (can be cadenced by external sound shmdata)', 'license': 'LGPL', 'author': 'Jérémie Soria'}, {'id': 'ltctojack', 'class': 'ltctojack', 'name': 'ltctojack', 'category': 'audio', 'tags': ['reader'], 'description': 'Control Jack Transport from an incoming LTC stream', 'license': 'LGPL', 'author': 'Jérémie Soria'}, {'id': 'method', 'class': 'method', 'name': 'method', 'category': 'test', 'tags': [], 'description': 'Dummy plugin for testing/example purpose', 'license': 'LGPL', 'author': 'Nicolas Bouillot'}, {'id': 'midisink', 'class': 'midisink', 'name': 'midisink', 'category': 'midi', 'tags': ['reader', 'device'], 'description': 'Shmdata to midi', 'license': 'LGPL', 'author': 'Nicolas Bouillot'}, {'id': 'midisrc', 'class': 'midisrc', 'name': 'midisrc', 'category': 'midi', 'tags': ['writer', 'hid', 'device'], 'description': 'Midi to shmdata and properties', 'license': 'LGPL', 'author': 'Nicolas Bouillot'}, {'id': 'protocol-mapper', 'class': 'protocol-mapper', 'name': 'protocol-mapper', 'category': 'controller', 'tags': ['hid', 'device'], 'description': 'Maps properties to a protocol', 'license': 'LGPL', 'author': 'Nicolas Bouillot/Jérémie Soria'}, {'id': 'pulsesink', 'class': 'pulsesink', 'name': 'pulsesink', 'category': 'audio', 'tags': ['reader', 'device'], 'description': 'Inspecting Devices And Playing Audio To Outputs', 'license': 'LGPL', 'author': 'Nicolas Bouillot'}, {'id': 'pulsesrc', 'class': 'pulsesrc', 'name': 'pulsesrc', 'category': 'audio', 'tags': ['writer', 'device'], 'description': 'Audio From Pulse audio driver', 'license': 'LGPL', 'author': 'Nicolas Bouillot'}, {'id': 'resample', 'class': 'resample', 'name': 'resample', 'category': 'audio', 'tags': ['reader', 'writer'], 'description': 'Audio resampling with libsamplerate', 'license': 'GPL', 'author': 'Nicolas Bouillot'}, {'id': 'rtmp', 'class': 'rtmp', 'name': 'rtmp', 'category': 'audio/video', 'tags': ['reader'], 'description': 'Plugin for streaming audio/video to an RTMP server (Youtube, Twitch, etc.)', 'license': 'LGPL', 'author': 'Jérémie Soria/Francis Lecavalier'}, {'id': 'shmdelay', 'class': 'shmdelay', 'name': 'shmdelay', 'category': 'other', 'tags': ['reader', 'writer'], 'description': 'Takes an input shmdata and delays it by a fixed amount', 'license': 'LGPL', 'author': 'Jérémie Soria'}, {'id': 'signal', 'class': 'signal', 'name': 'signal', 'category': 'test', 'tags': [], 'description': 'Dummy quiddity for testing of signals', 'license': 'LGPL', 'author': 'Jérémie Soria'}, {'id': 'sip', 'class': 'sip', 'name': 'sip', 'category': 'network', 'tags': ['occasional-writer'], 'description': 'Manages user sessions', 'license': 'LGPL', 'author': 'Nicolas Bouillot'}, {'id': 'systemusage', 'class': 'systemusage', 'name': 'systemusage', 'category': 'monitoring', 'tags': [], 'description': 'Gives system load information', 'license': 'LGPL', 'author': 'Emmanuel Durand'}, {'id': 'timelapse', 'class': 'timelapse', 'name': 'timelapse', 'category': 'video', 'tags': ['reader'], 'description': 'Make an image timelapse from raw video stream', 'license': 'LGPL', 'author': 'Nicolas Bouillot'}, {'id': 'urisrc', 'class': 'urisrc', 'name': 'urisrc', 'category': 'network', 'tags': ['writer'], 'description': 'URI decoding to one or more shmdata', 'license': 'LGPL', 'author': 'Nicolas Bouillot'}, {'id': 'v4l2src', 'class': 'v4l2src', 'name': 'v4l2src', 'category': 'video', 'tags': ['writer', 'device'], 'description': 'Discover and use v4l2 supported capture cards and cameras', 'license': 'GPL', 'author': 'Nicolas Bouillot'}, {'id': 'videnc', 'class': 'videnc', 'name': 'videnc', 'category': 'video', 'tags': ['writer', 'reader'], 'description': 'Encode raw video stream', 'license': 'LGPL', 'author': 'Nicolas Bouillot'}, {'id': 'videoconvert', 'class': 'videoconvert', 'name': 'videoconvert', 'category': 'video', 'tags': ['writer', 'reader'], 'description': 'Convert pixel format of raw video stream', 'license': 'LGPL', 'author': 'Nicolas Bouillot'}, {'id': 'videosnapshot', 'class': 'videosnapshot', 'name': 'videosnapshot', 'category': 'video', 'tags': ['reader'], 'description': 'Take snapshot from a video shmdata', 'license': 'LGPL', 'author': 'Nicolas Bouillot'}, {'id': 'videotestsrc', 'class': 'videotestsrc', 'name': 'videotestsrc', 'category': 'video', 'tags': ['writer'], 'description': 'Creates a test video stream', 'license': 'LGPL', 'author': 'Nicolas Bouillot'}, {'id': 'vncclientsrc', 'class': 'vncclientsrc', 'name': 'vncclientsrc', 'category': 'video', 'tags': ['writer', 'reader'], 'description': 'Connects to a VNC server and outputs the video to a shmdata', 'license': 'LGPL', 'author': 'Emmanuel Durand'}, {'id': 'vrpnsink', 'class': 'vrpnsink', 'name': 'vrpnsink', 'category': 'vrpn', 'tags': ['reader', 'device'], 'description': 'Plugin to create a local VRPN server from shmdata sources.', 'license': 'LGPL', 'author': 'François Ubald Brien'}, {'id': 'vrpnsrc', 'class': 'vrpnsrc', 'name': 'vrpnsrc', 'category': 'vrpn', 'tags': ['writer', 'hid', 'device'], 'description': 'Plugin to connect to a VRPN server and share its controls through shmdata and/or properties.', 'license': 'LGPL', 'author': 'François Ubald Brien'}, {'id': 'watcher', 'class': 'watcher', 'name': 'watcher', 'category': 'utils', 'tags': ['writer'], 'description': 'Watch a directory for shmdatas', 'license': 'LGPL', 'author': 'Francis Lecavalier'}, {'id': 'webrtc', 'class': 'webrtc', 'name': 'webrtc', 'category': 'audio/video', 'tags': ['reader', 'writer'], 'description': 'Plugin implementing a simple WebRTC client', 'license': 'LGPL', 'author': 'Hantz-Carly F. Vius'}]}

sw.quid_descr() and sw.quids_descr()

Both functions are now reconciled with the python data types.

>>> sw.create('dummy', 'd1')
<pyquid.Quiddity object at 0x7fa6e5786230>
>>> sw.quid_descr(1)
{'id': 1, 'class': 'dummy'}
>>> sw.quids_descr()
{'quiddities': [{'id': 1, 'class': 'dummy'}]}

tree.json()

This one is deprecated in favor of tp_str. See repr() and str() above.

tree.graft()

We are now able to graft an infotree with python dictionnaries and lists values (and that's great):

>>> from pyquid import InfoTree
>>> x = InfoTree()
>>> x.graft("buddies", [{"name": "a"}, {"name": "b"}])
True
>>> x.graft("homies", {"alice": 42, "bob": 21})
True
>>> print(x)
{
  "buddies" : [
    {
      "name" : "a"
    },
    {
      "name" : "b"
    }
  ],
  "homies" : {
    "alice" : 42,
    "bob" : 21
  }
}
>>> x.get("buddies.0.name")
'a'
>>> x.get("homies.alice")
42

Merge request reports