diff --git a/Dockerfile b/Dockerfile index 2242bf8..a56df3b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ ENV FLASK_APP=/src/app ENV ROLES_DIR=/roles RUN DEBIAN_FRONTEND=noninteractive apt-get update && \ - apt install -y python3-pip sshpass git openssh-client libhdf5-dev libssl-dev libffi-dev && \ + apt install -y python3-pip sshpass git openssh-client libhdf5-dev libssl-dev libffi-dev imagemagick && \ rm -rf /var/lib/apt/lists/* && apt-get clean WORKDIR /src diff --git a/src/app.py b/src/app.py index f7b9c37..4c2c1e4 100644 --- a/src/app.py +++ b/src/app.py @@ -3,6 +3,8 @@ from flask import Flask, request import json import os +from PIL import Image +import subprocess import sys import yaml @@ -12,9 +14,23 @@ KEYS_DIR = "/keys" WORK_DIR = "/var/tmp" ROLES_DIR = os.environ.get("ROLES_DIR", "{}/roles".format(WORK_DIR)) +IMG_MINT_DIR = "{}/images".format(WORK_DIR) CONSTRUCTS = {} +def execute_command(command): + process = subprocess.Popen(command.split(), stdout=subprocess.PIPE) + output, error = process.communicate() + + if process.returncode > 0: + print('Executing command \"%s\" returned a non-zero status code %d' % (command, process.returncode)) + sys.exit(process.returncode) + + if error: + print(error.decode('utf-8')) + + return output.decode('utf-8') + def generate_setup(spec): with open("{dir}/{id}.yaml".format(dir=WORK_DIR, id=spec['id']), 'w') as f: for role in spec['setup']: @@ -50,6 +66,24 @@ def generate_inventory(spec): return { 'message': "{id} inventory generation completed successfully.".format(id=spec['id']) } +def generate_file_images(dir): + l = [os.path.join(dp, f) for dp, dn, fn in os.walk(os.path.expanduser(dir)) for f in fn] + number_files = len(l) + + new_im = Image.new('RGB', (800, 800)) + for x in range(0, number_files): + target = "{}/{}_{}.png".format(IMG_MINT_DIR, os.path.dirname(l[x]).split('/')[-1], os.path.basename(l[x])) + execute_command("convert -size 720x720 xc:white -font FreeMono -pointsize 12 -fill black -annotate +15+15 @{} {}".format(l[x], target)) + im = Image.open(target) + im.thumbnail((100, 100)) + + for i in range(0, 800, 100): + for j in range(0, 800, 100): + + new_im.paste(im, (i, j)) + + new_im.save('{}/out.png'.format(IMG_MINT_DIR)) + def load_construct_file(cid): data = {} with open("{dir}/{id}.yaml".format(dir=WORK_DIR, id=cid)) as file: diff --git a/src/requirements.txt b/src/requirements.txt index 042e87f..ffc36a3 100644 --- a/src/requirements.txt +++ b/src/requirements.txt @@ -1,3 +1,4 @@ Flask==2.0.2 ansible==4.8.0 -ansible_runner==2.0.3 \ No newline at end of file +ansible_runner==2.0.3 +pillow==8.4.0 diff --git a/version.txt b/version.txt index b82608c..8308b63 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -v0.1.0 +v0.1.1