From 0402d4a57d0d89d1708d3f2914d19756da7e72ca Mon Sep 17 00:00:00 2001 From: Tobias Date: Wed, 27 Nov 2024 09:05:23 +0100 Subject: [PATCH 1/2] Introduce `remove_stopping_executable` with Docker This allows to run the code in isolation and from the command line. --- Dockerfile | 11 ++++++++ README.md | 11 +++++++- remove_stopping_executable.ts | 47 +++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 Dockerfile create mode 100755 remove_stopping_executable.ts diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..329af37 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +# Use an official Python runtime as a parent image +FROM python:3.9-slim + +# Set the working directory in the container +WORKDIR /usr/src/app + +# Copy the current directory contents into the container at /usr/src/app +COPY . . + +# Install any needed packages specified in requirements.txt +RUN pip install --no-cache-dir -r requirements.txt diff --git a/README.md b/README.md index 4a53b6d..4b9a0dc 100644 --- a/README.md +++ b/README.md @@ -3,4 +3,13 @@ Tools for gopro or other action cams for preparing upload to mapillary, kartaview, panoramx or other street image sites. - remove_stopping.py - Move images without GPS position in file and nearby photos (duplicated position) -- copy_from_gopro.py - Copy or move images from action cam to a folder with subfolder each date \ No newline at end of file +- copy_from_gopro.py - Copy or move images from action cam to a folder with subfolder each date + +## Standalone + +To run the Python script inside docker from the command line, you can [use Bun](https://bun.sh/docs/installation) like this: + +```sh +chmod +x remove_stopping_executable.ts +./remove_stopping_executable.ts PATH/TO/YOUR/FILES +``` diff --git a/remove_stopping_executable.ts b/remove_stopping_executable.ts new file mode 100755 index 0000000..fe2e6aa --- /dev/null +++ b/remove_stopping_executable.ts @@ -0,0 +1,47 @@ +#!/usr/bin/env bun + +const args = process.argv.slice(2); + +if (args.length !== 1) { + console.error("Usage: drag and drop a folder onto this script."); + process.exit(1); +} + +const folderPath = args[0]; +const dockerImage = "remove_stopping"; + +// Function to check if the Docker image exists +async function imageExists(image: string): Promise { + const { stdout } = await Bun.spawn(["docker", "images", "-q", image]); + const output = await new Response(stdout).text(); + return output.trim().length > 0; +} + +// Function to build the Docker image if it doesn't exist +async function buildImageIfNeeded(image: string): Promise { + const exists = await imageExists(image); + if (!exists) { + console.log(`Building Docker image: ${image}`); + const buildProcess = Bun.spawn(["docker", "build", "-t", image, "."]); + const status = await buildProcess.exited; + if (status !== 0) { + console.error("Failed to build Docker image."); + process.exit(status); + } + } +} + +async function run() { + await buildImageIfNeeded(dockerImage); + + const dockerCommand = `docker run -v "${folderPath}:/data" ${dockerImage} python ./remove_stopping.py -p /data -d 3`; + const runProcess = Bun.spawn(["sh", "-c", dockerCommand], { + stdout: "inherit", + stderr: "inherit", + }); + + const status = await runProcess.exited; + process.exit(status); +} + +run(); From a21a720269144b1dedbf734b2ff7ac6deb4189e8 Mon Sep 17 00:00:00 2001 From: Tobias Date: Sat, 30 Nov 2024 07:38:33 +0100 Subject: [PATCH 2/2] Debugging --- remove_stopping_executable.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/remove_stopping_executable.ts b/remove_stopping_executable.ts index fe2e6aa..69231a4 100755 --- a/remove_stopping_executable.ts +++ b/remove_stopping_executable.ts @@ -3,12 +3,11 @@ const args = process.argv.slice(2); if (args.length !== 1) { - console.error("Usage: drag and drop a folder onto this script."); + console.error("Usage: Call with `./remove_stopping_executable.ts PATH/TO/YOUR/FILES`."); process.exit(1); } const folderPath = args[0]; -const dockerImage = "remove_stopping"; // Function to check if the Docker image exists async function imageExists(image: string): Promise { @@ -32,9 +31,9 @@ async function buildImageIfNeeded(image: string): Promise { } async function run() { - await buildImageIfNeeded(dockerImage); + await buildImageIfNeeded("remove_stopping_image"); - const dockerCommand = `docker run -v "${folderPath}:/data" ${dockerImage} python ./remove_stopping.py -p /data -d 3`; + const dockerCommand = `docker run --rm -v "${folderPath}:/data" remove_stopping_image python ./remove_stopping.py -p /data -d 3`; const runProcess = Bun.spawn(["sh", "-c", dockerCommand], { stdout: "inherit", stderr: "inherit",