Initial commit.

main
oniboni 2021-06-08 20:51:53 +02:00
commit bf4b51dbbc
Signed by: oniboni
GPG Key ID: 11E6EDEFD248BB50
12 changed files with 100 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.mypy*

19
Dockerfile Normal file
View File

@ -0,0 +1,19 @@
FROM python:3.9
ARG UID=1000
ARG GID=1000
WORKDIR /src
RUN groupadd -g $GID -o builder && \
useradd -m -u $UID -g $GID -r builder && \
chown builder /src
USER builder
COPY . /src
VOLUME /input
VOLUME /output
ENTRYPOINT ./entrypoint.sh

8
entrypoint.sh Executable file
View File

@ -0,0 +1,8 @@
#!/usr/bin/env bash
input_dirs=""
for dir in $(find /input -type d); do
input_dirs="${input_dirs} ${dir}"
done
./meshmerge.py /output ${input_dirs}

57
meshmerge.py Executable file
View File

@ -0,0 +1,57 @@
#! /usr/bin/env python3
import argparse
import pathlib
import json
from typing import Dict, Any
meshviewer_file_name = 'meshviewer.json'
nodelist_file_name = 'nodelist.json'
def _merge_nodelist(output_file_path: pathlib.PosixPath, input_files: list[pathlib.PosixPath]):
output_content: Dict[str, Any] = {
'version': '',
'updated_at': '',
'nodes': list()
}
for input_file in input_files:
json_content = json.loads(input_file.read_bytes())
output_content['version'] = json_content['version']
output_content['updated_at'] = json_content['updated_at']
output_content['nodes'].extend(json_content['nodes'])
with open(output_file_path, 'w') as output_file:
output_file.write(json.dumps(output_content))
def _merge_meshviewer(output_file_path: pathlib.PosixPath, input_files: list[pathlib.PosixPath]):
output_content: Dict[str, Any] = {
'timestamp': '',
'nodes': list()
}
for input_file in input_files:
json_content = json.loads(input_file.read_bytes())
output_content['timestamp'] = json_content['timestamp']
output_content['nodes'].extend(json_content['nodes'])
with open(output_file_path, 'w') as output_file:
output_file.write(json.dumps(output_content))
def _merge_files(output_dir: pathlib.PosixPath, dirs: list[pathlib.PosixPath]):
_merge_nodelist(output_dir.joinpath('nodelist.json'),
[dir.joinpath('nodelist.json') for dir in dirs if dir.joinpath('nodelist.json').exists()])
_merge_meshviewer(output_dir.joinpath('meshviewer.json'),
[dir.joinpath('meshviewer.json') for dir in dirs if dir.joinpath('meshviewer.json').exists()])
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Mergetool for meshviewer JSON files.')
parser.add_argument('output_dir', type=pathlib.Path, help='Output directory to receive the merged files.')
parser.add_argument('input_dir', nargs='+', type=pathlib.Path,
help='Directory containing meshviewer.json and modelist.json.')
args = parser.parse_args()
_merge_files(args.output_dir, args.input_dir)

9
run_test.sh Normal file
View File

@ -0,0 +1,9 @@
#!/usr/bin/env bash
docker build --build-arg UID=$(id -u) \
--build-arg GID=$(id -g) \
-t meshmerger .
docker run -it \
-v /input:$(pwd)/tests/test_data:ro \
-v /output:$(pwd)/tests/out:rw meshmerger

0
tests/out/.gitkeep Normal file
View File

File diff suppressed because one or more lines are too long

1
tests/out/nodelist.json Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long