Skip to content

Allow Search with Pip #80

@psaavedra

Description

@psaavedra

This patch hacks the code in order to allow pip search PKG. For example:

pip search  --index http://pypi.intenet.com:8080/search/ MyDjango

I wonder if you are interested on this and if this patch is wellcome for your side.

--- /root/_app.py   2015-03-12 11:16:23.000000000 +0000
+++ /usr/local/lib/python2.7/dist-packages/pypiserver/_app.py   2015-03-12 12:26:29.000000000 +0000
@@ -6,6 +6,7 @@
 import mimetypes
 import logging
 import pkg_resources
+import xml.dom.minidom
 
 try:
     from io import BytesIO
@@ -24,6 +25,48 @@
 log = logging.getLogger('pypiserver.http')
 packages = None
 
+XMLRPC_RESPONSE_SKELETON='''
+
+
+
+
+%(objects)s
+
+
+
+'''
+
+def from_obj_to_xmlrpc(obj_):
+    res = ""
+    if isinstance(obj_,int):
+        res += "%s" % obj_
+        return res
+    elif isinstance(obj_,str):
+        res += "%s" % obj_
+        return res
+    elif isinstance(obj_,dict):
+        res += ""
+        for k,v in obj_.iteritems():
+            member = {}
+            member["name"]=k
+            member["value"]=from_obj_to_xmlrpc(v)
+            res_1 = ""
+            res_1 += "%(name)s"
+            res_1 += "%(value)s"
+            res_1 += ""
+            res += res_1 % member
+        res += ""
+        return res
+    elif isinstance(obj_,list):
+        res += ""
+        for i in obj_:
+            res += "%s" % from_obj_to_xmlrpc(i)
+        res += ""
+        return res
+    else:
+       raise Exception("No valid object")
+
+
 
 class Configuration(object):
     def __init__(self):
@@ -267,8 +310,31 @@
     return redirect(request.fullpath + "/")
 
 
[email protected]("/simple/")
[email protected]('/search')
[email protected]('/search/')
 @auth("list")
+def search():
+    value = ""
+    try:
+        parser = xml.dom.minidom.parse(request.body)
+        member = parser.getElementsByTagName("member")[0]
+        value  = parser.getElementsByTagName("string")[0].childNodes[0].wholeText.strip()
+    except Exception, e:
+        value = ""
+
+    response = []
+    ordering = 0
+    for p in packages():
+        if p.pkgname.count(value) > 0:
+            d = {'_pypi_ordering': ordering, 'version': p.version,
+                 'name': p.pkgname, 'summary': p.fn}
+            response.append(d)
+        ordering += 1
+    res = XMLRPC_RESPONSE_SKELETON \
+        % {"objects":from_obj_to_xmlrpc(response)}
+    return res
+
[email protected]("/simple/")
 def simpleindex():
     links = sorted(get_prefixes(packages()))
     tmpl = """\

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions