From 0c4dfdec5b55b6064dccc38bbfb0a7c0699c895a Mon Sep 17 00:00:00 2001 From: Agustin Henze Date: Thu, 30 May 2013 17:41:06 -0300 Subject: Imported Upstream version 5.4.4 --- nikola/plugins/task_render_posts.py | 84 ++++++++++++++++++++++++++++++++----- 1 file changed, 74 insertions(+), 10 deletions(-) (limited to 'nikola/plugins/task_render_posts.py') diff --git a/nikola/plugins/task_render_posts.py b/nikola/plugins/task_render_posts.py index a4d5578..4be68bf 100644 --- a/nikola/plugins/task_render_posts.py +++ b/nikola/plugins/task_render_posts.py @@ -23,10 +23,20 @@ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. from copy import copy -import os +import codecs +import string from nikola.plugin_categories import Task -from nikola import utils +from nikola import utils, rc4 + + +def wrap_encrypt(path, password): + """Wrap a post with encryption.""" + with codecs.open(path, 'rb+', 'utf8') as inf: + data = inf.read() + "" + data = CRYPT.substitute(data=rc4.rc4(password, data)) + with codecs.open(path, 'wb+', 'utf8') as outf: + outf.write(data) class RenderPosts(Task): @@ -41,25 +51,26 @@ class RenderPosts(Task): "translations": self.site.config["TRANSLATIONS"], "timeline": self.site.timeline, "default_lang": self.site.config["DEFAULT_LANG"], + "hide_untranslated_posts": self.site.config['HIDE_UNTRANSLATED_POSTS'], } flag = False for lang in kw["translations"]: - # TODO: timeline is global, get rid of it deps_dict = copy(kw) deps_dict.pop('timeline') for post in kw['timeline']: source = post.source_path dest = post.base_path - if lang != kw["default_lang"]: - dest += '.' + lang - source_lang = source + '.' + lang - if os.path.exists(source_lang): - source = source_lang + if not post.is_translation_available(lang) and kw["hide_untranslated_posts"]: + continue + else: + source = post.translated_source_path(lang) + if lang != post.default_lang: + dest = dest + '.' + lang flag = True - yield { + task = { 'basename': self.name, - 'name': dest.encode('utf-8'), + 'name': dest, 'file_dep': post.fragment_deps(lang), 'targets': [dest], 'actions': [(self.site.get_compiler(post.source_path), @@ -67,6 +78,9 @@ class RenderPosts(Task): 'clean': True, 'uptodate': [utils.config_changed(deps_dict)], } + if post.meta('password'): + task['actions'].append((wrap_encrypt, (dest, post.meta('password')))) + yield task if flag is False: # Return a dummy task yield { 'basename': self.name, @@ -74,3 +88,53 @@ class RenderPosts(Task): 'uptodate': [True], 'actions': [], } + + +CRYPT = string.Template("""\ + + + +
+
+
+This post is password-protected. + + +
+
+
""") -- cgit v1.2.3