• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1def extract_blocks(pkgdiff_command):
2    """Extract block ranges from a pkgdiff command."""
3    parts = pkgdiff_command.split()
4    if len(parts) < 6:
5        return []
6    parts = pkgdiff_command.replace(',', ' ').split()
7    # The block range is in the 6th position (index 5)
8    blocks = []
9    all_blocks = []
10    start = int(parts[6])
11    end = int(parts[7])
12    # Generate the blocks for the range [start, end)
13    blocks.extend(range(start, end))
14    print(f'pkg diff len(blocks):{len(blocks)}')
15
16    all_blocks.extend(blocks)
17
18    return all_blocks
19
20
21def extract_blocks_new(new_command):
22    """Extract block ranges from a pkgdiff command."""
23    parts = new_command.split()
24    parts = new_command.replace(',', ' ').split()
25    # The block range is in the 6th position (index 5)
26    blocks = []
27    all_blocks = []
28    start = int(parts[2])
29    end = int(parts[3])
30    # Generate the blocks for the range [start, end)
31    blocks.extend(range(start, end))
32    print(f'pkg diff len(blocks):{len(blocks)}')
33
34    all_blocks.extend(blocks)
35
36    return all_blocks
37
38
39def read_pkgdiff_file(filename):
40    """Read a pkgdiff file and extract blocks from each command."""
41    blocks_set = set()
42    with open(filename, 'r') as file:
43        for line in file:
44            line = line.strip()
45            if line.startswith("pkgdiff"):  # Only process lines that start with "pkgdiff"
46                blocks = extract_blocks(line)
47                blocks_set.update(blocks)
48            if line.startswith("new"):
49                blocks_new = extract_blocks_new(line)
50                blocks_set.update(blocks_new)
51    return blocks_set
52
53
54def compare_block_lists(list1, list2):
55    """Compare two sets of blocks and print missing blocks in list2."""
56    missing_blocks = list1.difference(list2)
57    if missing_blocks:
58        print("Missing blocks in the second file:")
59        for block in sorted(missing_blocks):
60            print(block)
61    else:
62        print("No missing blocks in the second file.")
63
64
65def main():
66    # Replace 'file1.txt' and 'file2.txt' with your actual file names
67    file1 = 'system.transfer_1.list'
68    file2 = 'system.transfer_2.list'
69
70    # Read and extract blocks from both files
71    blocks_file1 = read_pkgdiff_file(file1)
72    blocks_file2 = read_pkgdiff_file(file2)
73
74    # Compare the two sets of blocks
75    compare_block_lists(blocks_file1, blocks_file2)
76
77
78if __name__ == "__main__":
79    main()