Détecte si un thème est déjà présent

This commit is contained in:
Simon
2023-05-18 12:30:10 +00:00
parent 9d6ddf6e25
commit d541628920
12 changed files with 146 additions and 9 deletions

View File

@@ -1,18 +1,23 @@
const fs = require("fs");
const path = require("path");
const iptc = require("node-iptc");
const { exit } = require("process");
// find all images
// Fetch envs to target the right folder
const slug = process.env["PACKAGE_NAME"];
const root = process.env["ENTRY_FOLDER"];
if (!slug || !root) exit(1);
let workingDirectory = path.join(root, slug);
// extract metadata from them
fs.readdir(workingDirectory, (err, files) => {
if (err) { throw err };
if (err) { throw err }; // If IO error, exit with an error message
// construct a JSON file
// If there is already a theme.json silentely exit and let mocha running afterwards
if (files.find(file => path.extname(file) == '.json')) exit(0);
// construct a JSON object
let theme = new Object();
theme.dayImageList = [];
theme.nightImageList = [];
@@ -63,7 +68,7 @@ fs.readdir(workingDirectory, (err, files) => {
break;
}
});
// make it the theme.json
fs.writeFileSync(path.join(workingDirectory, 'theme.json'), JSON.stringify(theme));
});

View File

@@ -7,7 +7,7 @@ import os
import pytest
def validate_brightness_image(working_path, theme_config, high_light, image_list, brightness_way):
def _validate_brightness_image(working_path, theme_config, high_light, image_list, brightness_way):
image_pattern = theme_config.get("imageFilename")
image_filenames = {}.fromkeys(glob.glob(str(Path(working_path, image_pattern))))
# generate an image statistics for each images
@@ -15,6 +15,7 @@ def validate_brightness_image(working_path, theme_config, high_light, image_list
this_image = Image.open(an_imagefile).convert("L")
this_image_stats = ImageStat.Stat(this_image)
image_filenames[an_imagefile] = this_image_stats.mean[0]
#print(f'{an_imagefile} : {image_filenames[an_imagefile]}')
# get the brightest observed image from the list
if high_light == "dayHighlight":
@@ -54,11 +55,11 @@ def manifest(working_path):
def test_brightest_image(working_path, manifest):
validate_brightness_image(working_path, manifest, "dayHighlight", "dayImageList", "Brightest")
_validate_brightness_image(working_path, manifest, "dayHighlight", "dayImageList", "Brightest")
def test_darkest_image(working_path, manifest):
validate_brightness_image(working_path, manifest, "nightHighlight", "nightImageList", "Darkest")
_validate_brightness_image(working_path, manifest, "nightHighlight", "nightImageList", "Darkest")
def test_image_size(working_path, manifest):