semvec/pypi-packages huggingface dataset:
shotfirst 0.12.3
Monitor a number of directories for files and copy/move them
License: MIT
Requires Python: <4.0,>=3.10
Keywords: inotify, backup

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:

#.  Monitor the ``/tmp/inbox`` folder for files
#.  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)
#.  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.
#.  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``.

.. NOTE::
   Write permissions on the monitored volumes is only needed if you will be
   moving files instead of just copying

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