def testDepGetCPV(self): prefix_ops = ["<", ">", "=", "~", "<=", ">=", "!=", "!<", "!>", "!~"] bad_prefix_ops = [">~", "<~", "~>", "~<"] postfix_ops = [ ("=", "*"), ] cpvs = [ "sys-apps/portage-2.1", "sys-apps/portage-2.1", "sys-apps/portage-2.1" ] slots = [None, ":foo", ":2"] for cpv in cpvs: for slot in slots: for prefix in prefix_ops: mycpv = prefix + cpv if slot: mycpv += slot self.assertEqual(dep_getcpv(mycpv), cpv) for prefix, postfix in postfix_ops: mycpv = prefix + cpv + postfix if slot: mycpv += slot self.assertEqual(dep_getcpv(mycpv), cpv)
def findUseFlagCombis (package, config, port): """ Generate combinations of use flags to test The output will be a list each containing a ready to use USE=... string """ uselist = sorted(reduce_flags(get_flags(dep_getcpv(package.packageString())))) # The uselist could have duplicates due to slot-conditional # output of equery uselist=unique(uselist) for i in config['ignoreprefix']: uselist=[u for u in uselist if not re.match(i,u)] ruse = " ".join(port.aux_get(dep_getcpv(package.packageString()), ["REQUIRED_USE"])) swlist = [] if config['usecombis'] == 0: # Do only all and nothing: if check_uses(ruse, uselist, 0, package): swlist.append(0) if check_uses(ruse, uselist, 2**len(uselist) - 1): swlist.append(2**len(uselist) - 1) # Test if we can exhaust all USE-combis by computing the binary logarithm. elif len(uselist) > math.log(config['usecombis'],2): # Generate a sample of USE combis s = 2**(len (uselist)) rnds = set() random.seed() while len(swlist) < config['usecombis'] and len(rnds) < s: r = random.randint(0, s-1) if r in rnds: # already checked continue rnds.add(r) if not check_uses(ruse, uselist, r, package): # invalid combination continue swlist.append(r) swlist.sort() else: # Yes we can: generate all combinations for pos in range(2**len(uselist)): if check_uses(ruse, uselist, pos, package): swlist.append(pos) usecombis=[] for sw in swlist: mod = [] for pos in range(len(uselist)): if ((2**pos) & sw): mod.append("") else: mod.append("-") usecombis.append(" ".join(["".join(uf) for uf in list(zip(mod, uselist))])) # Merge everything to a USE="" string return ["USE=\'" + uc + "\'" for uc in usecombis]
def __init__(self, st): """An atom is initialized from an atom string""" if not isvalidatom(st): st = '=' + st cp = dep_getkey(st) self.ver = dep_getcpv(st)[len(cp) + 1:] # +1 to strip the leading '-' slashparts = cp.split("/") self.category = slashparts[0] self.name = slashparts[1]
def testDepGetCPV(self): prefix_ops = ["<", ">", "=", "~", "<=", ">=", "!=", "!<", "!>", "!~"] bad_prefix_ops = [ ">~", "<~", "~>", "~<" ] postfix_ops = [ ("=", "*"), ] cpvs = ["sys-apps/portage-2.1", "sys-apps/portage-2.1", "sys-apps/portage-2.1"] slots = [None, ":foo", ":2"] for cpv in cpvs: for slot in slots: for prefix in prefix_ops: mycpv = prefix + cpv if slot: mycpv += slot self.assertEqual( dep_getcpv( mycpv ), cpv ) for prefix, postfix in postfix_ops: mycpv = prefix + cpv + postfix if slot: mycpv += slot self.assertEqual( dep_getcpv( mycpv ), cpv )
def read_config_files(): global toskip, from_date # # Read ebuilds to skip in the re-compilation # fd = open(conf_toskip, 'r') toskip_lines = fd.readlines() fd.close() for atom in toskip_lines: # Whitespace cleanup atom = re.sub('\s+', '', atom) if not re.match('^#.*|^$', atom) and isvalidatom(atom): toskip.append(dep_getcpv(atom)) # # Read from_date value from the config file # if os.path.isfile(conf_fromdate): fd = open(conf_fromdate, 'r') from_date = fd.readline() fd.close() else: raise EwoError("The starting point has not been set!\nPlease specify it using -s option first")
def findUseFlagCombis(package, config, port): """ Generate combinations of use flags to test The output will be a list each containing a ready to use USE=... string """ uselist = sorted( reduce_flags(get_flags(dep_getcpv(package.packageString())))) # The uselist could have duplicates due to slot-conditional # output of equery uselist = unique(uselist) for i in config['ignoreprefix']: uselist = [u for u in uselist if not re.match(i, u)] ruse = " ".join( port.aux_get(dep_getcpv(package.packageString()), ["REQUIRED_USE"])) swlist = [] if config['usecombis'] == 0: # Do only all and nothing: if check_uses(ruse, uselist, 0, package): swlist.append(0) if check_uses(ruse, uselist, 2**len(uselist) - 1): swlist.append(2**len(uselist) - 1) # Test if we can exhaust all USE-combis by computing the binary logarithm. elif len(uselist) > math.log(config['usecombis'], 2): # Generate a sample of USE combis s = 2**(len(uselist)) rnds = set() random.seed() while len(swlist) < config['usecombis'] and len(rnds) < s: r = random.randint(0, s - 1) if r in rnds: # already checked continue rnds.add(r) if not check_uses(ruse, uselist, r, package): # invalid combination continue swlist.append(r) swlist.sort() else: # Yes we can: generate all combinations for pos in range(2**len(uselist)): if check_uses(ruse, uselist, pos, package): swlist.append(pos) usecombis = [] for sw in swlist: mod = [] for pos in range(len(uselist)): if ((2**pos) & sw): mod.append("") else: mod.append("-") usecombis.append(" ".join( ["".join(uf) for uf in list(zip(mod, uselist))])) # Merge everything to a USE="" string return ["USE=\'" + uc + "\'" for uc in usecombis]
def findUseFlagCombis(package, config, port): """ Generate combinations of use flags to test The output will be a list each containing a ready to use USE=... string """ uselist = sorted( reduce_flags(get_flags(dep_getcpv(package.packageString())))) # The uselist could have duplicates due to slot-conditional # output of equery uselist = unique(uselist) for i in config['ignoreprefix']: uselist = [u for u in uselist if not re.match(i, u)] ruse = " ".join( port.aux_get(dep_getcpv(package.packageString()), ["REQUIRED_USE"])) swlist = [] if config['usecombis'] == 0: # Do only all and nothing: if check_uses(ruse, uselist, 0, package): swlist.append(0) if check_uses(ruse, uselist, 2**len(uselist) - 1): swlist.append(2**len(uselist) - 1) # Test if we can exhaust all USE-combis by computing the binary logarithm. elif len(uselist) > math.log(config['usecombis'], 2): # Generate a sample of USE combis s = 2**(len(uselist)) rnds = set() random.seed() attempts = 0 ignore_use_expand = False while len(swlist) < config['usecombis'] and len(rnds) < s: if attempts >= 10000: if not ignore_use_expand: # After 10000 attempts, let's give up on USE_EXPAND. ignore_use_expand = True attempts = 0 print( "Giving up on USE_EXPAND after {0} tries to find valid USE combinations" .format(attempts)) print("We've found {0} USE combinations so far".format( len(swlist))) uselist = [use for use in uselist if not "_" in use] else: # Let's give up entirely and use what we have. print( "Giving up on finding more USE combinations after {0} further attempts" .format(attempts)) print("We've found {0} USE combinations".format( len(swlist))) break r = random.randint(0, s - 1) if r in rnds: # already checked continue rnds.add(r) if not check_uses(ruse, uselist, r, package): attempts += 1 # invalid combination continue swlist.append(r) swlist.sort() else: # Yes we can: generate all combinations for pos in range(2**len(uselist)): if check_uses(ruse, uselist, pos, package): swlist.append(pos) usecombis = [] for sw in swlist: mod = [] for pos in range(len(uselist)): if ((2**pos) & sw): mod.append("") else: mod.append("-") usecombis.append(" ".join( ["".join(uf) for uf in list(zip(mod, uselist))])) # Merge everything to a USE="" string return ["USE=\'" + uc + "\'" for uc in usecombis]