aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pomu/cli.py8
-rw-r--r--pomu/patch/patch.py16
-rw-r--r--pomu/repo/repo.py2
-rw-r--r--pomu/source/bugz.py44
-rw-r--r--pomu/source/url.py13
-rw-r--r--pomu/util/iquery.py16
-rw-r--r--pomu/util/misc.py2
7 files changed, 30 insertions, 71 deletions
diff --git a/pomu/cli.py b/pomu/cli.py
index 14e0b95..bf163b9 100644
--- a/pomu/cli.py
+++ b/pomu/cli.py
@@ -3,6 +3,7 @@ import click
from os import path
+from pomu.patch.patch import process_changes
from pomu.repo.init import init_plain_repo, init_portage_repo
from pomu.repo.repo import portage_repo_path, portage_repos, pomu_active_repo
from pomu.source import dispatcher
@@ -70,12 +71,11 @@ def status():
else:
print('pomu is initialized at', repo.root)
-@main.command()
+@main.command(name='import')
@click.argument('package', required=True)
-@click.option('--patch', nargs=-1)
- #help='Patches for the package')
+@click.option('--patch', nargs = -1)
@needs_repo
-def import(package, patch):
+def list(package, patch):
"""Imports a package"""
pkg = dispatcher.get_package(package).expect()
pkg.patch(patch)
diff --git a/pomu/patch/patch.py b/pomu/patch/patch.py
index 4a8357c..7021d63 100644
--- a/pomu/patch/patch.py
+++ b/pomu/patch/patch.py
@@ -1,20 +1,12 @@
"""
"""
-from os import path, walk, makedirs, remove
-from shutil import copy2
+from os import path
from time import time
-import subprocess
-
from git.repo import Repo
-from patch import PatchSet
-from pomu.repo.repo import Repository
-from pomu.util.fs import strip_prefix
-from pomu.util.misc import list_add
from pomu.util.pkg import cpv_split
-from pomu.util.result import Result
def process_changes(_repo):
# we only tackle repository changes so far
@@ -32,7 +24,7 @@ def process_changes(_repo):
for diff in chans: # changes in tracked files
pkpref = path.dirname(diff.a_path).split('/')[0:1].join('/')
if pkpref in res:
- res[pkpref].append(header(diff.a_path, diff.b_path).join('\n') +
+ res[pkpref].append(diff_header(diff.a_path, diff.b_path).join('\n') +
diff.diff.decode('utf-8'))
res = {x: res[x] for x in res if res[x]}
for _pkg, diffs in res.items(): # add each change as its own patch
@@ -59,7 +51,6 @@ def process_changes(_repo):
orig = repo.odb.stream(diff.a_blob.binsha).read().decode('utf-8')
pkg = _repo.get_package(cat, name)
orig_lines = [path.join(pkg.pkgdir, x.strip()) for x in orig.split('\n') if x.strip() != '']
- ps = PatchSet()
pkg.patches = orig_lines
pkg.apply_patches(revert=True)
pkg = _repo.get_package(cat, name)
@@ -92,7 +83,7 @@ def process_changes(_repo):
def new_file_patch(repo, newf):
with open(path.join(repo.root, newf), 'r') as f:
lines = ['+' + x.strip('\n') for x in f.readlines()]
- head = header('/dev/null', newf, len(lines))
+ head = diff_header('/dev/null', newf, len(lines))
return (head + lines).join('\n') + '\n'
def diff_header(a_path, b_path, lines=None):
@@ -100,4 +91,3 @@ def diff_header(a_path, b_path, lines=None):
if lines:
header.append('@@ -0,0 +1,' + lines + ' @@')
return header
- filename = path.join(self.category, self.name, '{}-{}.format')
diff --git a/pomu/repo/repo.py b/pomu/repo/repo.py
index a60e5b2..4317e47 100644
--- a/pomu/repo/repo.py
+++ b/pomu/repo/repo.py
@@ -35,7 +35,7 @@ class Repository():
def merge(self, mergeable):
"""Merges a package or a patchset into the repository"""
if isinstance(mergeable, Package):
- return merge_pkg(mergeable)
+ return self.merge_pkg(mergeable)
elif isinstance(mergeable, PatchList):
pkg = self.get_package(mergeable.name, mergeable.category,
mergeable.slot).unwrap()
diff --git a/pomu/source/bugz.py b/pomu/source/bugz.py
index 84adfd7..8dc92ac 100644
--- a/pomu/source/bugz.py
+++ b/pomu/source/bugz.py
@@ -6,13 +6,11 @@ import xmlrpc.client
from os import path
from urllib.parse import urlparse
-from pbraw import grab
-
from pomu.package import Package
from pomu.source import dispatcher
-from pomu.util.misc import extract_urls, parse_range
-from pomu.util.pkg import cpv_split, ver_str
-from pomu.util.query import query, QueryContext
+from pomu.util.iquery import Prompt
+from pomu.util.misc import extract_urls
+from pomu.util.query import query
from pomu.util.result import Result
class BzEbuild():
@@ -62,43 +60,19 @@ class BugzillaSource():
comments = proxy.comments(payload)['bugs'][str(uri)]['comments']
comment_links = []
for comment in comments:
- comment_links.extend(extract_urls(text))
+ comment_links.extend(extract_urls(comment['text']))
items = attachments + comment_links
if not items:
return Result.Err()
- lines = ['Please select required items (ranges are accepted)']
- for idx, item in enumerate(items):
- if isinstance(item, str):
- lines.append('{} - {}'.format(idx, item))
- else:
- lines.append('{} - Attachment: {}'.format(idx, item['file_name']))
- lines.append('>>> ')
- rng = query('items', '\n'.join(lines), 1)
- idxs = parse_range(rng, len(items))
- if not idxs:
- return Result.Err()
- filtered = [x for idx, x in enumerate(items) if idx + 1 in idxs]
- files = []
- for idx, item in enumerate(idxs):
- if isinstance(item, str):
- files.extend([(x[0], x[1].encode('utf-8')) for x in grab(item)])
- else:
- files.append((item['file_name'], item['data']))
+ p = Prompt(items)
+ files = p.run()
if not files:
return Result.Err()
category = query('category', 'Please enter package category').expect()
- name = query('name', 'Please enter package name')
+ name = query('name', 'Please enter package name').expect()
ver = query('version', 'Please specify package version for {}'.format(name)).expect()
- # TODO: ???
- fmap = {}
- for fn, data in files:
- with QueryContext(path=None):
- fpath = query('path', 'Please enter path for {} file'.format(fn), path.join(category, name, fn))
- fmap[fpath] = data
-
-
-
- return Result.Ok(BzEbuild(uri, category, name, ver, uri))
+ fmap = {path.join(category, name, x[2]): x[1] for x in items}
+ return Result.Ok(BzEbuild(uri, category, name, ver, fmap))
@dispatcher.handler(priority=2)
def parse_link(uri):
diff --git a/pomu/source/url.py b/pomu/source/url.py
index 0f43f01..33f51fb 100644
--- a/pomu/source/url.py
+++ b/pomu/source/url.py
@@ -2,15 +2,13 @@
A package source module to import packages from URLs
"""
-from os import path, close
-from tempfile import mkstemp
+from os import path
from pbraw import grab
from pomu.package import Package
from pomu.source import dispatcher
from pomu.source.base import PackageBase, BaseSource
-from pomu.util.pkg import cpv_split, ver_str
from pomu.util.query import query
from pomu.util.result import Result
@@ -26,15 +24,12 @@ class URLEbuild(PackageBase):
self.contents = contents
def fetch(self):
- fd, tfile = tempfile.mkstemp()
- os.close(fd)
if self.contents:
if isinstance(self.contents, str):
self.content = self.content.encode('utf-8')
else:
fs = grab(self.url)
self.content = fs[0][1].encode('utf-8')
- f.write(fs[0][1])
return Package(self.name, '/', self, self.category, self.version,
filemap = {
path.join(
@@ -70,7 +65,7 @@ class URLGrabberSource(BaseSource):
category, _, name = name.rpartition('/')
ver = query('version', 'Please specify package version for {}'.format(name)).expect()
if not category:
- category = query('category', 'Please enter category for {}'.format(name), parent).expect()
+ category = query('category', 'Please enter category for {}'.format(name)).expect()
files = grab(uri)
if not files:
return Result.Err()
@@ -80,8 +75,8 @@ class URLGrabberSource(BaseSource):
def parse_full(url):
if not url.startswith('url:'):
return Result.Err()
- return URLGrabberSource.parse_ebuild_path(uri[3:])
+ return URLGrabberSource.parse_ebuild_path(url[4:])
@classmethod
def from_meta_dir(cls, metadir):
- return LocalEbuild.from_data_dir(cls, metadir)
+ return URLEbuild.from_data_dir(cls, metadir)
diff --git a/pomu/util/iquery.py b/pomu/util/iquery.py
index 032838d..df76251 100644
--- a/pomu/util/iquery.py
+++ b/pomu/util/iquery.py
@@ -1,14 +1,12 @@
"""A module to interactively query"""
from pydoc import pager
-from curtsies import CursorAwareWindow, Input, FSArray, fsarray, fmtstr
+from curtsies import CursorAwareWindow, Input, fsarray, fmtstr
from curtsies.fmtfuncs import underline
from pbraw import grab
class Position:
- row = attr.ib()
- column = attr.ib()
def __init__(self, row=0, column=0):
self.row = row
self.column = column
@@ -21,7 +19,7 @@ def render_entry(entry, width, active=False):
char = '*' if entry[2] else ' '
w = 3 + fmtstr(entry[0]).width + 2
text = fmtstr(entry[3])
- return fsmtstr(
+ return fmtstr(
'[' + underline(char) if active else char + '] ' +
entry[0] + ' ' +
entry[3][:width - w - 2] + '..' if text.width < width - w else entry[3])
@@ -46,7 +44,7 @@ class Prompt:
CursorAwareWindow(in_stream=tty_in,
out_stream=tty_out,
hide_cursor=False,
- extra_bytes_callback=input_generator.unget_bytes) as window:
+ extra_bytes_callback=input_.unget_bytes) as window:
self.window = window
self.render()
for event in input_:
@@ -61,22 +59,22 @@ class Prompt:
def preview(self):
entry = self.entries[self.idx]
if entry[0] is not None:
- pydoc.pager(entry[1])
+ pager(entry[1])
else:
gr = grab(entry)
if not gr:
del self.entries[self.idx]
self.idx = clamp(self.idx - 1)
- pydoc.pager('Error: could not fetch '.format(entry))
+ 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]
- pydoc.pager(self.entries[self.idx][1])
+ pager(self.entries[self.idx][1])
def toggle(self):
if self.idx == len(self.entries):
return
self.entries[self.idx][3] = not self.entries[self.idx][3]
- def process_event(self):
+ def process_event(self, event):
if self.list:
if event == '<UP>':
self.idx = clamp(self.idx - 1)
diff --git a/pomu/util/misc.py b/pomu/util/misc.py
index 09d4232..de297af 100644
--- a/pomu/util/misc.py
+++ b/pomu/util/misc.py
@@ -1,6 +1,8 @@
"""Miscellaneous utility functions"""
import re
+from pomu.util.result import Result
+
def list_add(dst, src):
"""
Extends the target list with a scalar, or contents of the given list