#!/bin/bash

ZIP_FILE="RemoteViewer.zip"

if [ -d $ZIP_FILE ]; then
	rm $ZIP_FILE
fi

# make sure all resources are generated before byte-compiling
make

python3 -m compileall .

for file in `find . -name \*\.pyc -print`; do
	echo $file
	if [[ $file =~ (.*)__pycache__/(.*)\.cpython-..(.*) ]]; then
		target="${BASH_REMATCH[1]}${BASH_REMATCH[2]}${BASH_REMATCH[3]}"
		cp $file $target
		rm $file
	else
		echo 'no match'
		exit 1
	fi
done

find . -name \*.pyc -print | xargs zip -@ $ZIP_FILE
