Ejemplo n.º 1
0
    def parse(self, args):
        result = self.driver.GetAll('org.chemlab.UChroma.Device')
        keylen = max_keylen(result)
        props = OrderedDict(
            sorted({camel_to_snake(k): v
                    for k, v in result.items()}.items()))

        for dumpable in self._dumpables:
            for v in dumpable.current_state.values():
                if len(v.keys()) == 0:
                    continue
                kk = max_keylen(v.keys())
                if kk > keylen:
                    keylen = kk

        print('\n Device properties:\n')

        device_index = "device-%s" % props.pop('device_index')
        device_name = props.pop('name')

        self.columns(keylen, color(device_index, style='bright'),
                     color(device_name, style='bright'))
        self.seperator(keylen)

        for k, v in props.items():
            self.columns(keylen, color(k, style='bright'), v)

        print('\n')

        for dumpable in self._dumpables:
            dumpable.dump(keylen=keylen)
Ejemplo n.º 2
0
    def list_objects(self,
                     objects,
                     values=None,
                     aliases=None,
                     show_all: bool = False,
                     keylen=None):

        if aliases is None:
            keys = objects.keys()
        else:
            keys = [aliases.get(k, k) for k in objects.keys()]

        if keylen is None:
            keys = list(keys)
            for v in objects.values():
                keys.extend(v.traits.trait_names())
            if values is not None:
                for v in values.values():
                    keys.extend(v.keys())
            keylen = max_keylen(keys) + 1

        for name, trait_data in objects.items():
            if not show_all and values is not None and name not in values:
                continue

            dname = name
            if aliases is not None and name in aliases:
                dname = aliases[name]

            desc = trait_data.description

            vals = None
            if values is not None and name in values:
                vals = values[name]

            self.columns(keylen, color(dname, style='bright'),
                         color(desc, style='bright'))

            self.show_meta(trait_data, indent=keylen)

            self.show_traits(trait_data.traits, vals, indent=keylen)
            print('\n')