diff options
author | Matthias Vogelgesang <matthias.vogelgesang@kit.edu> | 2015-03-19 14:47:05 +0100 |
---|---|---|
committer | Matthias Vogelgesang <matthias.vogelgesang@kit.edu> | 2015-03-23 10:30:55 +0100 |
commit | ed1f4eb5c9dc1ae02d95034551bf6640b393e754 (patch) | |
tree | 8dfebc8e62016425c84dbdeab6a13964837037fe /docs/update-props.py | |
parent | d7a2099d51b535dbce6b68f2021f6fc0f37adc00 (diff) | |
download | libuca-ed1f4eb5c9dc1ae02d95034551bf6640b393e754.tar.gz libuca-ed1f4eb5c9dc1ae02d95034551bf6640b393e754.tar.bz2 libuca-ed1f4eb5c9dc1ae02d95034551bf6640b393e754.tar.xz libuca-ed1f4eb5c9dc1ae02d95034551bf6640b393e754.zip |
Document camera properties
Diffstat (limited to 'docs/update-props.py')
-rw-r--r-- | docs/update-props.py | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/docs/update-props.py b/docs/update-props.py new file mode 100644 index 0000000..7f2c294 --- /dev/null +++ b/docs/update-props.py @@ -0,0 +1,75 @@ +#!/usr/bin/env + +import sys +from gi.repository import Uca, GLib, GObject + + +def get_default_optional(prop): + if hasattr(prop, 'default_value'): + return ' | *Default:* {}'.format(prop.default_value) + return '' + + +def get_range_optional(prop): + if hasattr(prop, 'minimum') and hasattr(prop, 'maximum'): + return ' | *Range:* [{}, {}]'.format(prop.minimum, prop.maximum) + return '' + + +def get_type_description(value_type): + mapping = { + GObject.TYPE_BOOLEAN: 'bool', + GObject.TYPE_CHAR: 'char', + GObject.TYPE_UCHAR: 'unsigned char', + GObject.TYPE_FLOAT: 'float', + GObject.TYPE_INT: 'int', + GObject.TYPE_UINT: 'unsigned int', + GObject.TYPE_LONG: 'long', + GObject.TYPE_DOUBLE: 'double', + GObject.TYPE_STRING: 'string', + GObject.TYPE_ENUM: 'enum', + } + + return mapping.get(value_type, None) + + +def get_prop_string(prop): + template = """ +{type} **{name}** + {blurb} + +{optionals}""" + + optionals = '\n'.join(opt for opt in (get_default_optional(prop), get_range_optional(prop)) if opt) + + return template.format(name=prop.name, blurb=prop.blurb, + type=get_type_description(prop.value_type), + optionals=optionals) + +def output(camera, name): + template = """ +{name} +{name_underline} +{props}""" + + name_underline = '='*len(name) + + stream = open('{}.rst'.format(name), 'w') + props = '\n'.join((get_prop_string(prop) for prop in camera.props)) + stream.write(template.format(name=name, name_underline=name_underline, + props=props)) + + +if __name__ == '__main__': + pm = Uca.PluginManager() + + if len(sys.argv) < 2: + print("Usage: update-props.py NAME") + sys.exit(0) + + name = sys.argv[1] + + try: + output(pm.get_camerav(name, []), name) + except GLib.GError as e: + print("Could not query {}: {}".format(name, e.message)) |