Example #1
0
def dump_directories_cont(dir1):
    check_dir(dir1)
    list1 = pcap_sync.create_list_of_files(dir1)
    for i in list1:
        print(dir1 + i[0] + ':')
        pcap.dump(dir1 + i[0])
        print("-------------------------------")
Example #2
0
def sync_directories(dir_list):
    check_dir(dir_list)
    dir1 = dir_list[0]
    dir2 = dir_list[1]
    list1 = pcap_sync.create_list_of_files(dir1)
    list2 = pcap_sync.create_list_of_files(dir2)

    print("sync...")

    new_file_list1 = []
    for i in list1:
        found = False
        for j in list2:
            file1, key1 = i[:2]
            file2, key2 = j[:2]
            if key1 == key2:
                found = True
                synchro = pcap_sync.Sync(dir1 + file1, dir2 + file2)
                # Only syncs if files are not up-to-date
                if not synchro.up_to_date:
                    synchro.sync_files()
                # Pops element of the second list if match was found to avoid unnecessary iterations
                list2.pop(list2.index(j))
                continue
        # If no match was found for the element of the first list, that means that the file is new and needs to be
        # added to the second list, respectively second directory. This is done below.
        if not found:
            new_file_list1.append(i)

    list1 = new_file_list1
    print(list1)
    print(list2)

    if list1:
        for i in list1:
            file, key = i[:2]
            synchro = pcap_sync.Sync(dir1 + file, dir2 + file)
            synchro.sync_files(True, key)

    if list2:
        for i in list2:
            file, key = i[:2]
            synchro = pcap_sync.Sync(dir1 + file, dir2 + file)
            synchro.sync_files(True, key)
def get_i_have_list():
    # TODO: Change directory to database
    list_of_files = pcap_sync.create_list_of_files('udpDir/')  # 4
    return cbor.dumps(list_of_files)