예제 #1
0
파일: usecombis.py 프로젝트: tom111/tatt
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]
예제 #2
0
파일: uses.py 프로젝트: zmedico/gentoolkit
def get_output_descriptions(pkg, global_usedesc):
	"""Prepare descriptions and usage information for each USE flag."""

	if pkg.metadata is None:
		local_usedesc = []
	else:
		local_usedesc = pkg.metadata.use()

	iuse, final_use = get_flags(pkg.cpv, final_setting=True)
	usevar = reduce_flags(iuse)
	usevar.sort()

	if QUERY_OPTS['ignore_l10n']:
		for a in usevar[:]:
			#TODO: Remove linguas after transition to l10n is complete
			if a.startswith("l10n_") or a.startswith("linguas_"):
				usevar.remove(a)


	if pkg.is_installed():
		used_flags = pkg.use().split()
	else:
		used_flags = settings["USE"].split()

	# store (inuse, inused, flag, desc, restrict)
	output = []
	for flag in usevar:
		inuse = False
		inused = False

		local_use = None
		for use in local_usedesc:
			if use.name == flag:
				local_use = use
				break

		try:
			desc = local_use.description
		except AttributeError:
			try:
				desc = global_usedesc[flag]
			except KeyError:
				desc = ""

		try:
			restrict = local_use.restrict
			restrict = restrict if restrict is not None else ""
		except AttributeError:
			restrict = ""

		if flag in final_use:
			inuse = True
		if flag in used_flags:
			inused = True

		output.append((inuse, inused, flag, desc, restrict))

	return output
예제 #3
0
파일: uses.py 프로젝트: pamxy/gentoolkit
def get_output_descriptions(pkg, global_usedesc):
	"""Prepare descriptions and usage information for each USE flag."""

	if pkg.metadata is None:
		local_usedesc = []
	else:
		local_usedesc = pkg.metadata.use()

	iuse, final_use = get_flags(pkg.cpv, final_setting=True)
	usevar = reduce_flags(iuse)
	usevar.sort()

	if QUERY_OPTS['ignore_linguas']:
		for a in usevar[:]:
			if a.startswith("linguas_"):
				usevar.remove(a)


	if pkg.is_installed():
		used_flags = pkg.use().split()
	else:
		used_flags = settings["USE"].split()

	# store (inuse, inused, flag, desc, restrict)
	output = []
	for flag in usevar:
		inuse = False
		inused = False

		local_use = None
		for use in local_usedesc:
			if use.name == flag:
				local_use = use
				break

		try:
			desc = local_use.description
		except AttributeError:
			try:
				desc = global_usedesc[flag]
			except KeyError:
				desc = ""

		try:
			restrict = local_use.restrict
			restrict = restrict if restrict is not None else ""
		except AttributeError:
			restrict = ""

		if flag in final_use:
			inuse = True
		if flag in used_flags:
			inused = True

		output.append((inuse, inused, flag, desc, restrict))

	return output
예제 #4
0
def get_output_descriptions(pkg, global_usedesc):
	"""Prepare descriptions and usage information for each USE flag."""

	if pkg.metadata is None:
		local_usedesc = []
	else:
		local_usedesc = pkg.metadata.use()

	iuse, final_use = get_flags(pkg.cpv, final_setting=True)
	usevar = reduce_flags(iuse)
	usevar.sort()
	

	if pkg.is_installed():
		used_flags = pkg.use().split()
	else:
		used_flags = settings["USE"].split()

	# store (inuse, inused, flag, desc, restrict)
	output = []
	for flag in usevar:
		inuse = False
		inused = False

		local_use = None
		for use in local_usedesc:
			if use.name == flag:
				local_use = use
				break

		try:
			desc = local_use.description
		except AttributeError:
			try:
				desc = global_usedesc[flag]
			except KeyError:
				desc = ""

		try:
			restrict = local_use.restrict
			restrict = restrict if restrict is not None else ""
		except AttributeError:
			restrict = ""

		if flag in final_use:
			inuse = True
		if flag in used_flags:
			inused = True

		output.append((inuse, inused, flag, desc, restrict))

	return output
예제 #5
0
    def analyse_cpv(self, cpv):
        """Gets all relavent USE flag info for a cpv and breaks them down
		into 3 sets, plus (package.use enabled), minus ( package.use disabled),
		unset.

		@param cpv: string. 'cat/pkg-ver'
		@rtype tuple of sets
		@return (plus, minus, unset) sets of USE flags
		"""
        installed = set(self.get_used(cpv, self.target))
        _iuse = self.get_flags(cpv)
        iuse = set(reduce_flags(_iuse))
        iuse_defaults = defaulted_flags(_iuse)
        return self._analyse(installed, iuse, iuse_defaults)
예제 #6
0
파일: lib.py 프로젝트: zmedico/gentoolkit
	def analyse_cpv(self, cpv):
		"""Gets all relavent USE flag info for a cpv and breaks them down
		into 3 sets, plus (package.use enabled), minus ( package.use disabled),
		unset.

		@param cpv: string. 'cat/pkg-ver'
		@rtype tuple of sets
		@return (plus, minus, unset) sets of USE flags
		"""
		installed = set(self.get_used(cpv, self.target))
		_iuse = self.get_flags(cpv)
		iuse =  set(reduce_flags(_iuse))
		iuse_defaults = defaulted_flags(_iuse)
		return self._analyse(installed, iuse, iuse_defaults)
예제 #7
0
    def analyse_pkg(self, pkg):
        """Gets all relevent USE flag info for a pkg and breaks them down
		into 3 sets, plus (package.use enabled), minus ( package.use disabled),
		unset.

		@param pkg: gentoolkit.package.Package object
		@rtype tuple of sets
		@return (plus, minus, unset) sets of USE flags
		"""
        installed = set(self.pkg_used(pkg))
        #print("installed =", installed)
        _iuse = self.pkg_flags(pkg)
        iuse = set(reduce_flags(_iuse))
        iuse_defaults = defaulted_flags(_iuse)
        #print("iuse =", iuse)
        return self._analyse(installed, iuse, iuse_defaults)
예제 #8
0
파일: lib.py 프로젝트: zmedico/gentoolkit
	def analyse_pkg(self, pkg):
		"""Gets all relevent USE flag info for a pkg and breaks them down
		into 3 sets, plus (package.use enabled), minus ( package.use disabled),
		unset.

		@param pkg: gentoolkit.package.Package object
		@rtype tuple of sets
		@return (plus, minus, unset) sets of USE flags
		"""
		installed = set(self.pkg_used(pkg))
		#print("installed =", installed)
		_iuse =  self.pkg_flags(pkg)
		iuse =  set(reduce_flags(_iuse))
		iuse_defaults = defaulted_flags(_iuse)
		#print("iuse =", iuse)
		return self._analyse(installed, iuse, iuse_defaults)
예제 #9
0
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]
예제 #10
0
파일: usecombis.py 프로젝트: wraeth/tatt
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]