fix the rebuild_keywords slot appended bug.
authorBrian Dolbec <brian.dolbec@gmail.com>
Thu, 24 Feb 2011 01:21:19 +0000 (17:21 -0800)
committerBrian Dolbec <brian.dolbec@gmail.com>
Thu, 24 Feb 2011 01:44:39 +0000 (17:44 -0800)
re-factor rebuild_use to do the same slotted packages entries.
fix some errors where I edited rebuild_use instead of rebuild_keywords print statements.

pym/gentoolkit/analyse/output.py
pym/gentoolkit/analyse/rebuild.py

index a67e8c600b5c4d9ad9cf3dc50434b2a3fa6924af..b193d546ddd15fa6172e4fd4b9f51073f53bb173 100644 (file)
@@ -216,9 +216,9 @@ class RebuildPrinter(CpvValueWrapper):
                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)
 
@@ -236,9 +236,11 @@ class RebuildPrinter(CpvValueWrapper):
                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:
@@ -248,31 +250,31 @@ class RebuildPrinter(CpvValueWrapper):
                        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:
index 0c1ce6e031f20a8b8156b8044045741990f14f3a..091df3aa526f701f27206d28d90f3f17d5adbe49 100644 (file)
@@ -58,6 +58,7 @@ def cpv_all_diff_use(
                cpvs = VARDB.cpv_all()
        cpvs.sort()
        data = {}
+       cp_counts = {}
        # pass them in to override for tests
        flags = FlagAnalyzer(system_flags,
                filter_defaults=True,
@@ -67,11 +68,19 @@ def cpv_all_diff_use(
        )
        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(
@@ -97,6 +106,7 @@ 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
@@ -111,16 +121,20 @@ def cpv_all_diff_keywords(
                        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):
@@ -213,8 +227,9 @@ 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()
@@ -227,15 +242,15 @@ class Rebuild(ModuleBase):
                        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)) +
@@ -248,7 +263,7 @@ class Rebuild(ModuleBase):
                                #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):
@@ -282,7 +297,7 @@ class Rebuild(ModuleBase):
 
                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'],
@@ -303,7 +318,7 @@ class Rebuild(ModuleBase):
                        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("_________________________________________________")