aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Dolbec <dolsen@gentoo.org>2014-12-26 13:15:22 -0800
committerBrian Dolbec <dolsen@gentoo.org>2014-12-30 13:42:25 -0800
commit244ace4fee1054945eb97aad31919dba71374b0b (patch)
treee54a907d8187c6713b9354780ed39ef833835c18 /gkeys/gkeys/seed.py
parentremove unused imports (diff)
downloadgentoo-keys-244ace4fee1054945eb97aad31919dba71374b0b.tar.gz
gentoo-keys-244ace4fee1054945eb97aad31919dba71374b0b.tar.bz2
gentoo-keys-244ace4fee1054945eb97aad31919dba71374b0b.zip
gkeys: Add key-search action
Add _list_search() sub function. Add category output and grouping. Fix arg as a list searching as well as seed values as a list. Use recursion to get to single value searches. Make nick search to be partial unless --exact specified. Move main key_search code to SeedHandler class, it is much better suited to this class. Add 1name subparser option for single name entries only Add seen tracking in key_search to eliminate duplicates Add --all option to key-search If --all is specified, it filters out search results to match a seed for all criteria specified.
Diffstat (limited to 'gkeys/gkeys/seed.py')
-rw-r--r--gkeys/gkeys/seed.py43
1 files changed, 42 insertions, 1 deletions
diff --git a/gkeys/gkeys/seed.py b/gkeys/gkeys/seed.py
index f0cb019..2406c1a 100644
--- a/gkeys/gkeys/seed.py
+++ b/gkeys/gkeys/seed.py
@@ -160,7 +160,48 @@ class Seeds(object):
try:
return self.seeds[nick]
except KeyError:
- return None
+ return []
+
+
+ def field_search(self, field, value, exact=False):
+ '''Searches the seeds for a matching nick
+
+ @param keyid: string
+ @returns GKEY instance or None
+ '''
+ results = []
+ if field == 'nick' and exact:
+ return self.nick_search(value)
+ for nick in self.seeds:
+ seed = self.seeds[nick]
+ val = getattr(seed, field)
+ if isinstance(val, list) or isinstance(value, list):
+ if self._list_search(value, val, exact):
+ results.append(seed)
+ elif exact:
+ if value in val:
+ results.append(seed)
+ else:
+ if value.lower() in val.lower():
+ results.append(seed)
+
+ return results
+
+
+ def _list_search(self, find, values, exact):
+ if isinstance(find, list):
+ found = []
+ for f in find:
+ found.append(self._list_search(f, values, exact))
+ return True in found
+ for val in values:
+ if exact:
+ if find in val:
+ return True
+ else:
+ if find.lower() in val.lower():
+ return True
+ return False
def _error(self, err):