Permalink
Browse files

'snap find' list/prefix support; simplify metadata

  • Loading branch information...
1 parent 7fbb93a commit 37020e913757f84d872d3483c5dc3184df494db3 @noise committed Jun 24, 2016
Showing with 82 additions and 44 deletions.
  1. +1 −1 .gitignore
  2. +21 −0 files/bar.meta
  3. BIN files/bar.snap
  4. +21 −0 files/baz.meta
  5. BIN files/baz.snap
  6. +19 −28 files/foobar25.meta
  7. +20 −15 store.py
View
@@ -91,5 +91,5 @@ ENV/
# snapcraft
stage/
prime/
-*.snap
+snapstore-example*
*.bz2
View
@@ -0,0 +1,21 @@
+{
+ "architecture": [
+ "amd64"
+ ],
+ "binary_filesize": null,
+ "channel": "stable",
+ "confinement": "strict",
+ "content": "application",
+ "description": "This is a bar snap",
+ "icon_url": null,
+ "last_updated": "2016-06-03T12:01:15.435821Z",
+ "origin": "testuser",
+ "package_name": "bar",
+ "prices": {},
+ "publisher": "TestUser",
+ "ratings_average": 0.0,
+ "revision": 1,
+ "snap_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxbar",
+ "summary": "This is a bar snap",
+ "version": "0.2"
+}
View
Binary file not shown.
View
@@ -0,0 +1,21 @@
+{
+ "architecture": [
+ "amd64"
+ ],
+ "binary_filesize": null,
+ "channel": "stable",
+ "confinement": "strict",
+ "content": "application",
+ "description": "This is a baz snap",
+ "icon_url": null,
+ "last_updated": "2016-06-03T12:01:15.435821Z",
+ "origin": "testuser",
+ "package_name": "baz",
+ "prices": {},
+ "publisher": "TestUser",
+ "ratings_average": 0.0,
+ "revision": 3,
+ "snap_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxbaz",
+ "summary": "This is a baz snap",
+ "version": "0.4"
+}
View
Binary file not shown.
View
@@ -1,30 +1,21 @@
{
- "_embedded": {
- "clickindex:package": [
- {
- "anon_download_url": "http://localhost:5000/anon/download-snap/foobar25.snap",
- "architecture": [
- "amd64"
- ],
- "binary_filesize": null,
- "channel": "stable",
- "confinement": "strict",
- "content": "application",
- "description": "This is a test snap",
- "download_sha512": "7c229e954b1e136d02b33ad14841164b85d19e5b6b2efc9bed27b01bec3bba82e8580cbce6fa4feac1680ce7ff6b1023b3633d8dec7910e1d34203fa48e1bc72",
- "download_url": "http://localhost:5000/download-snap/foobar25.snap",
- "icon_url": null,
- "last_updated": "2016-06-03T12:01:15.435821Z",
- "origin": "testuser",
- "package_name": "foobar25",
- "prices": {},
- "publisher": "TestUser",
- "ratings_average": 0.0,
- "revision": 1,
- "snap_id": "W2pGsnY3YWr5L8TE8s5l1i6XC6sC6xQB",
- "summary": "This is a test snap",
- "version": "2.5"
- }
- ]
- }
+ "architecture": [
+ "amd64"
+ ],
+ "binary_filesize": null,
+ "channel": "stable",
+ "confinement": "strict",
+ "content": "application",
+ "description": "This is a test snap",
+ "icon_url": null,
+ "last_updated": "2016-06-03T12:01:15.435821Z",
+ "origin": "testuser",
+ "package_name": "foobar25",
+ "prices": {},
+ "publisher": "TestUser",
+ "ratings_average": 0.0,
+ "revision": 1,
+ "snap_id": "xxxxxxxxxxxxxxxxxxxxxxxxfoobar25",
+ "summary": "This is a test snap",
+ "version": "2.5"
}
View
@@ -15,27 +15,32 @@ def hello():
return 'Hello snap store example!'
-@app.route('/api/v1/search')
-def search():
- ''' note in 2.0.9 snap install uses the search endpoint
- for package details as well as for snap find '''
- name = request.args.get('q')
- # hackity hack hack: find passes q=package_name:"foo"
- if 'package_name' in name:
- name = name.split(':')[1].replace('"', '')
-
+def read_meta(name):
try:
fname = safe_join(FILES, name + '.meta')
with open(fname, 'r') as meta:
# replace download URLs
- data = json.loads(meta.read())
- pkg = data['_embedded']['clickindex:package'][0]
- pkg['download_url'] = url_for('download', name=name + '.snap',
- _external=True)
+ pkg = json.loads(meta.read())
+ pkg['download_url'] = url_for('download', name=name + '.snap', _external=True)
pkg['anon_download_url'] = pkg['download_url']
- return Response(json.dumps(data), mimetype='application/hal+json')
+ return pkg
except Exception as e:
- return Response('{}', mimetype='application/hal+json')
+ return None
+
+
+@app.route('/api/v1/search')
+def search():
+ ''' note in 2.0.9 snap install uses the search endpoint
+ for package details as well as for snap find '''
+ q = request.args.get('q', '')
+ if 'package_name' in q:
+ names = [q.split(':')[1].replace('"', '')]
+ else:
+ names = [os.path.splitext(n)[0] for n in os.listdir(FILES)
+ if n.startswith(q) and n.endswith('.meta')]
+ data = {'_embedded': {'clickindex:package': []}}
+ data['_embedded']['clickindex:package'] = [m for m in [read_meta(n) for n in names] if m]
+ return Response(json.dumps(data), mimetype='application/hal+json')
@app.route('/download/<name>')

0 comments on commit 37020e9

Please sign in to comment.