Browse Source

Add pre-commit config

pull/440/head
Simon Conseil 5 years ago
parent
commit
bab54d1286
  1. 19
      .pre-commit-config.yaml
  2. 1
      docs/changelog.py
  3. 2
      docs/faq.rst
  4. 1
      docs/plugins.rst
  5. 4
      setup.cfg
  6. 1
      setup.py
  7. 3
      sigal/image.py
  8. 1
      sigal/plugins/adjust.py
  9. 48
      sigal/plugins/encrypt/static/decrypt.js
  10. 4
      sigal/plugins/nonmedia_files.py
  11. 2
      sigal/themes/default/templates/piwik.html
  12. 1
      tests/sample/pictures/dir1/test1/flickr_jerquiaga_2394751088_cc-by-nc.md
  13. 1
      tests/sample/pictures/dir1/test2/CMB_Timeline300_no_WMAP.md
  14. 2
      tests/sample/pictures/nomedia/created/.nomedia
  15. 2
      tests/test_image.py
  16. 2
      tests/test_video.py

19
.pre-commit-config.yaml

@ -0,0 +1,19 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: check-yaml
- id: check-added-large-files
- id: trailing-whitespace
exclude: ".*(galleria|photoswipe|jquery).*$"
- id: end-of-file-fixer
exclude: ".*(galleria|photoswipe|jquery).*$"
- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8
types: [file, python]
- repo: https://github.com/timothycrosley/isort
rev: 5.8.0
hooks:
- id: isort

1
docs/changelog.py

@ -37,7 +37,6 @@ import os
import re
from git import Repo
from github import Github
this_repo = Repo(os.path.join(os.path.dirname(__file__), ".."))

2
docs/faq.rst

@ -119,7 +119,7 @@ end of the file, like so::
#!/bin/sh
# automatically configured by git-annex
git annex post-receive
/home/foo/src/git-hooks/sigal-git-hook
This assumes, of course, that you are running your own Git server;

1
docs/plugins.rst

@ -145,4 +145,3 @@ ZIP Gallery plugin
==================
.. automodule:: sigal.plugins.zip_gallery

4
setup.cfg

@ -56,7 +56,7 @@ ignore =
readthedocs.yml
[flake8]
ignore = E731, W504
ignore = E731,W504,E501
[isort]
known_third_party=blinker,click,jinja2,markdown,natsort,PIL,Pillow
known_third_party=blinker,click,jinja2,markdown,natsort,PIL,Pillow,pilkit

1
setup.py

@ -1,2 +1,3 @@
from setuptools import setup
setup()

3
sigal/image.py

@ -37,11 +37,10 @@ import warnings
from copy import deepcopy
from datetime import datetime
import pilkit.processors
from PIL import Image as PILImage
from PIL import ImageFile, ImageOps, IptcImagePlugin
from PIL.ExifTags import GPSTAGS, TAGS
import pilkit.processors
from pilkit.processors import Transpose
from pilkit.utils import save_image

1
sigal/plugins/adjust.py

@ -18,6 +18,7 @@ Settings::
import logging
from pilkit.processors import Adjust
from sigal import signals
logger = logging.getLogger(__name__)

48
sigal/plugins/encrypt/static/decrypt.js

@ -7,10 +7,10 @@
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@ -82,7 +82,7 @@ class Decryptor {
const aes_key = await Decryptor._initAesKey(crypto, salt, iters, shared_key);
if (await this._swCheckAesKey(aes_key, gcm_tag)) {
this.workerReady = true;
this._decrypt = (encrypted_blob_arraybuffer) =>
this._decrypt = (encrypted_blob_arraybuffer) =>
Decryptor.decrypt(crypto, encrypted_blob_arraybuffer, aes_key, gcm_tag);
this._swNotifyWorkerReady();
} else {
@ -167,7 +167,7 @@ class Decryptor {
_mGetLocalConfig() {
try {
const local_config = JSON.parse(localStorage.getItem(this._config.galleryId));
if (local_config
if (local_config
&& local_config.galleryId
&& local_config.sw_script
&& local_config.password
@ -178,7 +178,7 @@ class Decryptor {
}
} catch (e) {
console.error("Error retrieving config from local storage: " + e);
}
}
return null;
}
@ -196,7 +196,7 @@ class Decryptor {
this.serviceWorker = registration.active;
}
navigator.serviceWorker.onmessage =
navigator.serviceWorker.onmessage =
(e) => Decryptor.onMessage(this.serviceWorker, e);
this.serviceWorker = this._proxyWrap(this.serviceWorker);
@ -283,10 +283,10 @@ class Decryptor {
static async _initAesKey(crypto, kdf_salt, kdf_iters, shared_key) {
const pbkdf2key = await crypto.importKey(
"raw",
shared_key,
"PBKDF2",
false,
"raw",
shared_key,
"PBKDF2",
false,
["deriveKey"]
);
const pbkdf2params = {
@ -296,10 +296,10 @@ class Decryptor {
iterations: kdf_iters
};
return await crypto.deriveKey(
pbkdf2params,
pbkdf2key,
{ name: "AES-GCM", length: 128 },
false,
pbkdf2params,
pbkdf2key,
{ name: "AES-GCM", length: 128 },
false,
["decrypt"]
);
}
@ -315,8 +315,8 @@ class Decryptor {
static async checkMagicString(arraybuffer) {
const sample = new DataView(
arraybuffer,
0,
arraybuffer,
0,
Decryptor.MAGIC_STRING_ARRAYBUFFER.byteLength
);
for (let i = 0; i < Decryptor.MAGIC_STRING_ARRAYBUFFER.byteLength; i++) {
@ -343,7 +343,7 @@ class Decryptor {
// although 1 byte of data seems not acceptable for some browsers
// in which case crypto.decrypt will throw an error
// "The provided data is too small"
if (arraybuffer.byteLength <
if (arraybuffer.byteLength <
Decryptor.MAGIC_STRING_ARRAYBUFFER.byteLength
+ Decryptor.IV_LENGTH
+ 1) {
@ -354,14 +354,14 @@ class Decryptor {
// data is not encrypted
return blob_or_arraybuffer;
}
const iv = new DataView(
arraybuffer,
Decryptor.MAGIC_STRING_ARRAYBUFFER.byteLength,
arraybuffer,
Decryptor.MAGIC_STRING_ARRAYBUFFER.byteLength,
Decryptor.IV_LENGTH
);
const ciphertext = new DataView(
arraybuffer,
arraybuffer,
Decryptor.MAGIC_STRING_ARRAYBUFFER.byteLength + Decryptor.IV_LENGTH
);
const decrypted = await crypto.decrypt(
@ -437,7 +437,7 @@ class Decryptor {
if (!(method in instance && instance[method] instanceof Function)) {
return Promise.reject(new Error(`no such method: ${method}`))
}
try {
let promise_or_value = instance[method].apply(instance, args);
if (promise_or_value instanceof Promise) {
@ -462,7 +462,7 @@ class Decryptor {
Decryptor._asyncReturn(instance, method, args)
.then(
(result) => { return {type: "reply", success: true, result: result}; },
(result) => { return {type: "reply", success: true, result: result}; },
(error) => { return {type: "reply", success: false, result: error.message}; }
)
.then((reply) => {
@ -589,7 +589,7 @@ class Decryptor {
}
);
decrypted_response.headers.set("content-length", decrypted_blob.size);
Decryptor._addToCache(request, decrypted_response.clone());
console.debug(`Responding with decrypted response ${request.url}`);

4
sigal/plugins/nonmedia_files.py

@ -30,11 +30,9 @@ import os
from PIL import Image as PILImage
from PIL import ImageDraw, ImageFont
from pilkit.utils import save_image
from sigal import signals
from sigal import utils
from sigal import signals, utils
from sigal.gallery import Media
from sigal.settings import Status

2
sigal/themes/default/templates/piwik.html

@ -14,4 +14,4 @@
</script>
<noscript><p><img src="{{ settings.piwik.tracker_url }}/piwik.php?idsite={{ settings.piwik.site_id }}" style="border:0;" alt="" /></p></noscript>
<!-- End Piwik Code -->
{% endif %}
{% endif %}

1
tests/sample/pictures/dir1/test1/flickr_jerquiaga_2394751088_cc-by-nc.md

@ -1,4 +1,3 @@
Title: WÎth spécial chÆracters
This is a funny description of this image

1
tests/sample/pictures/dir1/test2/CMB_Timeline300_no_WMAP.md

@ -1,2 +1 @@
Order: 03

2
tests/sample/pictures/nomedia/created/.nomedia

@ -1,2 +1,2 @@
should_be_ignored3.jpg
ignored
ignored

2
tests/test_image.py

@ -5,9 +5,9 @@ import pytest
from PIL import Image as PILImage
from sigal import init_logging
from sigal.gallery import Image
from sigal.image import (generate_image, generate_thumbnail, get_exif_data,
get_exif_tags, get_iptc_data, get_size, process_image)
from sigal.gallery import Image
from sigal.settings import Status, create_settings
CURRENT_DIR = os.path.dirname(__file__)

2
tests/test_video.py

@ -1,4 +1,5 @@
import os
from unittest.mock import patch
import pytest
@ -6,7 +7,6 @@ from sigal.gallery import Video
from sigal.settings import Status, create_settings
from sigal.video import (generate_thumbnail, generate_video, process_video,
video_size)
from unittest.mock import patch
CURRENT_DIR = os.path.dirname(__file__)
SRCDIR = os.path.join(CURRENT_DIR, 'sample', 'pictures')

Loading…
Cancel
Save