X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=tags.py;h=44f1a070d02b08c02e9b1f265ba9ec8095bd5fb5;hb=af6063f9b0099f34c8817cd5c63802a160bc0463;hp=35c4634ca53702fe4791bc70237fe13aa6018a2b;hpb=9379ed3a21cf6aaacc9c3d3a2f6349aa22b7d3ee;p=phdru.name%2Fcgi-bin%2Fblog-ru%2Fsearch-tags.git diff --git a/tags.py b/tags.py index 35c4634..44f1a07 100644 --- a/tags.py +++ b/tags.py @@ -6,7 +6,7 @@ except ImportError: import pickle try: - blog_file = open(blog_filename, "rb") + blog_file = open('../../../../phdru.name/ru/' + blog_filename, "rb") except IOError: blog_dict = {} else: @@ -25,6 +25,11 @@ def tag_exists(tag): return False def _test_post(post, tree): + """Test if the list of tags in the post satisfies condition + + Recursively evaluate the tree against the list of tags in the post. + + """ op = tree[0] if op == 'NAME': tag = tree[1] @@ -40,16 +45,24 @@ def _test_post(post, tree): return value1 or value2 elif op == 'NOT': return not _test_post(post, tree[1]) + elif op == 'PARENS': + return _test_post(post, tree[1]) else: raise ValueError("Cannot get there") -def calc_tree(tree): +def find_tags(tree): + """Test every blog post against parsed expression + + Return all posts that passed the test. + + """ _posts = [] for (year, month, day), posts in blog_dict.iteritems(): for post in posts: if _test_post(post, tree): _posts.append(( - '/'.join((year, month, day, post[0].replace('.tmpl', '.html'))), + year, month, day, + '/'.join((year, month, day, post[0][:-len("tmpl")] + "html")), post[1])) - _posts.sort() + _posts.sort(reverse=True) return _posts