Gentoo Archives: gentoo-portage-dev

From: Zac Medico <zmedico@g.o>
To: gentoo-portage-dev@l.g.o
Cc: Zac Medico <zmedico@g.o>
Subject: [gentoo-portage-dev] [PATCH 1/5] Add egencache --update-pkg-desc-index action.
Date: Sat, 01 Nov 2014 22:46:36
Message-Id: 1414881983-19877-2-git-send-email-zmedico@gentoo.org
In Reply to: [gentoo-portage-dev] by Zac Medico
1 This adds an egencache --update-pkg-desc-index action which generates
2 a plain-text index of package names, versions, and descriptions. The
3 index can then be used to optimize emerge --search / --searchdesc
4 actions.
5
6 X-Gentoo-Bug: 525718
7 X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=525718
8 ---
9 bin/egencache | 38 ++++++++++++++++++++++--
10 man/egencache.1 | 4 +++
11 man/portage.5 | 12 ++++++++
12 pym/portage/cache/index/__init__.py | 2 ++
13 pym/portage/cache/index/pkg_desc_index.py | 48 +++++++++++++++++++++++++++++++
14 5 files changed, 102 insertions(+), 2 deletions(-)
15 create mode 100644 pym/portage/cache/index/__init__.py
16 create mode 100644 pym/portage/cache/index/pkg_desc_index.py
17
18 diff --git a/bin/egencache b/bin/egencache
19 index e366058..f97432f 100755
20 --- a/bin/egencache
21 +++ b/bin/egencache
22 @@ -48,6 +48,7 @@ portage._internal_caller = True
23 from portage import os, _encodings, _unicode_encode, _unicode_decode
24 from _emerge.MetadataRegen import MetadataRegen
25 from portage.cache.cache_errors import CacheError, StatCollision
26 +from portage.cache.index.pkg_desc_index import pkg_desc_index_line_format
27 from portage.const import TIMESTAMP_FORMAT
28 from portage.manifest import guessManifestFileType
29 from portage.package.ebuild._parallel_manifest.ManifestScheduler import ManifestScheduler
30 @@ -57,7 +58,7 @@ from portage.util._async.run_main_scheduler import run_main_scheduler
31 from portage.util._eventloop.global_event_loop import global_event_loop
32 from portage import cpv_getkey
33 from portage.dep import Atom, isjustname
34 -from portage.versions import pkgsplit, vercmp
35 +from portage.versions import pkgsplit, vercmp, _pkg_str
36
37 try:
38 from xml.etree import ElementTree
39 @@ -91,6 +92,9 @@ def parse_args(args):
40 actions.add_argument("--update-changelogs",
41 action="store_true",
42 help="update the ChangeLog files from SCM logs")
43 + actions.add_argument("--update-pkg-desc-index",
44 + action="store_true",
45 + help="update package description index")
46 actions.add_argument("--update-manifests",
47 action="store_true",
48 help="update manifests")
49 @@ -451,6 +455,29 @@ class GenCache(object):
50 if hasattr(trg_cache, '_prune_empty_dirs'):
51 trg_cache._prune_empty_dirs()
52
53 +class GenPkgDescIndex(object):
54 + def __init__(self, portdb, output_file):
55 + self.returncode = os.EX_OK
56 + self._portdb = portdb
57 + self._output_file = output_file
58 +
59 + def run(self):
60 +
61 + portage.util.ensure_dirs(os.path.dirname(self._output_file))
62 + f = portage.util.atomic_ofstream(self._output_file,
63 + encoding=_encodings["repo.content"])
64 +
65 + portdb = self._portdb
66 + for cp in portdb.cp_all():
67 + pkgs = portdb.cp_list(cp)
68 + if not pkgs:
69 + continue
70 + desc, = portdb.aux_get(pkgs[-1], ["DESCRIPTION"])
71 +
72 + f.write(pkg_desc_index_line_format(cp, pkgs, desc))
73 +
74 + f.close()
75 +
76 class GenUseLocalDesc(object):
77 def __init__(self, portdb, output=None,
78 preserve_comments=False):
79 @@ -893,7 +920,8 @@ def egencache_main(args):
80 local_config=False, env=env)
81
82 if not (options.update or options.update_use_local_desc or
83 - options.update_changelogs or options.update_manifests):
84 + options.update_changelogs or options.update_manifests or
85 + options.update_pkg_desc_index):
86 parser.error('No action specified')
87 return 1
88
89 @@ -1057,6 +1085,12 @@ def egencache_main(args):
90 else:
91 ret.append(scheduler.returncode)
92
93 + if options.update_pkg_desc_index:
94 + gen_index = GenPkgDescIndex(portdb, os.path.join(
95 + repo_config.location, "metadata", "pkg_desc_index"))
96 + gen_index.run()
97 + ret.append(gen_index.returncode)
98 +
99 if options.update_use_local_desc:
100 gen_desc = GenUseLocalDesc(portdb,
101 output=options.uld_output,
102 diff --git a/man/egencache.1 b/man/egencache.1
103 index f71feb3..3a3197f 100644
104 --- a/man/egencache.1
105 +++ b/man/egencache.1
106 @@ -19,6 +19,10 @@ for the details on package atom syntax.
107 .BR "\-\-update\-changelogs"
108 Update the ChangeLog files from SCM logs (supported only in git repos).
109 .TP
110 +.BR "\-\-update\-pkg\-desc\-index"
111 +Update the package description index which is located at
112 +\fImetadata/pkg_desc_index\fR in the repository.
113 +.TP
114 .BR "\-\-update\-use\-local\-desc"
115 Update the \fIprofiles/use.local.desc\fR file from metadata.xml.
116 .TP
117 diff --git a/man/portage.5 b/man/portage.5
118 index 309e259..f2f5243 100644
119 --- a/man/portage.5
120 +++ b/man/portage.5
121 @@ -76,6 +76,7 @@ user\-defined package sets
122 .BR /usr/portage/metadata/
123 .nf
124 layout.conf
125 +pkg_desc_index
126 .fi
127 .TP
128 .BR /usr/portage/profiles/
129 @@ -1138,6 +1139,17 @@ cache\-formats = md5-dict pms
130 profile\-formats = portage-2
131 .fi
132 .RE
133 +.TP
134 +.BR pkg_desc_index
135 +This is an index of package names, versions, and descriptions which
136 +may be generated by \fBegencache\fR(1) in order to optimize
137 +\fBemerge\fR(1) search actions.
138 +
139 +.I Example:
140 +.nf
141 +sys-apps/sed 4.2 4.2.1 4.2.1-r1 4.2.2: Super-useful stream editor
142 +sys-apps/usleep 0.1: A wrapper for usleep
143 +.fi
144 .RE
145 .TP
146 .BR /usr/portage/profiles/
147 diff --git a/pym/portage/cache/index/__init__.py b/pym/portage/cache/index/__init__.py
148 new file mode 100644
149 index 0000000..7cd880e
150 --- /dev/null
151 +++ b/pym/portage/cache/index/__init__.py
152 @@ -0,0 +1,2 @@
153 +# Copyright 2014 Gentoo Foundation
154 +# Distributed under the terms of the GNU General Public License v2
155 diff --git a/pym/portage/cache/index/pkg_desc_index.py b/pym/portage/cache/index/pkg_desc_index.py
156 new file mode 100644
157 index 0000000..7a05984
158 --- /dev/null
159 +++ b/pym/portage/cache/index/pkg_desc_index.py
160 @@ -0,0 +1,48 @@
161 +# Copyright 2014 Gentoo Foundation
162 +# Distributed under the terms of the GNU General Public License v2
163 +
164 +import collections
165 +
166 +from portage.dep import Atom
167 +from portage.exception import InvalidAtom, InvalidData
168 +from portage.versions import _pkg_str
169 +
170 +pkg_desc_index_node = collections.namedtuple("pkg_desc_index_node",
171 + ["cp", "cpv_list", "desc"])
172 +
173 +def pkg_desc_index_line_format(cp, pkgs, desc):
174 + return "%s %s: %s\n" % (cp,
175 + " ".join(_pkg_str(cpv).version
176 + for cpv in pkgs), desc)
177 +
178 +def pkg_desc_index_line_read(line, repo = None):
179 +
180 + try:
181 + pkgs, desc = line.split(":", 1)
182 + except ValueError:
183 + return None
184 + desc = desc.strip()
185 +
186 + try:
187 + cp, pkgs = pkgs.split(" ", 1)
188 + except ValueError:
189 + return None
190 +
191 + try:
192 + atom = Atom(cp)
193 + except InvalidAtom:
194 + return None
195 + if cp != atom.cp:
196 + return None
197 +
198 + cp_list = []
199 + for ver in pkgs.split():
200 + try:
201 + cpv = _pkg_str(
202 + cp + "-" + ver, repo = repo)
203 + except InvalidData:
204 + pass
205 + else:
206 + cp_list.append(cpv)
207 +
208 + return pkg_desc_index_node(cp, tuple(cp_list), desc)
209 --
210 2.0.4

Replies