diff options
author | 2017-08-22 06:51:29 +0300 | |
---|---|---|
committer | 2017-08-22 06:51:29 +0300 | |
commit | 9bdda7f338769572425d8e6c2df93cd4fae4a728 (patch) | |
tree | ac374890483a867078dc23c877426519ba0a0a2c | |
parent | Initial implementation of zugaina picker gui (diff) | |
download | pomu-9bdda7f338769572425d8e6c2df93cd4fae4a728.tar.gz pomu-9bdda7f338769572425d8e6c2df93cd4fae4a728.tar.bz2 pomu-9bdda7f338769572425d8e6c2df93cd4fae4a728.zip |
Finished zugaina searcher and picker
removed extraneous text from iquery.py
added a unified_ver option to cpv_split
-rw-r--r-- | pomu/data/zugaina.py | 4 | ||||
-rw-r--r-- | pomu/search.py | 42 | ||||
-rw-r--r-- | pomu/util/iquery.py | 2 | ||||
-rw-r--r-- | pomu/util/pkg.py | 7 |
4 files changed, 44 insertions, 11 deletions
diff --git a/pomu/data/zugaina.py b/pomu/data/zugaina.py index 6f67444..14a3ddd 100644 --- a/pomu/data/zugaina.py +++ b/pomu/data/zugaina.py @@ -5,6 +5,7 @@ import lxml.html import requests from pomu.data.datasource import DataSource +from pomu.util.pkg import cpv_split BASE_URL = 'https://gpo.zugaina.org/' SBASE_URL = BASE_URL + 'Search?search={}&page={}' @@ -39,8 +40,9 @@ class ZugainaDataSource(DataSource): for div in doc.xpath('//div[@id="ebuild_list"]/ul/div'): id_ = div.xpath('li/a')[0].get('href').split('/')[3] pv = div.xpath('li/div/b')[0].text + v = cpv_split(pv, True)[2] overlay = div.xpath('@id') - res.append((id_, pv, overlay)) + res.append((id_, v, overlay)) return res def get_item(self, ident): diff --git a/pomu/search.py b/pomu/search.py index 6f0a2b0..e77ed1a 100644 --- a/pomu/search.py +++ b/pomu/search.py @@ -28,7 +28,7 @@ class Entry: return len(self.children) + 1 if self.expanded else 1 def selected(self): - return [child for child in self.children if child[0]] + return [child[1] for child in self.children if child[0]] class PromptState(Enum): TOP_PREV=0 @@ -44,6 +44,19 @@ class PSPrompt(Prompt): self.state = PromptState.LIST self.set_page(1) + def results(): + # (cp, v, overlay, data) + res = [] + for k, v in self. itemitems(): + for entry in v: + cp = entry.item[0] + for child in entry.selected(): + cid, v, overlay = *child + data = self.data.get_item(cid) + res.append((cp, v, overlay, data)) + return res + + def set_page(self, page): self.idx = 0 self.page = page @@ -77,7 +90,7 @@ class PSPrompt(Prompt): stt = '*' if hld else ' ' text = ' [' + invert(stt) if idx == 0 else stt + '] ' text += '{}::{}'.format(data[1], data[2]) - else if entry[0]: + elif entry[0]: data = entry[0] exp = 'v' if entry.expanded else '>' text = '[' + invert(exp) if idx == 0 else exp + '] ' @@ -89,6 +102,19 @@ class PSPrompt(Prompt): text = '' return text + def process_event(self, event): + res = super().process_event(event) + if res: + return res + elif event == '<TAB>': + self.state = (self.state + 1) % 2 + elif event in {'<Ctrl-j>', '<Ctrl-m>'}: + if self.state < 2: + return -1 + else: + return False + return True + def __len__(self): return sum(lun(y) for y in self.entries) @@ -101,6 +127,10 @@ class PSPrompt(Prompt): def clamp(self, x): return clamp(x, 0, len(self)) + def toggle(self): + item, idx = self.get_idx(self.idx) + item.toggle(idx) + def preview(self): target = self.get_target() if target[1]: @@ -109,21 +139,21 @@ class PSPrompt(Prompt): def lens(self): h = self.window.height - 2 - lst = [self.get_idx(i) for i in range(self.idx, self.clamp(self.idx + h))] + lst = [self.get_idx(i)[0] for i in range(self.idx, self.clamp(self.idx + h))] lst += [(None, None)] * clamp(h - len(lst), 0, h) return lst def get_target(self): - return get_idx(self.idx) + return get_idx(self.idx)[0] def get_idx(self, idx): for entry in self.entries(): if len(entry) > idx: break idx -= len(entry) - return entry.get_idx(idx) + return (entry.get_idx(idx), idx) - def process_entry(self, entry): + def process_entry(self, item): return Entry(item, self.data) def run(self): diff --git a/pomu/util/iquery.py b/pomu/util/iquery.py index 606d79d..d0281a3 100644 --- a/pomu/util/iquery.py +++ b/pomu/util/iquery.py @@ -164,8 +164,6 @@ class EditSelectPrompt(Prompt): self.list = True elif isinstance(event, str) and not event.startswith('<'): self.add_char(event) - else, - **args: return False return True diff --git a/pomu/util/pkg.py b/pomu/util/pkg.py index 56afff6..ac7c55a 100644 --- a/pomu/util/pkg.py +++ b/pomu/util/pkg.py @@ -14,7 +14,7 @@ def ver_str(vernum, suff, rev): """Gets the string representation of the version (specified by number, suffix and rev)""" return vernum + (suff if suff else '') + (rev if rev else '') -def cpv_split(pkg): +def cpv_split(pkg, unified_ver=False): """ Extracts category, name, version number, suffix, revision from a package descriptor e.g. dev-libs/openssl-0.9.8z_p8-r100 -> dev-libs, openssl, 0.9.8z, p8, r100 @@ -41,4 +41,7 @@ def cpv_split(pkg): vernum = None # openssl name = pkg - return category, name, vernum, suff, rev + if unified_ver: + return category, name, ver_str(vernum, suff, rev) + else: + return category, name, vernum, suff, rev |