#!/usr/bin/env python # package.py # # Python program to mimic the packages unmasked by '##' in package.mask across an 'emerge rsync' # # José Fonseca def make_key(operator,category,package,version,release): key = package if operator: key = operator + key if operator == '=': key = key + '-' + version return key if __name__ == "__main__": import sys, os, time, glob, re, string old = sys.argv[1] new = sys.argv[2] # Regular expressions to match the packages masks OPERATOR_RE = r"([*<>=~]+)" CATEGORY_RE = r"([0-9a-zA-Z]+-[0-9a-zA-Z]+)" PACKAGE_RE = r"([a-zA-Z+][-+_0-9a-zA-Z]*?)" NUMBER_RE = r"(?:[a-zA-Z]*[0-9]+|[0-9]+[a-zA-Z]*)" VERSION_RE = r"(" + NUMBER_RE + r"(?:[._]" + NUMBER_RE + r")*)" RELEASE_RE = r"(r[0-9]+)" EXTENSION_RE = r"[0-9a-zA-Z]+" MASK_RE = OPERATOR_RE + r"?(?:" + CATEGORY_RE + r"/)?" + PACKAGE_RE + r"(?:-" + VERSION_RE + r"\*?(?:-" + RELEASE_RE + r")?)?(?:\." + EXTENSION_RE + r")?" UNMASK_RE = r"##" + MASK_RE BEGIN_RE = r"^" END_RE = r"(?:[ ].*)?\n$" mask_re = re.compile(BEGIN_RE + MASK_RE + END_RE) unmask_re = re.compile(BEGIN_RE + UNMASK_RE + END_RE) # Dictinary to old the unmasked packages keys. The key consists of the operator and package name to cope with multiple ocurrences of the same package unmasked = {}; # Search for unmasked packages in the old package.mask f = open(old) l = f.readline() while l != "": if unmask_re.match(l): begin,operator,category,package,version,release,end = unmask_re.split(l) key = make_key(operator,category,package,version,release) unmasked[key] = 1; l = f.readline() f.close() # Unmask them again on the new package.mask f = open(new) l = f.readline() while l != "": if mask_re.match(l): begin,operator,category,package,version,release,end = mask_re.split(l) key = make_key(operator,category,package,version,release) if unmasked.has_key(key): print "##" + l, else: print l, else: print l, l = f.readline() f.close()