From 332b5d7c80f7af68c2f581dae5d70b8c78ec3ddd Mon Sep 17 00:00:00 2001 From: volpino Date: Sun, 2 Sep 2012 18:39:04 +0200 Subject: [PATCH 1/3] euscan: Added XML output Signed-off-by: volpino --- TODO | 2 +- pym/euscan/helpers.py | 31 +++++++++++++++++++++++++++++++ pym/euscan/out.py | 4 ++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/TODO b/TODO index eaa0d72..19126b4 100644 --- a/TODO +++ b/TODO @@ -13,7 +13,7 @@ euscan ### Command line interface -- html and xml output +- html output ### Misc diff --git a/pym/euscan/helpers.py b/pym/euscan/helpers.py index f748c2e..5e3e6ea 100644 --- a/pym/euscan/helpers.py +++ b/pym/euscan/helpers.py @@ -2,6 +2,7 @@ import os import re import errno import urllib2 +from xml.dom.minidom import Document import portage from portage import dep @@ -451,3 +452,33 @@ def parse_mirror(uri): return None return uri + + +def dict_to_xml(data, indent): + doc = Document() + root = doc.createElement("euscan") + doc.appendChild(root) + + def _set_value(parent, value): + if isinstance(value, dict): + for k, v in value.iteritems(): + node = doc.createElement(k) + _set_value(node, v) + parent.appendChild(node) + elif isinstance(value, list): + for item in value: + node = doc.createElement("value") + text = doc.createTextNode(item) + node.appendChild(text) + parent.appendChild(node) + else: + text = doc.createTextNode(unicode(value)) + parent.appendChild(text) + + for key, value in data.iteritems(): + node = doc.createElement("package") + node.setAttribute("name", key) + _set_value(node, value) + root.appendChild(node) + + return doc.toprettyxml(indent=" " * indent) diff --git a/pym/euscan/out.py b/pym/euscan/out.py index dcdd5f0..e6e6ebf 100644 --- a/pym/euscan/out.py +++ b/pym/euscan/out.py @@ -10,6 +10,8 @@ import portage from portage.output import EOutput, TermProgressBar from gentoolkit import pprinter as pp +from euscan.helpers import dict_to_xml + mirrors_ = None @@ -200,6 +202,8 @@ class EuscanOutput(object): format_ = format_ or self.config["format"] if format_.lower() == "json": return json.dumps(data, indent=self.config["indent"]) + elif format_.lower() == "xml": + return dict_to_xml(data, indent=self.config["indent"]) elif format_.lower() == "dict": return data else: From 2019b245e8c370d5b55b3e99e0da319d6a35146f Mon Sep 17 00:00:00 2001 From: volpino Date: Sun, 2 Sep 2012 18:58:01 +0200 Subject: [PATCH 2/3] euscan: Adding config file support Signed-off-by: volpino --- TODO | 1 - bin/euscan | 3 ++- pym/euscan/__init__.py | 11 +++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/TODO b/TODO index 19126b4..4ed8061 100644 --- a/TODO +++ b/TODO @@ -17,7 +17,6 @@ euscan ### Misc -- Add a config file (/etc/euscan.conf, ~/.euscan.conf) - Add a HTTP cache (configurable) ### Tests diff --git a/bin/euscan b/bin/euscan index 76922d4..5d5e812 100755 --- a/bin/euscan +++ b/bin/euscan @@ -230,7 +230,8 @@ def parse_args(): def main(): """Parse command line and execute all actions.""" CONFIG['nocolor'] = ( - settings["NOCOLOR"] in ('yes', 'true') or not isatty + CONFIG['nocolor'] or + (settings["NOCOLOR"] in ('yes', 'true') or not isatty) ) if CONFIG['nocolor']: pp.output.nocolor() diff --git a/pym/euscan/__init__.py b/pym/euscan/__init__.py index dad6742..12c4a16 100644 --- a/pym/euscan/__init__.py +++ b/pym/euscan/__init__.py @@ -5,6 +5,10 @@ __version__ = "git" +import ConfigParser +import os + + CONFIG = { 'nocolor': False, 'quiet': False, @@ -27,6 +31,13 @@ CONFIG = { 'ebuild-uri': False, } +config = ConfigParser.ConfigParser() +config.read(['/etc/euscan.conf', os.path.expanduser('~/.euscan.conf')]) +if config.has_section("euscan"): + for key, value in config.items("euscan"): + if key in CONFIG: + CONFIG[key] = value + BLACKLIST_VERSIONS = [ # Compatibility package for running binaries linked against a # pre gcc 3.4 libstdc++, won't be updated From 80ca711565e8639b508319fc9e4e4293c7e16389 Mon Sep 17 00:00:00 2001 From: volpino Date: Mon, 3 Sep 2012 15:09:12 +0200 Subject: [PATCH 3/3] euscanwww: Improved email template Now the code is quite cryptic but it's to remove useless blank lines in the final output. Signed-off-by: volpino --- euscanwww/djeuscan/tasks.py | 2 + .../euscan/accounts/euscan_email.txt | 65 +++++++------------ 2 files changed, 25 insertions(+), 42 deletions(-) diff --git a/euscanwww/djeuscan/tasks.py b/euscanwww/djeuscan/tasks.py index bf936b0..f70c8fe 100644 --- a/euscanwww/djeuscan/tasks.py +++ b/euscanwww/djeuscan/tasks.py @@ -304,6 +304,8 @@ def process_emails(profiles, only_if_vlogs=False): if only_if_vlogs and not vlogs.count(): continue + vlogs = vlogs.order_by("-datetime") + infos = get_user_fav_infos(user) infos["user"] = user infos["vlogs"] = vlogs diff --git a/euscanwww/djeuscan/templates/euscan/accounts/euscan_email.txt b/euscanwww/djeuscan/templates/euscan/accounts/euscan_email.txt index fe609d2..c17c339 100644 --- a/euscanwww/djeuscan/templates/euscan/accounts/euscan_email.txt +++ b/euscanwww/djeuscan/templates/euscan/accounts/euscan_email.txt @@ -1,50 +1,31 @@ -{% load djeuscan_helpers %} -{% load sub %} -Hello {{ user }}, +{% load djeuscan_helpers %}{% load sub %}Hello {{ user }}, {% if vlogs %}euscan news: - -{% for vlog in vlogs %} - * {{ vlog }} {% if vlog.vtype and not vlog.vtype|is_stable %}({{ vlog.vtype }}){% endif %} - {{ vlog.datetime }} {% endfor %} +{% for vlog in vlogs %} * {{ vlog.package|ljust:"35" }} {{ vlog.version }} {% if vlog.vtype and not vlog.vtype|is_stable %}({{ vlog.vtype }}){% endif %} +{% endfor %} {% endif %} Summary: - {% with categories|length as num_categories %}{% if num_categories %} -Watching {{ num_categories }} categor{{ num_categories|pluralize:"y,ies"}} -{{ categories_upstream }} new upstream version{{ categories_upstream|pluralize:"s"}} -{% if categories_upstream %} -Hot categories: -{% for c in categories|slice:":3" %} - * {{ c.category }} ({{ c.n_versions|sub:c.n_packaged|sub:c.n_overlay }}){% endfor %} +Watching {{ num_categories }} categor{{ num_categories|pluralize:"y,ies"}}: {{ categories_upstream }} upstream version{{ categories_upstream|pluralize:"s"}} +{% if categories_upstream %}Hot categories: +{% for c in categories|slice:":3" %} * {{ c.category }} ({{ c.n_versions|sub:c.n_packaged|sub:c.n_overlay }}) +{% endfor %} +{% endif %}{% endif %}{% endwith %}{% with herds|length as num_herds %}{% if num_herds %} +Watching {{ num_herds }} herd{{ num_herds|pluralize:"s"}}: {{ herds_upstream }} upstream version{{ herds_upstream|pluralize:"s"}} +{% if herds_upstream %}Hot herds: +{% for c in herds|slice:":3" %} * {{ c.herds__herd }} ({{ c.n_versions|sub:c.n_packaged|sub:c.n_overlay }}) +{% endfor %} +{% endif %}{% endif %}{% endwith %}{% with maintainers|length as num_maintainers %}{% if num_maintainers %} +Watching {{ num_maintainers }} maintainer{{ num_maintainers|pluralize:"s"}}: {{ maintainers_upstream }} upstream version{{ maintainers_upstream|pluralize:"s"}} +{% if maintainers_upstream %}Hot maintainers: +{% for c in maintainers|slice:":3" %} * {{ c.maintainers__name }} ({{ c.n_versions|sub:c.n_packaged|sub:c.n_overlay }}) +{% endfor %} +{% endif %}{% endif %}{% endwith %}{% with packages|length as num_packages %}{% if num_packages %} +Watching {{ num_packages }} package{{ num_packages|pluralize:"s"}}: {{ packages_upstream }} upstream version{{ packages_upstream|pluralize:"s"}} +{% if packages_upstream %}Hot packages: +{% for c in packages|slice:":3" %} * {{ c }} ({{ c.n_versions|sub:c.n_packaged|sub:c.n_overlay }}) +{% endfor %} {% endif %}{% endif %}{% endwith %} - -{% with herds|length as num_herds %}{% if num_herds %} -Watching {{ num_herds }} herd{{ num_herds|pluralize:"s"}} -{{ herds_upstream }} new upstream version{{ herds_upstream|pluralize:"s"}} -{% if herds_upstream %} -Hot herds: -{% for c in herds|slice:":3" %} - * {{ c.herds__herd }} ({{ c.n_versions|sub:c.n_packaged|sub:c.n_overlay }}){% endfor %} -{% endif %}{% endif %}{% endwith %} - -{% with maintainers|length as num_maintainers %}{% if num_maintainers %} -Watching {{ num_maintainers }} maintainer{{ num_maintainers|pluralize:"s"}} -{{ maintainers_upstream }} new upstream version{{ maintainers_upstream|pluralize:"s"}} -{% if maintainers_upstream %} -Hot maintainers: -{% for c in maintainers|slice:":3" %} -* {{ c.maintainers__name }} ({{ c.n_versions|sub:c.n_packaged|sub:c.n_overlay }}){% endfor %} -{% endif %}{% endif %}{% endwith %} - -{% with packages|length as num_packages %}{% if num_packages %} -Watching {{ num_packages }} package{{ num_packages|pluralize:"s"}} -{{ packages_upstream }} new upstream version{{ packages_upstream|pluralize:"s"}} -{% if packages_upstream %} -Hot packages: -{% for c in packages|slice:":3" %} -* {{ c }} ({{ c.n_versions|sub:c.n_packaged|sub:c.n_overlay }}){% endfor %} -{% endif %}{% endif %}{% endwith %} - -- -This email was sent by euscan +This email was sent by euscan, please do not reply.