[game-data-packager] 44/51: make_template: Reuse groups from the base if possible
Simon McVittie
smcv at debian.org
Fri Dec 29 01:23:38 UTC 2017
This is an automated email from the git hooks/post-receive script.
smcv pushed a commit to branch master
in repository game-data-packager.
commit e3551178fd937ffe985cf211fc39d0cada4760da
Author: Simon McVittie <smcv at debian.org>
Date: Thu Dec 28 21:52:09 2017 +0000
make_template: Reuse groups from the base if possible
Signed-off-by: Simon McVittie <smcv at debian.org>
---
game_data_packager/make_template.py | 65 ++++++++++++++++++++++++++++++++-----
1 file changed, 56 insertions(+), 9 deletions(-)
diff --git a/game_data_packager/make_template.py b/game_data_packager/make_template.py
index f89c957..7d18680 100644
--- a/game_data_packager/make_template.py
+++ b/game_data_packager/make_template.py
@@ -208,29 +208,76 @@ class Template:
def reconcile_groups(self, files,
stem=None, provider=None, package=None):
+ names = set()
remaining = set()
- groups = {}
+ groups_found = {}
optional = set()
for f in files:
+ names.add(f.name)
remaining.add(f.name)
+ # If there are pre-existing groups that are strict subsets of
+ # what's left to classify, then take them out, largest first.
if remaining:
- main_group = self.new_group('contents of %s' % stem)
- opt_group = self.new_group('contents of %s - optional' % stem)
+ weighted = []
+
+ for name, g in self.game.groups.items():
+ weighted.append((len(g.group_members), g.name, g))
+
+ weighted.sort(reverse=True)
+
+ for _, _, g in weighted:
+ if g.group_members <= remaining:
+ remaining -= g.group_members
+ groups_found[g.name] = g
+
+ # If there are pre-existing groups with a non-trivial
+ # intersection with what's left to classify, then take those,
+ # largest intersection first.
+ while remaining:
+ weighted = []
+
+ for name, g in self.game.groups.items():
+ intersection = g.group_members & remaining
+
+ # Arbitrarily decide that overlaps of less than 5 are
+ # uninteresting
+ if len(intersection) >= 5:
+ weighted.append((len(intersection), g.name, g))
+
+ if not weighted:
+ break
+
+ weighted.sort(reverse=True)
+
+ for _, _, g in weighted:
+ intersecting_group = self.new_group('%s in %s' % (g.name, stem))
+ intersecting_group.group_members = g.group_members & names
+ disjoint_group = self.new_group('%s not in %s' % (g.name, stem))
+ disjoint_group.group_members = g.group_members - names
+
+ remaining -= intersecting_group.group_members
+
+ # If there's anything left, create new groups.
+ if remaining:
+ prefix = 'remaining ' if groups_found else ''
+
+ main_group = self.new_group('%scontents of %s' % (prefix, stem))
+ opt_group = self.new_group('%scontents of %s - optional' % (prefix, stem))
optional.add(opt_group.name)
- doc_group = self.new_group('contents of %s - documentation' % stem)
+ doc_group = self.new_group('%scontents of %s - documentation' % (prefix, stem))
doc_group.doc = True
- license_group = self.new_group('contents of %s - licenses' % stem)
+ license_group = self.new_group('%scontents of %s - licenses' % (prefix, stem))
license_group.license = True
# only from .deb
- abs_group = self.new_group('contents of %s - absolute paths' % stem)
+ abs_group = self.new_group('%scontents of %s - absolute paths' % (prefix, stem))
abs_group.install_to = '.'
optional.add(abs_group.name)
for g in (
main_group, opt_group, doc_group, license_group, abs_group):
- groups[g.name] = g
+ groups_found[g.name] = g
for n in remaining:
f = self.game.files[n]
@@ -252,12 +299,12 @@ class Template:
if provider:
provider.provides = set()
- for name, g in groups.items():
+ for name, g in groups_found.items():
if g.group_members:
provider.provides.add(name)
if package:
- for name, g in groups.items():
+ for name, g in groups_found.items():
if g.license or g.doc or g.ignorable or name in optional:
package.optional.add(name)
else:
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/game-data-packager.git
More information about the Pkg-games-commits
mailing list