Ejemplo n.º 1
0
    def test_it(self):

        keys = ("a", "c", "b")
        dic1 = {"a": "1:d", "b": "2", "d": "4", "c": "3"}
        dic3 = {"a": "1", "b": "2,0", "d": "4", "c": "3"}

        flat = dictool.dict_to_string(dic1)
        dic2 = dictool.string_to_dict(flat)
        assert dic1 == dic2

        flat = dictool.dict_to_string(dic1, keys=keys)
        assert flat == "a:1:d,c:3,b:2"
        dic2 = dictool.string_to_dict(flat)
        assert dic1 != dic2

        flat = dictool.dict_to_string(dic3, keys=keys)
        assert flat == "a:1,c:3,b:2_0"

        l1 = [dic1, dic2]
        dictool.write_dicts_to_file("/var/tmp/dictest", l1, comment="# hallo")
        l2 = dictool.read_dicts_from_file("/var/tmp/dictest")
        assert l1 == l2

        dictool.write_dicts_to_file("/var/tmp/dictest",
                                    [dic1, dic2, dic3, flat],
                                    comment="# hallo",
                                    keys=["a"])
        l = dictool.read_dicts_from_file("/var/tmp/dictest")

        l = dictool.read_dicts_from_file("/var/tmp/non_existent")
Ejemplo n.º 2
0
 def test_it(self):
     
     keys = ("a", "c", "b")
     dic1 = { "a": "1:d", "b": "2", "d": "4", "c": "3" }
     dic3 = { "a": "1", "b": "2,0", "d": "4", "c": "3" }
     
     flat = dictool.dict_to_string(dic1)
     dic2 = dictool.string_to_dict(flat)
     assert dic1 == dic2
     
     flat = dictool.dict_to_string(dic1, keys=keys)
     assert flat == "a:1:d,c:3,b:2"
     dic2 = dictool.string_to_dict(flat)
     assert dic1 != dic2
     
     flat = dictool.dict_to_string(dic3, keys=keys)
     assert flat == "a:1,c:3,b:2_0"
     
     l1 = [dic1,dic2]
     dictool.write_dicts_to_file("/var/tmp/dictest", l1, comment="# hallo")
     l2 = dictool.read_dicts_from_file("/var/tmp/dictest")
     assert l1 == l2
     
     dictool.write_dicts_to_file("/var/tmp/dictest", [dic1,dic2,dic3,flat],
                                 comment="# hallo", keys=["a"])
     l = dictool.read_dicts_from_file("/var/tmp/dictest")
     
     l = dictool.read_dicts_from_file("/var/tmp/non_existent")
Ejemplo n.º 3
0
def log_device(device):
    """Log a client device."""

    device = dictool.dict_to_string(device, keys=__FIELDS)

    seen_devices = dictool.read_dicts_from_file(DEVICE_FILE, flat=True, keys=__FIELDS)

    if not device in seen_devices:
        __user_notification("New Remuco Client", "Please run the tool <b>remuco-report</b> !")
        seen_devices.append(device)
        dictool.write_dicts_to_file(DEVICE_FILE, seen_devices, comment=__DEVICE_FILE_COMMENT)
Ejemplo n.º 4
0
def log_device(device):
    """Log a client device."""
    
    device = dictool.dict_to_string(device, keys=__FIELDS)
    
    seen_devices = dictool.read_dicts_from_file(DEVICE_FILE, flat=True,
                                                keys=__FIELDS)
    
    if not device in seen_devices:
        notify("New Remuco Client",
               "Please run the tool <b>remuco-report</b> !")
        seen_devices.append(device)
        dictool.write_dicts_to_file(DEVICE_FILE, seen_devices,
                                    comment=__DEVICE_FILE_COMMENT)