Skip to content

Commit

Permalink
Merge pull request #304 from ymyzk/update-pypi
Browse files Browse the repository at this point in the history
Update PyPI plugin
  • Loading branch information
nate-parrott committed Jan 26, 2015
2 parents af20919 + 5ae41fd commit 3eff964
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
4 changes: 3 additions & 1 deletion PluginDirectories/1/pypi.bundle/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@
"description": "Search at PyPI - the Python Package Index",
"description_de": "Suche auf PyPI - dem Python Package Index",
"examples": ["pypi setuptools"],
"categories": ["Developer"]
"categories": ["Developer"],
"creator_name": "Yusuke Miyazaki",
"creator_url": "http://www.ymyzk.com"
}
14 changes: 14 additions & 0 deletions PluginDirectories/1/pypi.bundle/options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"options": [
{
"text": "Server:",
"type": "dropdown",
"key": "server",
"options": [
{"text": "https://pypi.python.org (CheeseShop)", "value": "cheeseshop"},
{"text": "https://warehouse.python.org (Warehouse)", "value": "warehouse"},
{"text": "http://localhost:3141 (devpi)", "value": "devpi"}
]
}
]
}
23 changes: 21 additions & 2 deletions PluginDirectories/1/pypi.bundle/plugin.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
import json
import urllib


def results(parsed, original_query):
if '~query' not in parsed:
return

query = parsed['~query']
url = 'https://pypi.python.org/pypi?:action=search&term={0}'.format(
urllib.quote_plus(query))

# Query is too short
if len(query) < 2:
return

# Load server settings
with open('preferences.json') as f:
settings = json.load(f)
server = settings.get('server', None)

# Set server URL
if server == 'warehouse':
url_template = 'https://warehouse.python.org/search/project/?q={0}'
elif server == 'devpi':
url_template = 'http://localhost:3141/+search?query={0}'
else:
url_template = 'https://pypi.python.org/pypi?:action=search&term={0}'

url = url_template.format(urllib.quote_plus(query))
html = """
<script>
setTimeout(function () {
Expand Down

0 comments on commit 3eff964

Please sign in to comment.