Last active
August 29, 2015 13:56
-
-
Save YokoZar/8999726 to your computer and use it in GitHub Desktop.
Parser to remove dupe arch:all files and combine packages.i386 and packages.amd64 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
INPUT1 = 'Packages.i386' | |
INPUT2 = 'Packages.amd64' | |
OUTPUT = 'Packages.amd64i386' | |
known_all = set() | |
# open output | |
def parse_package(input_file,output_file): | |
output_buffer = [] | |
for line in input_file: | |
output_buffer.append(line) | |
if line.startswith('Package:'): current_package = line.split('Package: ')[1] | |
if line.startswith('Architecture:'): | |
arch = line.split('Architecture: ')[1] | |
if arch == 'all\n': | |
if current_package in known_all: | |
dupe = True | |
else: | |
dupe = False | |
known_all.add(current_package) | |
else: | |
dupe = False | |
if line == '\n': # End of package | |
if not dupe: | |
for x in output_buffer: output_file.write(x) | |
output_buffer = [] | |
with open(OUTPUT, 'w') as output: | |
with open(INPUT1, 'r') as package_file: | |
parse_package(package_file,output) | |
with open(INPUT2, 'r') as package_file: | |
parse_package(package_file,output) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment