[gentoo-portage-dev] [PATCH] emerge --search: auto-detect regular expressions (bug 737480)

2020-08-31 Thread Zac Medico
Automatically detect regular expressions when the search string
contains any of these regular expression characters:

  ^$*[]{}|?

This simplifies usage, so that users no longer have to remember
to prefix regular expressions with the % character. The new
behavior can be disabled by --regex-search-auto=n, in case the
regular expressions interpretation causes some kind of problem.

Note that fuzzy search and regular expression search are
mutually exclusive, and fuzzy search remains the default for
search strings that do not contain any regular expression
characters.

Bug: https://bugs.gentoo.org/737480
Signed-off-by: Zac Medico 
---
 lib/_emerge/actions.py |  1 +
 lib/_emerge/main.py|  6 ++
 lib/_emerge/search.py  | 12 +++-
 man/emerge.1   | 11 ++-
 4 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/lib/_emerge/actions.py b/lib/_emerge/actions.py
index a4ecfe43d..f57269817 100644
--- a/lib/_emerge/actions.py
+++ b/lib/_emerge/actions.py
@@ -2036,6 +2036,7 @@ def action_search(root_config, myopts, myfiles, spinner):
search_index=myopts.get("--search-index", "y") != "n",
search_similarity=myopts.get("--search-similarity"),
fuzzy=myopts.get("--fuzzy-search") != "n",
+   regex_auto=myopts.get("--regex-search-auto") != "n",
)
for mysearch in myfiles:
try:
diff --git a/lib/_emerge/main.py b/lib/_emerge/main.py
index 975738762..5075f7f57 100644
--- a/lib/_emerge/main.py
+++ b/lib/_emerge/main.py
@@ -709,6 +709,12 @@ def parse_opts(tmpcmdline, silent=False):
"action" : "store"
},
 
+   "--regex-search-auto": {
+   "help"   : "Enable or disable automatic regular 
expression detection for search actions",
+   "choices": y_or_n,
+   "default": "y",
+   },
+
"--root": {
 "help"   : "specify the target root filesystem for merging 
packages",
 "action" : "store"
diff --git a/lib/_emerge/search.py b/lib/_emerge/search.py
index a59191c1a..a23c2db80 100644
--- a/lib/_emerge/search.py
+++ b/lib/_emerge/search.py
@@ -28,7 +28,7 @@ class search:
#
def __init__(self, root_config, spinner, searchdesc,
verbose, usepkg, usepkgonly, search_index=True,
-   search_similarity=None, fuzzy=True):
+   search_similarity=None, fuzzy=True, regex_auto=False):
"""Searches the available and installed packages for the 
supplied search key.
The list of available and installed packages is created at 
object instantiation.
This makes successive searches faster."""
@@ -42,6 +42,7 @@ class search:
self.spinner = None
self.root_config = root_config
self.setconfig = root_config.setconfig
+   self.regex_auto = regex_auto
self.fuzzy = fuzzy
self.search_similarity = (80 if search_similarity is None
else search_similarity)
@@ -259,6 +260,15 @@ class search:
if '/' in self.searchkey:
match_category = 1
fuzzy = False
+
+   if self.regex_auto and not regexsearch and 
re.search(r'[^$*\[\]{}|?]', self.searchkey) is not None:
+   try:
+   re.compile(self.searchkey, re.I)
+   except Exception:
+   pass
+   else:
+   regexsearch = True
+
if regexsearch:
self.searchre=re.compile(self.searchkey,re.I)
else:
diff --git a/man/emerge.1 b/man/emerge.1
index fe7d05a21..f2783e7a1 100644
--- a/man/emerge.1
+++ b/man/emerge.1
@@ -229,7 +229,9 @@ explicitly discarded by running `emaint \-\-fix 
cleanresume` (see
 .BR \-\-search ", " \-s
 Searches for matches of the supplied string in the ebuild repository.
 By default emerge uses a case-insensitive simple search, but you can
-enable a regular expression search by prefixing the search string with %.
+enable a regular expression search by prefixing the search string with %
+(the % prefix can often be omitted if the
+\fB\-\-regex\-search\-auto\fR option is enabled).
 For example, \fBemerge \-\-search "%^kde"\fR searches for any package whose
 name starts with "kde"; \fBemerge \-\-search "%gcc$"\fR searches for any
 package that ends with "gcc"; \fBemerge \-\-search "office"\fR searches for
@@ -764,6 +766,13 @@ matching packages due to \fB\-\-rebuild\fR.
 A space separated list of package names or slot atoms. Emerge will not rebuild
 packages that depend on matching packages due to \fB\-\-rebuild\fR.
 .TP
+.BR "\-\-regex\-search\-auto < y | n >"
+Enable or disable automatic regular 

Re: [gentoo-dev] [PATCH] acct-*.eclass: Create sysusers.d files

2020-08-31 Thread Marek Szuba
On 2020-08-29 21:53, Michał Górny wrote:

> + newins - ${CATEGORY}-${ACCT_USER_NAME}.conf < <(
> + printf "u\t%q\t%q\t%q\t%q\t%q\n" \
> + "${ACCT_USER_NAME}" \
> + "${ACCT_USER_ID/#-*/-}:${ACCT_USER_GROUPS[0]}" \
> + "${DESCRIPTION//[:,=]/;}" \

Maybe it's a fault in how I have tested this (i.e. in an interactive
bash session, by setting all the variables and copy-pasting the relevant
printf lines by hand) but for me this results in an unquoted GECOS
string with spaces escaped with backslashes, whereas sysusers.d(5)
explicitly states this should be enclosed in quotation marks. Could you
double-check, please?

Otherwise LGTM.

-- 
MS



signature.asc
Description: OpenPGP digital signature