Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce remove_stopping_executable with Docker #1

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
- 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
```
46 changes: 46 additions & 0 deletions remove_stopping_executable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bun

const args = process.argv.slice(2);

if (args.length !== 1) {
console.error("Usage: Call with `./remove_stopping_executable.ts PATH/TO/YOUR/FILES`.");
process.exit(1);
}

const folderPath = args[0];

// Function to check if the Docker image exists
async function imageExists(image: string): Promise<boolean> {
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<void> {
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("remove_stopping_image");

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",
});

const status = await runProcess.exited;
process.exit(status);
}

run();