self.lines = [self.header()]
- def __call__(self, key, values):
- if self.target in ["keywords"]:
- self._format_atoms(key, values)
+ def __call__(self, key, values, cp_count):
+ if self.target in ["keywords", "use"]:
+ self._format_atoms(key, values, cp_count)
else:
self._format_key(key, values)
self.data[_key] = values
self.print_fn( _key, values)
- def print_use(self, key, values):
+ def print_use(self, key, atom=None, values=None):
"""Prints a USE flag string.
"""
+ if atom and not values:
+ values = atom.use
if self.pretend:
flags = []
for flag in values:
line = ' '.join([key, ' '.join(values)])
self.lines.append(line)
- def _format_atoms(self, key, atoms):
+ def _format_atoms(self, key, atoms, count):
"""Determines if there are more than one atom in the values and
calls the predetermined print function for each atom.
"""
#print("_format_atoms(),", key, atoms)
if self.exact:
for atom in atoms:
- self.print_fn(str(atom), atom.keyword)
+ self.print_fn(str(atom), atom=atom)
return
- many = False
- if len(atoms) >1:
- many = True
- if self.slot or many:
+ #print("_format_atoms(), count =", count)
+ if self.slot or count > 1:
for atom in atoms:
_key = str(atom.cp) + ":" + atom.slot
- self.print_fn(_key, atom.keyword)
+ self.print_fn(_key, atom=atom)
else:
for atom in atoms:
_key = str(atom.cp)
- self.print_fn(_key, atom.keyword)
+ self.print_fn(_key, atom=atom)
return
- def print_keyword(self, key, keyword):
+ def print_keyword(self, key, atom=None, keyword=None):
"""prints a pkg key and a keyword"""
#print("print_keyword(),", key, keyword)
+ if atom and not keyword:
+ keyword = atom.keyword
if self.pretend:
print(self._format_values(key, keyword))
else:
cpvs = VARDB.cpv_all()
cpvs.sort()
data = {}
+ cp_counts = {}
# pass them in to override for tests
flags = FlagAnalyzer(system_flags,
filter_defaults=True,
)
for cpv in cpvs:
plus, minus, unset = flags.analyse_cpv(cpv)
+ atom = Atom("="+cpv)
+ atom.slot = VARDB.aux_get(atom.cpv, ["SLOT"])[0]
for flag in minus:
plus.add("-"+flag)
if len(plus):
- data[cpv] = list(plus)
- return data
+ if atom.cp not in data:
+ data[atom.cp] = []
+ if atom.cp not in cp_counts:
+ cp_counts[atom.cp] = 0
+ atom.use = list(plus)
+ data[atom.cp].append(atom)
+ cp_counts[atom.cp] += 1
+ return data, cp_counts
def cpv_all_diff_keywords(
if cpvs is None:
cpvs = VARDB.cpv_all()
keyword_users = {}
+ cp_counts = {}
for cpv in cpvs:
if cpv.startswith("virtual"):
continue
atom = Atom("="+cpv)
if atom.cp not in keyword_users:
keyword_users[atom.cp] = []
+ if atom.cp not in cp_counts:
+ cp_counts[atom.cp] = 0
if key in ["~"]:
atom.keyword = keyword
atom.slot = VARDB.aux_get(atom.cpv, ["SLOT"])[0]
keyword_users[atom.cp].append(atom)
+ cp_counts[atom.cp] += 1
elif key in ["-"]:
#print "adding cpv to missing:", cpv
atom.keyword = "**"
atom.slot = VARDB.aux_get(atom.cpv, ["SLOT"])[0]
keyword_users[atom.cp].append(atom)
- return keyword_users
+ cp_counts[atom.cp] += 1
+ return keyword_users, cp_counts
class Rebuild(ModuleBase):
print(" do not match the default settings")
system_use = portage.settings["USE"].split()
output = RebuildPrinter(
- "use", self.options["pretend"], self.options["exact"])
- pkgs = cpv_all_diff_use(system_flags=system_use)
+ "use", self.options["pretend"], self.options["exact"],
+ self.options['slot'])
+ pkgs, cp_counts = cpv_all_diff_use(system_flags=system_use)
pkg_count = len(pkgs)
if self.options["verbose"]:
print()
if self.options["pretend"] and not self.options["quiet"]:
print()
print(pp.globaloption(
- " -- These are the installed packages & keywords " +
+ " -- These are the installed packages & use flags " +
"that were detected"))
- print(pp.globaloption(" to need keyword settings other " +
+ print(pp.globaloption(" to need use flag settings other " +
"than the defaults."))
print()
elif not self.options["quiet"]:
print(" -- preparing pkgs for file entries")
for pkg in pkg_keys:
- output(pkg, pkgs[pkg])
+ output(pkg, pkgs[pkg], cp_counts[pkg])
if self.options['verbose']:
message = (pp.emph(" ") +
pp.number(str(pkg_count)) +
#unique.sort()
#print unique
if not self.options["pretend"]:
- filepath = os.path.expanduser('~/package.keywords.test')
+ filepath = os.path.expanduser('~/package.use.test')
self.save_file(filepath, output.lines)
def rebuild_keywords(self):
cpvs = VARDB.cpv_all()
#print "Total number of installed ebuilds =", len(cpvs)
- pkgs = cpv_all_diff_keywords(
+ pkgs, cp_counts = cpv_all_diff_keywords(
cpvs=cpvs,
system_keywords=system_keywords,
use_portage=self.options['portage'],
elif not self.options["quiet"]:
print(" -- preparing pkgs for file entries")
for pkg in pkg_keys:
- output(pkg, pkgs[pkg])
+ output(pkg, pkgs[pkg], cp_counts[pkg])
if not self.options['quiet']:
if self.analyser.mismatched:
print("_________________________________________________")