Hi folks,

for some reason I often suffer from double (or triple or...) entries in
my /usr/lib/opkg/status and decided to write a little script that
removes double entries. To be safe I opted to remove the newer entries
and keep only the oldest.

Sorry for little comments in the code.

HTH someone
Jan
#!/usr/bin/python
#
# opkgrepair.py - removes double pkg entries in an opkg status file
#
# usage: opkgrepair.py <input-file> <output-file>
#
# Jan Girlich <vollk...@cryptobitch.de>

import sys

inputdata = open(sys.argv[1], 'r').readlines()

outputfile = open(sys.argv[2], 'w')

state = "lookForPackage"
lastpackage = []
currentpackage = []

def doComparison(last, cur):
	if ((len(last) > 0) and (len(cur) > 0)):
		if not (last[0] == cur[0]):
			for line in last:
				outputfile.write(line)
		else:
			print("Removing " + last[0])
	return

for line in inputdata:
	if (state == "lookForPackage"):
		if line.startswith("Package: "):
			state = "saveLines"
			currentpackage = [line]
	elif (state == "saveLines"):
		currentpackage.append(line)
		if (line == '\n'):
			doComparison(lastpackage, currentpackage)
			state = "lookForPackage"
			lastpackage = currentpackage

for line in lastpackage:
	outputfile.write(line)

Attachment: signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil

_______________________________________________
Openmoko community mailing list
community@lists.openmoko.org
http://lists.openmoko.org/mailman/listinfo/community

Reply via email to