1
0

upload-sorter init

This commit is contained in:
= 2024-11-22 16:10:38 -05:00
parent 4c5f615ba1
commit 5ed9bbf1fd
4 changed files with 71 additions and 0 deletions

17
publish.sh Executable file
View File

@ -0,0 +1,17 @@
#!/bin/sh
REGISTRY=code.balsillie.net
REPOSITORY=containers
IMAGE=$1
TAG1=$(date +%Y-%m-%d_%H-%M-%S)
TAG2=latest
docker build \
-t $REGISTRY/$REPOSITORY/$IMAGE:$TAG1 \
-t $REGISTRY/$REPOSITORY/$IMAGE:$TAG2 \
-f ./$IMAGE/DOCKERFILE \
./$IMAGE
docker push $REGISTRY/$REPOSITORY/$IMAGE:$TAG1
docker push $REGISTRY/$REPOSITORY/$IMAGE:$TAG2

20
upload-sorter/DOCKERFILE Normal file
View File

@ -0,0 +1,20 @@
FROM python:3.12-slim
# Set the working directory
WORKDIR /app
# Copy the sort.py file to the working directory
COPY sort.py .
COPY requirements.txt .
# Ensure pip
RUN python -m ensurepip
# Upgrade pip
RUN pip install --upgrade pip
# Install requirements
RUN pip install -r requirements.txt
# Set the entry point to sort.py
ENTRYPOINT ["python", "/app/sort.py"]

View File

@ -0,0 +1 @@
pillow

33
upload-sorter/sort.py Normal file
View File

@ -0,0 +1,33 @@
#!/usr/bin/python
import time
import os
import signal
import sys
# Set the directories
watch_directories: list[str] = os.getenv('WATCH_DIR', '/sync').split(':')
recordings_directory: str = os.getenv('RECORDINGS_DIRECTORY', '/recordings')
photos_directory: str = os.getenv('PHOTOS_DIRECTORY', '/photos')
sleep_duration: int = 30
def main():
while True:
for directory in watch_directories:
sort_directory(directory)
print(f"Finished sorting directory {directory}")
print(f"Sleeping for {sleep_duration} seconds")
time.sleep(sleep_duration)
def sort_directory(directory):
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
def signal_handler(sig, frame):
print('Shutdown signal received. Exiting gracefully.')
sys.exit(0)
if __name__ == "__main__":
main()