示例#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")
示例#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")
示例#3
0
文件: report.py 项目: cpatulea/remuco
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)
示例#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)
示例#5
0
文件: report.py 项目: cpatulea/remuco
def __send_devices():
    """Send all seen devices.
    
    @return: True if sending was successful, False if something failed
    """

    device_list = dictool.read_dicts_from_file(DEVICE_FILE, flat=False, keys=__FIELDS)
    ok = True

    for device in device_list:
        # add a simple watchword marking this report as a real one
        device["ww"] = "sun_is_shining"
        status, reason = __send_device(device)
        if status != httplib.OK:
            print("-> failed (%s - %s)" % (status, reason))
            if status == httplib.NOT_FOUND:
                print("   the submission link I'm using may be outdated")
            ok = False
        else:
            print("-> ok")

    return ok
示例#6
0
def __send_devices():
    """Send all seen devices.
    
    @return: True if sending was successful, False if something failed
    """
    
    device_list = dictool.read_dicts_from_file(DEVICE_FILE, flat=False,
                                               keys=__FIELDS)
    ok = True

    for device in device_list:
        # add a simple watchword marking this report as a real one
        device["ww"] = "sun_is_shining"
        status, reason = __send_device(device)
        if status != httplib.OK:
            print("-> failed (%s - %s)" % (status, reason))
            if status == httplib.NOT_FOUND:
                print("   the submission link I'm using may be outdated")
            ok = False
        else:
            print("-> ok")

    return ok
示例#7
0
文件: report.py 项目: cpatulea/remuco
        status, reason = __send_device(device)
        if status != httplib.OK:
            print("-> failed (%s - %s)" % (status, reason))
            if status == httplib.NOT_FOUND:
                print("   the submission link I'm using may be outdated")
            ok = False
        else:
            print("-> ok")

    return ok


if __name__ == "__main__":

    import sys

    if len(sys.argv) == 2:
        if sys.argv[1] == "send":
            ok = __send_devices()
            if ok:
                sys.exit(os.EX_OK)
            else:
                sys.exit(os.EX_TEMPFAIL)
        elif sys.argv[1] == "dump":
            devices = dictool.read_dicts_from_file(DEVICE_FILE, flat=True)
            for dev in devices:
                print(dev)
            sys.exit(os.EX_OK)

    sys.exit(os.EX_USAGE)
示例#8
0
        device["ww"] = "sun_is_shining"
        status, reason = __send_device(device)
        if status != httplib.OK:
            print("-> failed (%s - %s)" % (status, reason))
            if status == httplib.NOT_FOUND:
                print("   the submission link I'm using may be outdated")
            ok = False
        else:
            print("-> ok")

    return ok

if __name__ == '__main__':
    
    import sys
    if len(sys.argv) == 2:
        if sys.argv[1] == "send":
            ok = __send_devices()
            if ok:
                sys.exit(os.EX_OK)
            else:
                sys.exit(os.EX_TEMPFAIL)
        elif sys.argv[1] == "dump":
            devices = dictool.read_dicts_from_file(DEVICE_FILE, flat=True)
            for dev in devices:
                print(dev)
            sys.exit(os.EX_OK)
    
    sys.exit(os.EX_USAGE)