Skip to main content

Monitor a number of directories for files and copy/move them

Project description

Overview

This is just a very simple inotify monitor for “dropbox” style folders. What it does is you give it a JSON config file and some directories and it will go and find all the files in the directories and execute shutil operations on them (by default copy2 which means the file is copied along with the metadata) to the configured location.

Installing

  • Option 1: Clone this repo and pip install . (bleeding edge)

  • Option 2: Run pip install shotfirst (released)

Configuration

With the following configuration file shotfirst.json:

{
  "image/jpeg, image/gif, image/png": {
    "mask": "%Y/%m/%d",
    "target": "/tmp/foo/pics",
    "handler": "shotfirst.handlers.exif_image_handler"
  },
  "video/webm": {
    "target": "/tmp/foo/videos",
    "operation": "move",
    "mask": "%Y/%m/%d",
    "handler": "shotfirst.handlers.video_handler"
  },
  "application/pdf": {
    "target": "/tmp/foo/docs",
    "operation": "movereplace",
    "handler": "shotfirst.handlers.pdf_handler",
    "mask": "%Y/%m"
  }
}

shotfirst shotfirst.json /tmp/inbox will:

  1. Monitor the /tmp/inbox folder for files

  2. Copy all GIF, JPEG, and PNG images found to a directory /tmp/foo/pics and use the EXIF metadata from the image to figure out the sub-folder structure (which is year/month/day)

  3. Move all the WebM videos to a directory named /tmp/foo/videos based on the video metadata, if available. Otherwise will fall back to the file system meta data.

  4. Copy all PDF files to a directory /tmp/foo/docs based on the PDF metadata if available. If the file was somehow imported previously, overwrite with the newly discovered file

Running in a container

There’s a published container image, to run you will have to mount your configuration file and your input and output folders, for example:

podman run --rm -it -v `pwd`/myconfig:/etc/shotfirst.json -v `pwd`/input:/inbox:rw -v `pwd`/output:/outbox:rw thekad/shotfirst:latest

And adjust your configuration appropriately to output the files to subdirectories under /outbox.

If you want to monitor multiple directories, you can mount them as volumes and then set the SDIRS environment variable, like this:

podman run --rm -it -v /opt/dropbox1:/inbox1 -v /opt/dropbox2:/inbox2 -e SDIRS="/inbox1 /inbox2" thekad/shotfirst:latest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

shotfirst-0.12.2.tar.gz (6.4 kB view hashes)

Uploaded Source

Built Distribution

shotfirst-0.12.2-py3-none-any.whl (7.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page