Skip to content

Commit

Permalink
Add a config parameter to show or hide source RPMs
Browse files Browse the repository at this point in the history
  • Loading branch information
David Moreau Simard committed Sep 29, 2015
1 parent cfca4fb commit 14a3186
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 8 deletions.
3 changes: 3 additions & 0 deletions local_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,6 @@
# http://dnf.readthedocs.org/en/latest/api_package.html
# PACKAGE_PROPERTIES = ['arch', 'buildtime', 'downloadsize', 'epoch', 'files', 'installtime', 'installsize', 'name',
# 'release', 'sourcerpm', 'version']

# Whether or not to show source packages as well
# SHOW_SOURCE_RPM = False
5 changes: 5 additions & 0 deletions versiontracker/api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,8 @@ def get(self, tag=None, param=None):
class PackageProperties(Resource):
def get(self):
return settings.PACKAGE_PROPERTIES


class ShowSourceRpm(Resource):
def get(self):
return settings.SHOW_SOURCE_RPM
19 changes: 13 additions & 6 deletions versiontracker/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from versiontracker import utils

from versiontracker.api.packages import Packages
from versiontracker.api.settings import Repositories, Tags, PackageProperties
from versiontracker.api.settings import Repositories, Tags, PackageProperties, ShowSourceRpm

app = Flask(__name__)
api = Api(app)
Expand All @@ -38,6 +38,8 @@
'/settings/tags/<string:tag>/<string:param>')
api.add_resource(PackageProperties,
'/settings/packageproperties')
api.add_resource(ShowSourceRpm,
'/settings/showsourcerpm')


# Jinja Filters
Expand All @@ -53,29 +55,34 @@ def jinja_truncate_string(string, length=40):
return string[:length] + (string[length:] and '...')

# App routing
# Common variables
# Common/default settings
repositories = Repositories().get()
tags = Tags().get()
show_source_rpm = ShowSourceRpm().get()
default_settings = {
'repositories': repositories,
'tags': tags,
'show_source_rpm': show_source_rpm
}

@app.route('/')
def main():
return render_template('home.html', repositories=repositories, tags=tags)
return render_template('home.html', **default_settings)


@app.route('/details/<repository>')
def details(repository):
""" Returns the list of packages for <repository> """
packages = Packages().get(repository=repository)
return render_template('details.html', repository=repository, packages=packages, repositories=repositories, tags=tags)
return render_template('details.html', repository=repository, packages=packages, **default_settings)


@app.route('/compare/<tag>')
def compare(tag):
""" Compares the versions across different repositories matching <tag> """
# TODO: I don't like this part, it works but needs improvement. Move to a function ?
matched_repositories = [repository for repository in repositories if tag in repository]

# Match package versions for each release to highlight differences
packages = utils.diff_packages(matched_repositories)

return render_template('compare.html', tag=tag, packages=packages, repositories=repositories, tags=tags)
return render_template('compare.html', tag=tag, packages=packages, **default_settings)
3 changes: 3 additions & 0 deletions versiontracker/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,8 @@
PACKAGE_PROPERTIES = ['arch', 'buildtime', 'downloadsize', 'epoch', 'files', 'installtime', 'installsize', 'name',
'release', 'sourcerpm', 'version']

# Whether or not to show source packages as well
SHOW_SOURCE_RPM = False

if os.path.exists(os.path.join(BASE_DIR, 'local_settings.py')):
from local_settings import *
4 changes: 4 additions & 0 deletions versiontracker/templates/compare.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ <h1>Package comparison for {{ tags[tag]['friendly_name'] }}</h1>
<thead>
<tr>
<th>Package</th>
<th>Arch</th>
{% for repository in repositories %}
{% if tag in repository %}
<th><a href="{{ repositories[repository]['url'] }}">{{ repositories[repository]['friendly_name'] }}</a></th>
Expand All @@ -21,18 +22,21 @@ <h1>Package comparison for {{ tags[tag]['friendly_name'] }}</h1>
</thead>
<tbody>
{% for package in packages %}
{% if (show_source_rpm) or (not show_source_rpm and packages[package]['arch'] != 'src') %}
<tr>
{% if packages[package]['different'] %}
<td><span class="label label-primary" style="font-size:100%">{{ package }}</span></td>
{% else %}
<td>{{ package }}</td>
{% endif %}
<td>{{ packages[package]['arch'] }}</td>
{% for repository in repositories %}
{% if tag in repository %}
<td>{{ packages[package][repository]['version']|truncate(length=25) if packages[package][repository]['version'] }}-{{ packages[package][repository]['release']|truncate(length=25) if packages[package][repository]['release'] }}</td>
{% endif %}
{% endfor %}
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>
Expand Down
4 changes: 2 additions & 2 deletions versiontracker/templates/details.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="row">
<div class="col-md-12 text-center">
<h1><a href="{{ repositories[repository]['url'] }}">{{ repositories[repository]['friendly_name'] }}</a></h1>
<small class="text-center">Based on <a href="{{ repositories[repository]['url'] }}">{{ repositories[repository]['url'] }}</a></small>
<small>Based on <a href="{{ repositories[repository]['url'] }}">{{ repositories[repository]['url'] }}</a></small>
</div>
</div>
<div class="row">
Expand All @@ -20,7 +20,7 @@ <h1><a href="{{ repositories[repository]['url'] }}">{{ repositories[repository]
</thead>
<tbody>
{% for package in packages %}
{% if 'src' not in packages[package]['arch'] %}
{% if (show_source_rpm) or (not show_source_rpm and packages[package]['arch'] != 'src') %}
<tr>
<td>{{ packages[package]['name'] }}</td>
<td>{{ packages[package]['arch'] }}</td>
Expand Down
5 changes: 5 additions & 0 deletions versiontracker/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ def diff_packages(repositories):
compare_version = ""
packages[package]['different'] = False
for repository in repositories:
try:
if not packages[package]['arch']:
packages[package]['arch'] = packages[package][repository]['arch']
except KeyError:
pass
try:
full_version = packages[package][repository]['version'] + packages[package][repository]['release']
except KeyError:
Expand Down

0 comments on commit 14a3186

Please sign in to comment.