diff --git a/app.py b/app.py index f61b5fa..225dfcb 100644 --- a/app.py +++ b/app.py @@ -1,92 +1,92 @@ """ Copyright (C) 2018 Kunal Mehta This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . """ from collections import OrderedDict from debian import deb822 from flask import Flask, render_template from flask_cache import Cache import os import re import requests import toolforge app = Flask(__name__) toolforge.set_user_agent('apt-browser') session = requests.Session() if os.path.exists('/etc/wmcs-instancename'): cache_conf = { 'CACHE_TYPE': 'redis', 'CACHE_KEY_PREFIX': 'apt-browser1', 'CACHE_REDIS_HOST': 'tools-redis' } else: cache_conf = {} cache = Cache(app, config=cache_conf) @app.route('/') def index(): distributions = dists() comp = {} for dist in distributions: comp[dist] = components(dist) return render_template('index.html', dists=distributions, components=comp) @app.route('///') def package_listing(dist, comp, arch='binary-amd64'): if dist not in dists(): return 'Unknown distribution' if comp not in components(dist): return 'Unknown component' # TODO: validate arch? return render_template( 'packages.html', dist=dist, comp=comp, arch=arch, packages=packages(dist, comp, arch) ) -@cache.cached(timeout=60*60) +@cache.cached(timeout=60 * 60) def dists(): r = session.get('https://apt.wikimedia.org/wikimedia/dists/') return [x[0] for x in re.findall('([a-z\-]*?)/', r.text)] -@cache.cached(timeout=60*60) +@cache.cached(timeout=60 * 60) def components(dist): r = session.get('https://apt.wikimedia.org/wikimedia/dists/%s/Release' % dist) for item in deb822.Release.iter_paragraphs(r.text): return item['Components'].split(' ') @cache.cached(timeout=60) def packages(dist, component, arch='binary-amd64'): r = session.get('https://apt.wikimedia.org/wikimedia/dists/%s/%s/%s/Packages' % (dist, component, arch)) d = OrderedDict() for item in deb822.Packages.iter_paragraphs(r.text): d[item['Package']] = item['Version'] return d if __name__ == '__main__': app.run(debug=True) diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..8065675 --- /dev/null +++ b/tox.ini @@ -0,0 +1,19 @@ +[tox] + +# Ensure 1.6+ is used to support 'skipsdist' +minversion = 1.6 + +# Do not run install command +skipsdist = True + +# Environements to execute when invoking 'tox' +envlist = py34,py35 + +[testenv] +commands = flake8 +deps = flake8 + +[flake8] +exclude = .tox +max_line_length = 120 +ignore = F405