From 964c27f9464f7bf8b2573bb7bfced3e6101229f3 Mon Sep 17 00:00:00 2001 From: Simon Conseil Date: Tue, 21 Jul 2020 22:57:23 -0400 Subject: [PATCH] Fix doc issues with some plugins --- sigal/plugins/adjust.py | 10 ++++--- sigal/plugins/encrypt/__init__.py | 41 +++++++++++++++++++++++++++ sigal/plugins/encrypt/encrypt.py | 46 +++---------------------------- sigal/plugins/feeds.py | 2 +- sigal/plugins/upload_s3.py | 4 +-- 5 files changed, 54 insertions(+), 49 deletions(-) diff --git a/sigal/plugins/adjust.py b/sigal/plugins/adjust.py index 4e6daa6..82a3779 100644 --- a/sigal/plugins/adjust.py +++ b/sigal/plugins/adjust.py @@ -6,10 +6,12 @@ Based on pilkit's Adjust_ processor. Settings:: - adjust_options = {'color': 1.0, - 'brightness': 1.0, - 'contrast': 1.0, - 'sharpness': 1.0} + adjust_options = { + 'color': 1.0, + 'brightness': 1.0, + 'contrast': 1.0, + 'sharpness': 1.0 + } """ diff --git a/sigal/plugins/encrypt/__init__.py b/sigal/plugins/encrypt/__init__.py index 6fe3cc8..e530ef9 100644 --- a/sigal/plugins/encrypt/__init__.py +++ b/sigal/plugins/encrypt/__init__.py @@ -1 +1,42 @@ +""" +Plugin to protect gallery by encrypting image files using a password. + +Options:: + + encrypt_options = { + 'password': 'password', + 'ask_password': False, + 'gcm_tag': 'randomly_generated', + 'kdf_salt': 'randomly_generated', + 'kdf_iters': 10000, + } + +- ``password``: The password used to encrypt the images on gallery build, + and decrypt them when viewers access the gallery. No default value. You must + specify a password. +- ``ask_password``: Whether or not viewers are asked for the password to view + the gallery. If set to ``False``, the password will be present in the HTML + files so the images are decrypted automatically. Defaults to ``False``. +- ``gcm_tag``, ``kdf_salt``, ``kdf_iters``: Cryptographic parameters used when + encrypting the files. ``gcm_tag``, ``kdf_salt`` are meant to be randomly + generated, ``kdf_iters`` defaults to 10000. Do not specify them in the config + file unless you have good reasons to do so. + +Note: The plugin caches the cryptographic parameters (but not the password) +after the first build, so that incremental builds can share the same +credentials. DO NOT CHANGE THE PASSWORD OR OTHER CRYPTOGRAPHIC PARAMETERS ONCE +A GALLERY IS BUILT, or there will be inconsistency in encrypted files and +viewers will not be able to see some of the images any more. + +.. _compatibility-with-encrypt: + +Compatibility with other plugins: + +- ``zip_gallery``: if you enable both this plugin and the ``zip_gallery`` + plugin, the generated zip archives will contain encrypted images, which is + generally meaningless since viewers cannot easily decrypt them outside + a browser. + +""" + from .encrypt import register diff --git a/sigal/plugins/encrypt/encrypt.py b/sigal/plugins/encrypt/encrypt.py index f9fabba..27ca094 100644 --- a/sigal/plugins/encrypt/encrypt.py +++ b/sigal/plugins/encrypt/encrypt.py @@ -18,44 +18,6 @@ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. -'''Plugin to protect gallery by encrypting image files using a password. - -Options:: - - encrypt_options = { - 'password': 'password', - 'ask_password': False, - 'gcm_tag': 'randomly_generated', - 'kdf_salt': 'randomly_generated', - 'kdf_iters': 10000 - } - -- ``password``: The password used to encrypt the images on gallery build, - and decrypt them when viewers access the gallery. No default value. You must - specify a password. -- ``ask_password``: Whether or not viewers are asked for the password to view - the gallery. If set to ``False``, the password will be present in the HTML files - so the images are decrypted automatically. Defaults to ``False``. -- ``gcm_tag``, ``kdf_salt``, ``kdf_iters``: Cryptographic parameters used when - encrypting the files. ``gcm_tag``, ``kdf_salt`` are meant to be randomly generated, - ``kdf_iters`` defaults to 10000. Do not specify them in the config file unless - you have good reasons to do so. - -Note: The plugin caches the cryptographic parameters (but not the password) after -the first build, so that incremental builds can share the same credentials. -DO NOT CHANGE THE PASSWORD OR OTHER CRYPTOGRAPHIC PARAMETERS ONCE A GALLERY IS -BUILT, or there will be inconsistency in encrypted files and viewers will not be able -to see some of the images any more. - -.. _compatibility-with-encrypt: - -Compatibility with other plugins: - -- ``zip_gallery``: if you enable both this plugin and the ``zip_gallery`` plugin, - the generated zip archives will contain encrypted images, which is generally - meaningless since viewers cannot easily decrypt them outside a browser. -''' - import logging import os import pickle @@ -87,7 +49,7 @@ def get_options(settings, cache): if "encrypt_options" not in settings: logging.error("Encrypt: no encrypt_options in settings") raise ValueError("no encrypt_options in settings") - + # try load credential from cache try: options = cache["credentials"] @@ -108,16 +70,16 @@ def get_options(settings, cache): options["filtered_password"] = "" if options["ask_password"] else options["escaped_password"] if "gcm_tag" not in options: - options["gcm_tag"] = gen_rand_string() + options["gcm_tag"] = gen_rand_string() options["escaped_gcm_tag"] = options["gcm_tag"].translate(table) - + if "kdf_salt" not in options: options["kdf_salt"] = gen_rand_string() options["escaped_kdf_salt"] = options["kdf_salt"].translate(table) if "galleryId" not in options: options["galleryId"] = gen_rand_string(6) - + if "kdf_iters" not in options: options["kdf_iters"] = 10000 diff --git a/sigal/plugins/feeds.py b/sigal/plugins/feeds.py index b7c49fd..ec18fae 100644 --- a/sigal/plugins/feeds.py +++ b/sigal/plugins/feeds.py @@ -22,7 +22,6 @@ from datetime import datetime from jinja2 import Markup -from feedgenerator import Atom1Feed, Rss201rev2Feed from sigal import signals logger = logging.getLogger(__name__) @@ -43,6 +42,7 @@ def generate_feeds(gallery): def generate_feed(gallery, medias, feed_type=None, feed_url='', nb_items=0): + from feedgenerator import Atom1Feed, Rss201rev2Feed root_album = gallery.albums['.'] cls = Rss201rev2Feed if feed_type == 'rss' else Atom1Feed feed = cls( diff --git a/sigal/plugins/upload_s3.py b/sigal/plugins/upload_s3.py index 49e27f5..310c4d4 100644 --- a/sigal/plugins/upload_s3.py +++ b/sigal/plugins/upload_s3.py @@ -27,14 +27,13 @@ import os from click import progressbar -import boto -from boto.s3.key import Key from sigal import signals logger = logging.getLogger(__name__) def upload_s3(gallery, settings=None): + import boto upload_files = [] # Get local files @@ -86,6 +85,7 @@ def generate_cache_metadata(gallery, f): def upload_file(gallery, bucket, f): logger.debug("Uploading file %s" % (f)) + from boto.s3.key import Key key = Key(bucket) key.key = f