diff options
author | 2017-07-30 04:44:55 +0300 | |
---|---|---|
committer | 2017-07-30 04:44:55 +0300 | |
commit | 61bb0e5af81a9eca17bcddfa2bbfdd2b7d527e15 (patch) | |
tree | 4d0622e065eec018b9f9d14e891b8030ea9ce4da | |
parent | Implemented package updates (diff) | |
download | pomu-61bb0e5af81a9eca17bcddfa2bbfdd2b7d527e15.tar.gz pomu-61bb0e5af81a9eca17bcddfa2bbfdd2b7d527e15.tar.bz2 pomu-61bb0e5af81a9eca17bcddfa2bbfdd2b7d527e15.zip |
Multiple fixes in iquery
correctly display active entry, fix method call parametres, clamp
invocation, parenthesize conditional expressions, handle unicode
implemented fetch_package for all remaining backends
fixed ebuild naming and a logic error in url backend
correctly pass and build filemap, preprocess bug attachments in bugz
-rw-r--r-- | pomu/source/bugz.py | 10 | ||||
-rw-r--r-- | pomu/source/file.py | 4 | ||||
-rw-r--r-- | pomu/source/url.py | 10 | ||||
-rw-r--r-- | pomu/util/iquery.py | 27 |
4 files changed, 34 insertions, 17 deletions
diff --git a/pomu/source/bugz.py b/pomu/source/bugz.py index 8dc92ac..34d98df 100644 --- a/pomu/source/bugz.py +++ b/pomu/source/bugz.py @@ -26,7 +26,7 @@ class BzEbuild(): self.filemap = filemap def fetch(self): - return Package(self.name, '/', self, self.category, self.version, self.filemap) + return Package(self.name, '/', self, self.category, self.version, filemap=self.filemap) @staticmethod def from_data_dir(pkgdir): @@ -61,7 +61,7 @@ class BugzillaSource(): comment_links = [] for comment in comments: comment_links.extend(extract_urls(comment['text'])) - items = attachments + comment_links + items = [(x['file_name'], x['data'].data.decode('utf-8')) for x in attachments] + comment_links if not items: return Result.Err() p = Prompt(items) @@ -71,7 +71,7 @@ class BugzillaSource(): category = query('category', 'Please enter package category').expect() name = query('name', 'Please enter package name').expect() ver = query('version', 'Please specify package version for {}'.format(name)).expect() - fmap = {path.join(category, name, x[2]): x[1] for x in items} + fmap = {path.join(category, name, x[2]): x[1] for x in files} return Result.Ok(BzEbuild(uri, category, name, ver, fmap)) @dispatcher.handler(priority=2) @@ -97,5 +97,9 @@ class BugzillaSource(): return BugzillaSource.parse_link(rem) @classmethod + def fetch_package(self, pkg): + return pkg.fetch() + + @classmethod def from_meta_dir(cls, metadir): return BzEbuild.from_data_dir(cls, metadir) diff --git a/pomu/source/file.py b/pomu/source/file.py index 04624e3..5dbf25d 100644 --- a/pomu/source/file.py +++ b/pomu/source/file.py @@ -70,5 +70,9 @@ class LocalEbuildSource(BaseSource): return LocalEbuildSource.parse_ebuild_path(uri[3:]) @classmethod + def fetch_package(self, pkg): + return pkg.fetch() + + @classmethod def from_meta_dir(cls, metadir): return LocalEbuild.from_data_dir(cls, metadir) diff --git a/pomu/source/url.py b/pomu/source/url.py index 33f51fb..850e69f 100644 --- a/pomu/source/url.py +++ b/pomu/source/url.py @@ -26,7 +26,7 @@ class URLEbuild(PackageBase): def fetch(self): if self.contents: if isinstance(self.contents, str): - self.content = self.content.encode('utf-8') + self.content = self.contents.encode('utf-8') else: fs = grab(self.url) self.content = fs[0][1].encode('utf-8') @@ -35,7 +35,7 @@ class URLEbuild(PackageBase): path.join( self.category, self.name, - '{}/{}-{}.ebuild'.format(self.category, self.name, self.version) + '{}-{}.ebuild'.format(self.name, self.version) ) : self.content}) @staticmethod @@ -61,7 +61,7 @@ class URLGrabberSource(BaseSource): if not (uri.startswith('http://') or uri.startswith('https://')): return Result.Err() - name = query('name', 'Please specify package name'.expect()) + name = query('name', 'Please specify package name').expect() category, _, name = name.rpartition('/') ver = query('version', 'Please specify package version for {}'.format(name)).expect() if not category: @@ -78,5 +78,9 @@ class URLGrabberSource(BaseSource): return URLGrabberSource.parse_ebuild_path(url[4:]) @classmethod + def fetch_package(self, pkg): + return pkg.fetch() + + @classmethod def from_meta_dir(cls, metadir): return URLEbuild.from_data_dir(cls, metadir) diff --git a/pomu/util/iquery.py b/pomu/util/iquery.py index df76251..8d69399 100644 --- a/pomu/util/iquery.py +++ b/pomu/util/iquery.py @@ -18,11 +18,14 @@ def render_entry(entry, width, active=False): # (name, contents, state, value) char = '*' if entry[2] else ' ' w = 3 + fmtstr(entry[0]).width + 2 - text = fmtstr(entry[3]) + if entry[3]: + text = fmtstr(entry[3]) + val = entry[3][:width - w - 2] + '..' if text.width < width - w else entry[3] + else: + val = '' return fmtstr( - '[' + underline(char) if active else char + '] ' + - entry[0] + ' ' + - entry[3][:width - w - 2] + '..' if text.width < width - w else entry[3]) + '[' + (underline(char) if active else char) + '] ' + + entry[0] + ' ' + val) def process_entry(entry): if isinstance(entry, str): @@ -64,7 +67,7 @@ class Prompt: gr = grab(entry) if not gr: del self.entries[self.idx] - self.idx = clamp(self.idx - 1) + self.idx = self.clamp(self.idx - 1) pager('Error: could not fetch '.format(entry)) self.entries[self.idx:self.idx+1] = [process_entry((x[0], x[1].encode('utf-8'))) for x in gr] pager(self.entries[self.idx][1]) @@ -72,16 +75,17 @@ class Prompt: def toggle(self): if self.idx == len(self.entries): return - self.entries[self.idx][3] = not self.entries[self.idx][3] + e = self.entries[self.idx] + self.entries[self.idx] = (e[0], e[1], not e[2], e[3]) def process_event(self, event): if self.list: if event == '<UP>': - self.idx = clamp(self.idx - 1) + self.idx = self.clamp(self.idx - 1) elif event == '<DOWN>': - self.idx = clamp(self.idx + 1) + self.idx = self.clamp(self.idx + 1) elif event == '<SPACE>': - self.toggle(self.idx) + self.toggle() elif event in {'p', 'P'}: self.preview() elif event in {'<ESC>', '<Ctrl-g>'}: @@ -106,8 +110,9 @@ class Prompt: def render(self): if self.list: - output = fsarray([render_entry(x) for x in self.entries] + [' [ OK ] '], - self.window.width) + output = fsarray( + [render_entry(x, self.window.width, i == self.idx) for i, x in enumerate(self.entries)] + + [' [ OK ] '], width=self.window.width) self.window.render_to_terminal(output) return cur = self.entries[self.idx] |