[copr] search: api: find for fulltext in search (fe82e30)
by Igor Gnatenko
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : search
>---------------------------------------------------------------
commit fe82e30189bdc976296258a7cdc539a0e4fe7c14
Author: Igor Gnatenko <i.gnatenko.brain(a)gmail.com>
Date: Sat Mar 1 14:50:44 2014 +0400
api: find for fulltext in search
Signed-off-by: Igor Gnatenko <i.gnatenko.brain(a)gmail.com>
>---------------------------------------------------------------
coprs_frontend/coprs/logic/coprs_logic.py | 4 ----
coprs_frontend/coprs/templates/api.html | 22 ++++++++++++++++------
coprs_frontend/coprs/views/api_ns/api_general.py | 12 +++++++-----
3 files changed, 23 insertions(+), 15 deletions(-)
diff --git a/coprs_frontend/coprs/logic/coprs_logic.py b/coprs_frontend/coprs/logic/coprs_logic.py
index 19cb5b9..7cab264 100644
--- a/coprs_frontend/coprs/logic/coprs_logic.py
+++ b/coprs_frontend/coprs/logic/coprs_logic.py
@@ -47,7 +47,6 @@ class CoprsLogic(object):
def get_multiple(cls, user, **kwargs):
user_relation = kwargs.get("user_relation", None)
username = kwargs.get("username", None)
- coprname = kwargs.get("coprname", None)
with_mock_chroots = kwargs.get("with_mock_chroots", None)
with_builds = kwargs.get("with_builds", None)
incl_deleted = kwargs.get("incl_deleted", None)
@@ -64,9 +63,6 @@ class CoprsLogic(object):
if isinstance(ids, list): # can be an empty list
query = query.filter(models.Copr.id.in_(ids))
- if coprname:
- query = query.filter(models.Copr.name == coprname)
-
if user_relation == "owned":
query = query.filter(
models.User.openid_name == models.User.openidize_name(username))
diff --git a/coprs_frontend/coprs/templates/api.html b/coprs_frontend/coprs/templates/api.html
index 1e9ee9a..1df4fb3 100644
--- a/coprs_frontend/coprs/templates/api.html
+++ b/coprs_frontend/coprs/templates/api.html
@@ -342,15 +342,17 @@ copr_url = http://copr.fedoraproject.org
<h4>URL parameters:</h4>
<ul>
- <li><b>project</b> – The name of the project whose you'd like
+ <li><b>project</b> – The text of the project whose you'd like
to find</li>
</ul>
<h4>Result:</h4>
<ul>
- <li><b>"users"</b> – List of users in given format:
+ <li><b>"repos"</b> – List of repos in given format:
<ul>
- <li><b>"name"</b> – Name of the user</li>
+ <li><b>"username"</b> – Name of the user</li>
+ <li><b>"coprname"</b> – Name of the copr</li>
+ <li><b>"description"</b> – Description of the copr</li>
</ul>
</ul>
@@ -361,12 +363,20 @@ copr_url = http://copr.fedoraproject.org
<pre>
{
"output": "ok",
- "users": [
+ "repos": [
{
- "name": "ignatenkobrain"
+ "username": "ignatenkobrain",
+ "coprname": "test",
+ "description": "Tests"
+ },
+ "username": "ignatenkobrain",
+ "coprname": "tests",
+ "description": ""
},
{
- "name": "msuchy"
+ "username": "msuchy",
+ "coprname": "tests",
+ "description": "Copr testing repository, just for test various builds."
}
]
}
diff --git a/coprs_frontend/coprs/views/api_ns/api_general.py b/coprs_frontend/coprs/views/api_ns/api_general.py
index 527f49b..cc41fdd 100644
--- a/coprs_frontend/coprs/views/api_ns/api_general.py
+++ b/coprs_frontend/coprs/views/api_ns/api_general.py
@@ -344,23 +344,25 @@ def copr_chroot_details(username, coprname, chrootname):
@api_ns.route("/coprs/search/")
@api_ns.route("/coprs/search/<project>/")
def api_coprs_search_by_project(project=None):
- """ Return the list of coprs found in search by the given project.
+ """ Return the list of coprs found in search by the given text.
project is taken either from GET params or from the URL itself
(in this order).
- :arg project: the project one would like find for coprs.
+ :arg project: the text one would like find for coprs.
"""
project = flask.request.args.get("project", None) or project
httpcode = 200
if project:
- query = coprs_logic.CoprsLogic.get_multiple(
- flask.g.user, coprname=project)
+ query = coprs_logic.CoprsLogic.get_multiple_fulltext(
+ flask.g.user, project)
repos = query.all()
output = {"output": "ok", "users": []}
for repo in repos:
- output["users"].append({"name": repo.owner})
+ output["repos"].append({"username": repo.owner,
+ "coprname"; repo.name,
+ "description": repo.description})
else:
output = {"output": "notok", "error": "Invalid request"}
httpcode = 500
10 years, 2 months
[copr] search: api: implement search (ba18d6e)
by Igor Gnatenko
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : search
>---------------------------------------------------------------
commit ba18d6ec336553df523c53f3aa733666d297801d
Author: Igor Gnatenko <i.gnatenko.brain(a)gmail.com>
Date: Sun Feb 16 17:38:59 2014 +0400
api: implement search
Reference: https://bugzilla.redhat.com/show_bug.cgi?id=1064118
Signed-off-by: Igor Gnatenko <i.gnatenko.brain(a)gmail.com>
>---------------------------------------------------------------
coprs_frontend/coprs/logic/coprs_logic.py | 4 ++
coprs_frontend/coprs/templates/api.html | 39 ++++++++++++++++++++++
coprs_frontend/coprs/views/api_ns/api_general.py | 28 +++++++++++++++
3 files changed, 71 insertions(+), 0 deletions(-)
diff --git a/coprs_frontend/coprs/logic/coprs_logic.py b/coprs_frontend/coprs/logic/coprs_logic.py
index 7cab264..19cb5b9 100644
--- a/coprs_frontend/coprs/logic/coprs_logic.py
+++ b/coprs_frontend/coprs/logic/coprs_logic.py
@@ -47,6 +47,7 @@ class CoprsLogic(object):
def get_multiple(cls, user, **kwargs):
user_relation = kwargs.get("user_relation", None)
username = kwargs.get("username", None)
+ coprname = kwargs.get("coprname", None)
with_mock_chroots = kwargs.get("with_mock_chroots", None)
with_builds = kwargs.get("with_builds", None)
incl_deleted = kwargs.get("incl_deleted", None)
@@ -63,6 +64,9 @@ class CoprsLogic(object):
if isinstance(ids, list): # can be an empty list
query = query.filter(models.Copr.id.in_(ids))
+ if coprname:
+ query = query.filter(models.Copr.name == coprname)
+
if user_relation == "owned":
query = query.filter(
models.User.openid_name == models.User.openidize_name(username))
diff --git a/coprs_frontend/coprs/templates/api.html b/coprs_frontend/coprs/templates/api.html
index e835d0f..1e9ee9a 100644
--- a/coprs_frontend/coprs/templates/api.html
+++ b/coprs_frontend/coprs/templates/api.html
@@ -333,5 +333,44 @@ copr_url = http://copr.fedoraproject.org
}
</pre>
+ <h3>Search for project</h3>
+
+ <h4>URL:</h4>
+ <pre style="font-size:120%">/api/coprs/search/<project>/</pre>
+ <div>or</div>
+ <pre style="font-size:120%">/api/coprs/?search="<project>"</pre>
+
+ <h4>URL parameters:</h4>
+ <ul>
+ <li><b>project</b> – The name of the project whose you'd like
+ to find</li>
+ </ul>
+
+ <h4>Result:</h4>
+ <ul>
+ <li><b>"users"</b> – List of users in given format:
+ <ul>
+ <li><b>"name"</b> – Name of the user</li>
+ </ul>
+ </ul>
+
+ <h4>Example call URL</h4>
+ <pre style="font-size:120%">https://copr.fedoraproject.org/api/coprs/search/tests/</pre>
+
+ <h4>Example results</h4>
+ <pre>
+ {
+ "output": "ok",
+ "users": [
+ {
+ "name": "ignatenkobrain"
+ },
+ {
+ "name": "msuchy"
+ }
+ ]
+ }
+ </pre>
+
</div>
{% endblock %}
diff --git a/coprs_frontend/coprs/views/api_ns/api_general.py b/coprs_frontend/coprs/views/api_ns/api_general.py
index 0a673d2..527f49b 100644
--- a/coprs_frontend/coprs/views/api_ns/api_general.py
+++ b/coprs_frontend/coprs/views/api_ns/api_general.py
@@ -340,3 +340,31 @@ def copr_chroot_details(username, coprname, chrootname):
jsonout = flask.jsonify(output)
jsonout.status_code = httpcode
return jsonout
+
+(a)api_ns.route("/coprs/search/")
+(a)api_ns.route("/coprs/search/<project>/")
+def api_coprs_search_by_project(project=None):
+ """ Return the list of coprs found in search by the given project.
+ project is taken either from GET params or from the URL itself
+ (in this order).
+
+ :arg project: the project one would like find for coprs.
+
+ """
+ project = flask.request.args.get("project", None) or project
+ httpcode = 200
+ if project:
+ query = coprs_logic.CoprsLogic.get_multiple(
+ flask.g.user, coprname=project)
+
+ repos = query.all()
+ output = {"output": "ok", "users": []}
+ for repo in repos:
+ output["users"].append({"name": repo.owner})
+ else:
+ output = {"output": "notok", "error": "Invalid request"}
+ httpcode = 500
+
+ jsonout = flask.jsonify(output)
+ jsonout.status_code = httpcode
+ return jsonout
10 years, 2 months
[copr] search: dnf-plugin: search for fulltext (ae10dd4)
by Igor Gnatenko
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : search
>---------------------------------------------------------------
commit ae10dd4add58065e2af8a876940b28f66af7c769
Author: Igor Gnatenko <i.gnatenko.brain(a)gmail.com>
Date: Sat Mar 1 14:54:51 2014 +0400
dnf-plugin: search for fulltext
Signed-off-by: Igor Gnatenko <i.gnatenko.brain(a)gmail.com>
>---------------------------------------------------------------
dnf-plugin/copr_hook.py | 19 +++++++++++++++++--
1 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/dnf-plugin/copr_hook.py b/dnf-plugin/copr_hook.py
index cc546c8..c18e550 100644
--- a/dnf-plugin/copr_hook.py
+++ b/dnf-plugin/copr_hook.py
@@ -121,7 +121,7 @@ search project""")
print "{}".format(desc)
i += 1
elif subcommand == "search":
- #http://copr.fedoraproject.org/api/coprs/search/ocltoys/
+ #http://copr.fedoraproject.org/api/coprs/search/tests/
api_path = "/api/coprs/search/{}/".format(project_name)
opener = urllib.FanceURLopener({})
@@ -131,8 +131,23 @@ search project""")
except ValueError:
raise dnf.Exceptions.Error(_("Can't parse search for '{}'.").format(project_name)), None, sys.exc_info()[2]
i = 0
+ lmax = 0
while i < len(json_parse["repos"]):
- print "{0}/{1}".format(json_parse["users"][i]["name"], project_name)
+ lnow = len("{0}/{1}: ".format(json_parse["repos"][i]["username"], json_parse["repos"][i]["coprname"]))
+ if lnow > lmax:
+ lmax = lnow
+ i += 1
+ i = 0
+ while i < len(json_parse["repos"]):
+ repo = "{0}/{1}: ".format(json_parse["repos"][i]["username"], json_parse["repos"][i]["coprname"])
+ tmp_str = json_parse["repos"][i]["description"]
+ tmp_list = [y for y in (x.strip() for x in tmp_str.splitlines()) if y]
+ if tmp_list == []:
+ tmp_list = [_("No description given")]
+ tmp_list = [re.sub(r"^", " " * lmax, w) for w in tmp_list if w]
+ print "{}".format(repo)
+ for desc in tmp_list:
+ print "{}".format(desc)
i += 1
else:
raise dnf.exceptions.Error(_('Unknown subcommand {}.').format(subcommand))
10 years, 2 months
[copr] search: dnf-plugin: print description (219d350)
by Igor Gnatenko
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : search
>---------------------------------------------------------------
commit 219d350a7d4581b26dc3791e2eaaef6a612a207a
Author: Igor Gnatenko <i.gnatenko.brain(a)gmail.com>
Date: Sat Mar 1 14:32:13 2014 +0400
dnf-plugin: print description
Signed-off-by: Igor Gnatenko <i.gnatenko.brain(a)gmail.com>
>---------------------------------------------------------------
dnf-plugin/copr_hook.py | 18 +++++++++++++++++-
1 files changed, 17 insertions(+), 1 deletions(-)
diff --git a/dnf-plugin/copr_hook.py b/dnf-plugin/copr_hook.py
index 338d879..cc546c8 100644
--- a/dnf-plugin/copr_hook.py
+++ b/dnf-plugin/copr_hook.py
@@ -7,6 +7,7 @@ from dnf.yum.i18n import _
from urlgrabber import grabber
import urllib
import json
+import re
yes = set([_('yes'), _('y')])
no = set([_('no'), _('n'), ''])
@@ -101,8 +102,23 @@ search project""")
except ValueError:
raise dnf.exceptions.Error(_("Can't parse repositories for username '{}'.").format(project_name)), None, sys.exc_info()[2]
i = 0
+ lmax = 0
while i < len(json_parse["repos"]):
- print "{0}/{1}".format(project_name, json_parse["repos"][i]["name"])
+ lnow = len("{0}/{1}: ".format(project_name, json_parse["repos"][i]["name"]))
+ if lnow > lmax:
+ lmax = lnow
+ i += 1
+ i = 0
+ while i < len(json_parse["repos"]):
+ repo = "{0}/{1}: ".format(project_name, json_parse["repos"][i]["name"])
+ tmp_str = json_parse["repos"][i]["description"]
+ tmp_list = [y for y in (x.strip() for x in tmp_str.splitlines()) if y]
+ if tmp_list == []:
+ tmp_list = [_("No description given")]
+ tmp_list = [re.sub(r"^", " " * lmax, w) for w in tmp_list if w]
+ print "{}".format(repo)
+ for desc in tmp_list:
+ print "{}".format(desc)
i += 1
elif subcommand == "search":
#http://copr.fedoraproject.org/api/coprs/search/ocltoys/
10 years, 2 months
[copr] search: dnf-plugin: implement search (18afdcd)
by Igor Gnatenko
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : search
>---------------------------------------------------------------
commit 18afdcd8d123173a6e42f1e8fb9dfb364e54d7fe
Author: Igor Gnatenko <i.gnatenko.brain(a)gmail.com>
Date: Sun Feb 16 17:39:22 2014 +0400
dnf-plugin: implement search
Signed-off-by: Igor Gnatenko <i.gnatenko.brain(a)gmail.com>
>---------------------------------------------------------------
dnf-plugin/copr_hook.py | 18 +++++++++++++++++-
1 files changed, 17 insertions(+), 1 deletions(-)
diff --git a/dnf-plugin/copr_hook.py b/dnf-plugin/copr_hook.py
index eeddc8c..338d879 100644
--- a/dnf-plugin/copr_hook.py
+++ b/dnf-plugin/copr_hook.py
@@ -36,6 +36,7 @@ class CoprCommand(dnf.cli.Command):
copr enable ignatenkobrain/ocltoys
copr disable rhscl/perl516
copr list ignatenkobrain
+ copr search ocltoys
""")
@staticmethod
@@ -44,7 +45,8 @@ class CoprCommand(dnf.cli.Command):
return _("""
enable name/project [chroot]
disable name/project
-list name""")
+list name
+search project""")
def run(self, extcmds):
# FIXME this should do dnf itself (BZ#1062889)
@@ -102,6 +104,20 @@ list name""")
while i < len(json_parse["repos"]):
print "{0}/{1}".format(project_name, json_parse["repos"][i]["name"])
i += 1
+ elif subcommand == "search":
+ #http://copr.fedoraproject.org/api/coprs/search/ocltoys/
+ api_path = "/api/coprs/search/{}/".format(project_name)
+
+ opener = urllib.FanceURLopener({})
+ res = opener.open(base_url+api_path)
+ try:
+ json_parse = json.loads(res.read())
+ except ValueError:
+ raise dnf.Exceptions.Error(_("Can't parse search for '{}'.").format(project_name)), None, sys.exc_info()[2]
+ i = 0
+ while i < len(json_parse["repos"]):
+ print "{0}/{1}".format(json_parse["users"][i]["name"], project_name)
+ i += 1
else:
raise dnf.exceptions.Error(_('Unknown subcommand {}.').format(subcommand))
10 years, 2 months
[copr] search: dnf-plugin: search for fulltext (8c2daab)
by Igor Gnatenko
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : search
>---------------------------------------------------------------
commit 8c2daabaefc492001defd283531956229540319a
Author: Igor Gnatenko <i.gnatenko.brain(a)gmail.com>
Date: Sat Mar 1 14:54:51 2014 +0400
dnf-plugin: search for fulltext
Signed-off-by: Igor Gnatenko <i.gnatenko.brain(a)gmail.com>
>---------------------------------------------------------------
dnf-plugin/copr_hook.py | 19 +++++++++++++++++--
1 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/dnf-plugin/copr_hook.py b/dnf-plugin/copr_hook.py
index cc546c8..c18e550 100644
--- a/dnf-plugin/copr_hook.py
+++ b/dnf-plugin/copr_hook.py
@@ -121,7 +121,7 @@ search project""")
print "{}".format(desc)
i += 1
elif subcommand == "search":
- #http://copr.fedoraproject.org/api/coprs/search/ocltoys/
+ #http://copr.fedoraproject.org/api/coprs/search/tests/
api_path = "/api/coprs/search/{}/".format(project_name)
opener = urllib.FanceURLopener({})
@@ -131,8 +131,23 @@ search project""")
except ValueError:
raise dnf.Exceptions.Error(_("Can't parse search for '{}'.").format(project_name)), None, sys.exc_info()[2]
i = 0
+ lmax = 0
while i < len(json_parse["repos"]):
- print "{0}/{1}".format(json_parse["users"][i]["name"], project_name)
+ lnow = len("{0}/{1}: ".format(json_parse["repos"][i]["username"], json_parse["repos"][i]["coprname"]))
+ if lnow > lmax:
+ lmax = lnow
+ i += 1
+ i = 0
+ while i < len(json_parse["repos"]):
+ repo = "{0}/{1}: ".format(json_parse["repos"][i]["username"], json_parse["repos"][i]["coprname"])
+ tmp_str = json_parse["repos"][i]["description"]
+ tmp_list = [y for y in (x.strip() for x in tmp_str.splitlines()) if y]
+ if tmp_list == []:
+ tmp_list = [_("No description given")]
+ tmp_list = [re.sub(r"^", " " * lmax, w) for w in tmp_list if w]
+ print "{}".format(repo)
+ for desc in tmp_list:
+ print "{}".format(desc)
i += 1
else:
raise dnf.exceptions.Error(_('Unknown subcommand {}.').format(subcommand))
10 years, 2 months
[copr] search: api: find for fulltext in search (e888efc)
by Igor Gnatenko
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : search
>---------------------------------------------------------------
commit e888efc8a4284ec1b43d406158adb14ce348bfa9
Author: Igor Gnatenko <i.gnatenko.brain(a)gmail.com>
Date: Sat Mar 1 14:50:44 2014 +0400
api: find for fulltext in search
Signed-off-by: Igor Gnatenko <i.gnatenko.brain(a)gmail.com>
>---------------------------------------------------------------
coprs_frontend/coprs/logic/coprs_logic.py | 4 ----
coprs_frontend/coprs/templates/api.html | 22 ++++++++++++++++------
coprs_frontend/coprs/views/api_ns/api_general.py | 12 +++++++-----
3 files changed, 23 insertions(+), 15 deletions(-)
diff --git a/coprs_frontend/coprs/logic/coprs_logic.py b/coprs_frontend/coprs/logic/coprs_logic.py
index 19cb5b9..7cab264 100644
--- a/coprs_frontend/coprs/logic/coprs_logic.py
+++ b/coprs_frontend/coprs/logic/coprs_logic.py
@@ -47,7 +47,6 @@ class CoprsLogic(object):
def get_multiple(cls, user, **kwargs):
user_relation = kwargs.get("user_relation", None)
username = kwargs.get("username", None)
- coprname = kwargs.get("coprname", None)
with_mock_chroots = kwargs.get("with_mock_chroots", None)
with_builds = kwargs.get("with_builds", None)
incl_deleted = kwargs.get("incl_deleted", None)
@@ -64,9 +63,6 @@ class CoprsLogic(object):
if isinstance(ids, list): # can be an empty list
query = query.filter(models.Copr.id.in_(ids))
- if coprname:
- query = query.filter(models.Copr.name == coprname)
-
if user_relation == "owned":
query = query.filter(
models.User.openid_name == models.User.openidize_name(username))
diff --git a/coprs_frontend/coprs/templates/api.html b/coprs_frontend/coprs/templates/api.html
index 1e9ee9a..1df4fb3 100644
--- a/coprs_frontend/coprs/templates/api.html
+++ b/coprs_frontend/coprs/templates/api.html
@@ -342,15 +342,17 @@ copr_url = http://copr.fedoraproject.org
<h4>URL parameters:</h4>
<ul>
- <li><b>project</b> – The name of the project whose you'd like
+ <li><b>project</b> – The text of the project whose you'd like
to find</li>
</ul>
<h4>Result:</h4>
<ul>
- <li><b>"users"</b> – List of users in given format:
+ <li><b>"repos"</b> – List of repos in given format:
<ul>
- <li><b>"name"</b> – Name of the user</li>
+ <li><b>"username"</b> – Name of the user</li>
+ <li><b>"coprname"</b> – Name of the copr</li>
+ <li><b>"description"</b> – Description of the copr</li>
</ul>
</ul>
@@ -361,12 +363,20 @@ copr_url = http://copr.fedoraproject.org
<pre>
{
"output": "ok",
- "users": [
+ "repos": [
{
- "name": "ignatenkobrain"
+ "username": "ignatenkobrain",
+ "coprname": "test",
+ "description": "Tests"
+ },
+ "username": "ignatenkobrain",
+ "coprname": "tests",
+ "description": ""
},
{
- "name": "msuchy"
+ "username": "msuchy",
+ "coprname": "tests",
+ "description": "Copr testing repository, just for test various builds."
}
]
}
diff --git a/coprs_frontend/coprs/views/api_ns/api_general.py b/coprs_frontend/coprs/views/api_ns/api_general.py
index 527f49b..cc41fdd 100644
--- a/coprs_frontend/coprs/views/api_ns/api_general.py
+++ b/coprs_frontend/coprs/views/api_ns/api_general.py
@@ -344,23 +344,25 @@ def copr_chroot_details(username, coprname, chrootname):
@api_ns.route("/coprs/search/")
@api_ns.route("/coprs/search/<project>/")
def api_coprs_search_by_project(project=None):
- """ Return the list of coprs found in search by the given project.
+ """ Return the list of coprs found in search by the given text.
project is taken either from GET params or from the URL itself
(in this order).
- :arg project: the project one would like find for coprs.
+ :arg project: the text one would like find for coprs.
"""
project = flask.request.args.get("project", None) or project
httpcode = 200
if project:
- query = coprs_logic.CoprsLogic.get_multiple(
- flask.g.user, coprname=project)
+ query = coprs_logic.CoprsLogic.get_multiple_fulltext(
+ flask.g.user, project)
repos = query.all()
output = {"output": "ok", "users": []}
for repo in repos:
- output["users"].append({"name": repo.owner})
+ output["repos"].append({"username": repo.owner,
+ "coprname"; repo.name,
+ "description": repo.description})
else:
output = {"output": "notok", "error": "Invalid request"}
httpcode = 500
10 years, 2 months