Skip to content

Commit

Permalink
Merge pull request #24 from prezesp/feature/fix-reading-buckets
Browse files Browse the repository at this point in the history
Fix reading the buckets after removing the main bucket from scoop iself
  • Loading branch information
prezesp authored Jun 13, 2019
2 parents b3579a5 + 5a10b0e commit efaaa52
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
14 changes: 11 additions & 3 deletions explorer/explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,17 @@ def parse_json(self, file): # pylint: disable=R0201
def get_apps(self, directory, pattern=None):
""" Get all app from bucket directory. """
apps = []
for file in os.listdir(directory):
if file.endswith(".json") and ((pattern and pattern in file) or not pattern):
apps.append(self.parse_json(os.path.join(directory, file)))

def browse(dir, pattern, parsefunction):
for file in os.listdir(dir):
if file.endswith(".json") and ((pattern and pattern in file) or not pattern):
apps.append(parsefunction(os.path.join(dir, file)))

browse(directory, pattern, self.parse_json)

bucket_dir = os.path.join(directory, 'bucket')
if os.path.exists(bucket_dir):
browse(bucket_dir, pattern, self.parse_json)

return apps

Expand Down
2 changes: 2 additions & 0 deletions scoop-viewer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
""" App to browse scoop packages. """

import argparse
import logging
import platform
import sys
import webbrowser
Expand Down Expand Up @@ -94,6 +95,7 @@ def run():

if __name__ == '__main__':

logging.basicConfig(level='ERROR')
if platform.system() == "Darwin":
from darwin_http import hack
hack()
Expand Down
11 changes: 9 additions & 2 deletions webapp/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,18 @@ def index():

@app.route('/buckets/')
def buckets():
buckets = get_buckets(app.config['extra_buckets'])
buckets = get_buckets(app.config['bucket'], [app.config['extra_buckets']])
return Response(json.dumps(buckets), mimetype='application/json')

@app.route('/bucket/<name>/', methods=['GET'])
def get_bucket(name):
buckets = get_buckets(app.config['bucket'], [app.config['extra_buckets']])

if not any(name in b['name'] for b in buckets):
name = buckets[0]['name']

provider = get_provider(app.config)
# fix main bucket
bucket = app.config['bucket'] if name == MAIN_BUCKET else os.path.join(app.config['extra_buckets'], name)
apps = get_apps(provider, bucket, None)
return Response(json.dumps(apps), mimetype='application/json')
Expand All @@ -94,7 +100,8 @@ def search(query):
#query = request.args.get('q', default='*', type=str)

apps = []
for bucket in get_buckets(app.config['extra_buckets']):
buckets = get_buckets(app.config['bucket'], [app.config['extra_buckets']])
for bucket in buckets:
bucket_dir = app.config['bucket'] if bucket['name'] == MAIN_BUCKET else os.path.join(app.config['extra_buckets'], bucket['name'])
apps.extend(get_apps(provider, bucket_dir, query))

Expand Down
14 changes: 10 additions & 4 deletions webapp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,18 @@ def get_apps(provider, bucket_path, query):

return apps

def get_buckets(path):
def get_buckets(builtin_bucket, paths):
""" Get all buckets. """
ex = Explorer()
buckets = [{ 'name': MAIN_BUCKET }]
for bucket in ex.get_buckets(expandvars(path)):
buckets.append({ 'name': bucket })
buckets = []

# scoop master bucket for legacy versions
if os.path.exists(expandvars(builtin_bucket)):
buckets.append({ 'name': MAIN_BUCKET})

for path in paths:
for bucket in ex.get_buckets(expandvars(path)):
buckets.append({ 'name': bucket })

return buckets

Expand Down

0 comments on commit efaaa52

Please sign in to comment.