コード例 #1
0
def test_write_setup():
    import math

    idc_to_param_names = {1: {}, 2: {}}

    for i in range(10):
        idc_to_param_names[1][i] = 'idc=1, p=%i' % i
        idc_to_param_names[2][i] = 'idc=2, p=%i' % i

    d1 = cm.Device(bus=0, address=0, idc=1)
    d1.name = 'd1'

    d2 = cm.Device(bus=1, address=5, idc=2)
    d2.name = 'd2'

    d3 = cm.Device(bus=0, address=7, idc=2)
    d3.name = 'd3'

    for i in range(12):
        d1.set_parameter(i, i * i)
        d2.set_parameter(i, i * i * i)
        d3.set_parameter(i, math.sqrt(i))

    mrc1 = cm.ConfigMrc(url='/dev/ttyUSB0')
    mrc1.name = 'the_mrc'
    mrc1.add_device(d1)
    mrc1.add_device(d2)

    mrc2 = cm.ConfigMrc(url='/dev/ttyUSB1')
    mrc2.name = 'the_2nd_mrc'
    mrc2.add_device(d3)

    setup = cm.Setup()
    setup.add_mrc(mrc1)
    setup.add_mrc(mrc2)

    dest = io.StringIO()

    cxml.write_setup(setup, dest, idc_to_param_names)

    #with open("config_xml_debug_file.xml", 'w') as debugFile:
    #    cxml.write_setup(setup, debugFile, idc_to_param_names)

    actual = dest.getvalue()

    try:
        assert actual == expected2
    except AssertionError:
        print("test_write_device_config diff:")
        for l in difflib.unified_diff(expected2.splitlines(),
                                      actual.splitlines(), "expected",
                                      "actual"):
            print(l)
        raise
コード例 #2
0
ファイル: gui_util.py プロジェクト: flueke/mesycontrol
 def accepted():
     bus, address, idc, name = dialog.result()
     device_config = cm.make_device_config(bus, address, idc, name,
             device_registry.get_device_profile(idc))
     if not mrc.has_cfg:
         registry.cfg.add_mrc(cm.ConfigMrc(mrc.url))
     mrc.cfg.add_device(device_config)
コード例 #3
0
ファイル: gui_util.py プロジェクト: flueke/mesycontrol
    def accepted(mrc=mrc):
        try:
            url, connect, autoconnect = dialog.result()

            if url == mrc.cfg.url and mrc.cfg.autoconnect == autoconnect:
                return

            device_configs = [d for d in mrc.cfg]

            for d in device_configs:
                mrc.cfg.remove_device(d)

            name = mrc.cfg.name
            registry.cfg.remove_mrc(mrc.cfg)

            new_mrc = cm.ConfigMrc(url)
            new_mrc.name = name
            new_mrc.autoconnect = autoconnect

            for d in device_configs:
                new_mrc.add_device(d)

            registry.cfg.add_mrc(new_mrc)

            if connect:
                mrc = registry.hw.get_mrc(url)
                if not mrc:
                    add_mrc_connection(registry.hw, url, connect)
                elif mrc.is_disconnected():
                    mrc.connect()

        except Exception as e:
            log.exception("run_edit_mrc_config")
コード例 #4
0
ファイル: app_model.py プロジェクト: flueke/mesycontrol
    def create_config(self):
        if self.cfg is not None:
            raise RuntimeError("MRC config exists")

        self.mrc_registry.cfg.add_mrc(cm.ConfigMrc(self.url))

        return self.cfg
コード例 #5
0
ファイル: gui_util.py プロジェクト: flueke/mesycontrol
    def accepted():
        url, connect, autoconnect = dialog.result()
        mrc = cm.ConfigMrc(url)
        mrc.autoconnect = autoconnect
        registry.cfg.add_mrc(mrc)

        if connect:
            mrc = registry.hw.get_mrc(url)
            if not mrc:
                add_mrc_connection(registry.hw, url, True)
            elif mrc.is_disconnected():
                mrc.connect()
コード例 #6
0
def _mrc_config_from_node(mrc_node):
    attrs = ['url', 'name', 'autoconnect']
    ret = cm.ConfigMrc()

    for attr in attrs:
        n = mrc_node.find(attr)
        if n is not None:
            try:
                prop_t = getattr(cm.MRC, attr).type
            except AttributeError:
                prop_t = None

            if prop_t is bool:
                prop_v = n.text.lower() in ['true', 'y', 'yes', 'on', '1']
            else:
                prop_v = n.text

            setattr(ret, attr, prop_v)

    for device_node in mrc_node.findall('device_config'):
        ret.add_device(_device_config_from_node(device_node))

    return ret