diff --git a/hyde/ext/plugins/urls.py b/hyde/ext/plugins/urls.py index 13fc181..9f25abf 100644 --- a/hyde/ext/plugins/urls.py +++ b/hyde/ext/plugins/urls.py @@ -51,8 +51,6 @@ class UrlCleanerPlugin(Plugin): settings = config.urlcleaner - print settings.to_dict() - def clean_url(urlgetter): @wraps(urlgetter) def wrapper(site, path): @@ -73,4 +71,4 @@ class UrlCleanerPlugin(Plugin): return wrapper Site.___url_cleaner_patched___ = True - Site.content_url = clean_url(Site.content_url) \ No newline at end of file + Site.content_url = clean_url(Site.content_url) diff --git a/hyde/plugin.py b/hyde/plugin.py index d13dc8a..473df63 100644 --- a/hyde/plugin.py +++ b/hyde/plugin.py @@ -8,10 +8,11 @@ from hyde import loader from hyde.exceptions import HydeException from hyde.fs import File -from hyde.util import getLoggerWithNullHandler +from hyde.util import getLoggerWithNullHandler, first_match from hyde.model import Expando from functools import partial + import re import subprocess import traceback @@ -263,6 +264,11 @@ class CLTransformer(Plugin): return app def option_prefix(self, option): + """ + Return the prefix for the given option. + + Defaults to --. + """ return "--" def process_args(self, supported): @@ -273,32 +279,30 @@ class CLTransformer(Plugin): args = {} args.update(self.defaults) try: - args.update(getattr(self.settings, 'args').to_dict()) + args.update(self.settings.args.to_dict()) except AttributeError: pass - result = [] - for arg in supported: - if isinstance(arg, tuple): - (descriptive, short) = arg + params = [] + for option in supported: + if isinstance(option, tuple): + (descriptive, short) = option else: - descriptive = short = arg - - equal = False - if descriptive.endswith("="): - descriptive = descriptive[:-1] - equal = True - if descriptive in args or short in args: - val = args[descriptive if descriptive in args else short] - if equal and val: - result.append("%s%s=%s" % (self.option_prefix(descriptive), - descriptive, str(val))) - else: - result.append("%s%s" % (self.option_prefix(descriptive), - descriptive)) - if val: - result.append(str(val)) - return result + descriptive = short = option + + options = [descriptive.rstrip("="), short.rstrip("=")] + match = first_match(lambda arg: arg in options, args) + if match: + val = args[match] + param = "%s%s" % (self.option_prefix(descriptive), + descriptive) + if descriptive.endswith("="): + param.append(val) + val = None + params.append(param) + if val: + params.append(val) + return params def call_app(self, args): """ diff --git a/hyde/tests/ext/test_images.py b/hyde/tests/ext/test_images.py index 7cb63ed..79fcdbd 100644 --- a/hyde/tests/ext/test_images.py +++ b/hyde/tests/ext/test_images.py @@ -45,7 +45,6 @@ class TestImageSizer(object): assert f.exists html = f.read_all() assert html - print html return html def test_size_image(self): diff --git a/hyde/tests/ext/test_stylus.py b/hyde/tests/ext/test_stylus.py index 1f2af53..039bebf 100644 --- a/hyde/tests/ext/test_stylus.py +++ b/hyde/tests/ext/test_stylus.py @@ -45,9 +45,6 @@ class TestLess(object): assert target.exists text = target.read_all() expected_text = File(STYLUS_SOURCE.child('expected-site.css')).read_all() - print text.strip() - print "=" * 80 - print expected_text.strip() assert text.strip() == expected_text.strip() def test_can_compress_with_stylus(self): diff --git a/hyde/tests/ext/test_tagger.py b/hyde/tests/ext/test_tagger.py index e5cc437..105037c 100644 --- a/hyde/tests/ext/test_tagger.py +++ b/hyde/tests/ext/test_tagger.py @@ -86,7 +86,6 @@ class TestTagger(object): assert q - print q assert q('li').length == 2 assert q('li a:first-child').attr('href') == '/blog/another-sad-post.html' assert q('li a:eq(1)').attr('href') == '/blog/sad-post.html' diff --git a/hyde/tests/test_jinja2template.py b/hyde/tests/test_jinja2template.py index 734fd70..7331c3b 100644 --- a/hyde/tests/test_jinja2template.py +++ b/hyde/tests/test_jinja2template.py @@ -590,11 +590,10 @@ item_list: t.configure(None) t.env.filters['dateformat'] = dateformat html = t.render(text, {}).strip() - print html actual = PyQuery(html) assert actual("ul").length == 2 assert actual("li").length == 6 items = [item.text for item in actual("ul.top li")] assert items == ["A", "B", "C"] items = [item.text for item in actual("ul.mid li")] - assert items == ["D", "E", "F"] \ No newline at end of file + assert items == ["D", "E", "F"] diff --git a/hyde/util.py b/hyde/util.py index 152f467..eff646e 100644 --- a/hyde/util.py +++ b/hyde/util.py @@ -92,7 +92,6 @@ class ColorFormatter(logging.Formatter): logging.ColorFormatter = ColorFormatter - def make_method(method_name, method_): def method__(*args, **kwargs): return method_(*args, **kwargs) @@ -112,4 +111,14 @@ def add_method(obj, method_name, method_, *args, **kwargs): def pairwalk(iterable): a, b = tee(iterable) next(b, None) - return izip(a, b) \ No newline at end of file + return izip(a, b) + +def first_match(predicate, iterable): + """ + Gets the first element matched by the predicate + in the iterable. + """ + for item in iterable: + if predicate(item): + return item + return None