Commit 8b40f5ca authored by Louis's avatar Louis
Browse files

Errors are displayed into the generated html page

parent b1276b2c
......@@ -7,6 +7,7 @@
* Package names are now case insensitive.
* Column/badges are extensible using plugins.
* If served by the web server, it is possible to submit a new request using a form.
* Better error handling
* New column/badge types:
* empty: empty column;
* link: hyperlin;
......
- HTML
- [ ] Add package name in chart tooltips
- [ ] Add generation date and "built using XXX" to html page
- [ ] Add errors
- [x] Add favicon
- [ ] Validate the HTML output
- Core
- [x] Display "Listening to http://localhost:PORT"
- [x] localhost:PORT/index.html shows a form with text entries for pkg, usr, column if no valid package is given
- [x] Add an argument to Renderer to show the default data to put in form
- [x] If this argument is None, do not show forms
- [ ] Gather errors
- [x] Fill default values sooner
- [x] Make an `error` plugin, used:
- [x] For columns whose name is not a plugin
- [x] As a `plugin['error']` used when a cell wants to use a non-existent plugin.
- Project management
- [ ] Wait for pypi downloads to work again
- [ ] Document and add screenshot
- [ ] Publish on framagit and pypi
- [ ] Make an example documentation file
- [ ] Add copyright information
- [ ] Add a generated html page to the documentation
......@@ -14,6 +14,7 @@ columns:
- ci
- html
packages:
doesnotexists:
argdispatch:
html:
html: "Tagada tsoin tsoin"
......
......@@ -4,6 +4,7 @@ import functools
import itertools
import jinja2
import json
import logging
import operator
import os
import pkg_resources
......@@ -18,6 +19,7 @@ import yaml
from pypimonitor.column import load_column_plugins
VERSION = "0.2.0-dev"
LOGGER = logging.getLogger(__name__)
_client = xmlrpclib.ServerProxy('https://pypi.python.org/pypi')
......@@ -41,17 +43,13 @@ def random_color(seed, saturation, value):
def iter_user_packages(user):
for _, package in _client.user_packages(user):
try:
yield package
except urllib.error.HTTPError as error:
sys.stderr.write("Ignoring user '{}': {}.".format(
user,
str(error),
))
yield package
class Renderer:
def __init__(self, config, form=None):
self.errors = set()
# Processing config
self.config = config
if "columns" not in self.config:
......@@ -78,7 +76,7 @@ class Renderer:
try:
self.packages[name] = Package(name)
except Exception as error:
sys.stderr.write("Ignoring package '{}': {}.\n".format(name, error))
self.log_error("Ignoring package '{}': {}".format(name, error))
continue
# Processing form
......@@ -109,7 +107,13 @@ class Renderer:
packages = list(itertools.chain(*[item.split(",") for item in packages]))
if users is not None:
for user in users:
packages.extend(iter_user_packages(user))
try:
packages.extend(iter_user_packages(user))
except urllib.error.HTTPError as error:
LOGGER.error("Ignoring user '{}': {}".format(
user,
str(error),
))
packages = list(set(packages))
config['packages'] = {pkg: {} for pkg in set(packages)}
......@@ -153,8 +157,13 @@ class Renderer:
columns=self.columns,
packages=self.packages,
form=self.form,
errors=self.errors,
)
def log_error(self, message):
LOGGER.error(message)
self.errors.add(message)
class Package:
......@@ -163,7 +172,7 @@ class Package:
}
def __init__(self, name):
sys.stderr.write("Retrieving information about pypi package '{}'...\n".format(name))
LOGGER.info("Retrieving information about pypi package '{}'...\n".format(name))
try:
self.rawdata = json.loads(requests.get("http://pypi.python.org/pypi/{}/json".format(name)).text)
except Exception as error:
......
......@@ -45,3 +45,16 @@ table.badges td {
table.badges thead td {
text-align: center;
}
/*******************************************************************************
* ERRORS
******************************************************************************/
ul.errors {
color: #D8000C;
background-color: #FFBABA;
border: 2px solid #D8000C;
border-radius: 1em;
padding-top: 1em;
padding-bottom: 1em;
}
......@@ -13,6 +13,13 @@
{% endif %}
</head>
<body>
{% if errors %}
<ul class="errors">
{% for message in errors|sort %}
<li>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
{% if form != none %}
<form action="{{ form.rooturl }}" method="get">
<span class="tooltip">Packages <div class="tooltiptext">Comma separated list of packages to monitor.</div></span>: <input type="text" name="pkg" value="{{ form.pkg }}">
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment