keryx team mailing list archive
-
keryx team
-
Mailing list archive
-
Message #00074
StatusMerge.py
We recently discovered that Keryx 0.92.1's "default" project was
broken because it has no status file. In order to fix this, we need to
create a status file that contains only packages that are included in
Ubuntu, Kubuntu, and Xubuntu. Seeing as there are thousands of
packages installed by default in each of those Ubuntu flavors, making
this status file by hand is out of the question. So, this morning, I
wrote a Python script to do it.
To run the script, you gather the several status files you want to
filter into the directory with the script. Then run "python
StatusMerge.py status1 status2 ..." It will spit out a file called
"status_new" that will contain only packages included in all the
original status files.
Right now, there is a bug that causes two newline characters to be
tacked onto the end of the output status file. I haven't bothered to
fix the problem, because 1) I don't believe it's serious and 2) the
newlines can be quickly removed with your favorite text editor.
We will be releasing 0.92.2 with the new default project containing
this super status file soon. I will also be adding StatusMerge.py to
the /tools directory in the Keryx development branch.
Check it out, tell me what you think. Thanks
-mac
#!/usr/bin/python
import os, sys
from optparse import OptionParser
PROGRAM = 'StatusMerge'
VERSION = '0.9'
USAGE = """%prog file1 file2 ...
%prog takes two or more APT status files as arguments and produces one
file containing only packages listed in all provided status files."""
HELP = """EXAMPLE: python StatusMerge.py status1 status2 status3"""
def parse():
""" Parses options and arguments passed """
parser = OptionParser(description=HELP, usage=USAGE, version='%s %s' % (PROGRAM, VERSION))
parser.set_defaults(log_level="ERROR")
return parser.parse_args()
def main():
""" Main code """
opts, args = parse()
if len(args) == 0:
print HELP
exit()
elif len(args) < 2:
print 'ERROR: not enough arguments. Exiting.'
exit()
status_list = []
for filename in args:
status_file = open(filename, 'rb')
text = status_file.read()
status_file.close()
status_list.append(text.split('\n\n'))
outfile = file(os.path.join(os.getcwd(), 'status_new'), 'wb')
for package in status_list[0]:
write = True
for status in status_list:
if not package in status:
write = False
break
if write:
outfile.write(package + '\n\n')
outfile.close()
if __name__ == "__main__":
main()
Follow ups