Metadata-Version: 2.1
Name: shotfirst
Version: 0.12.2
Summary: Monitor a number of directories for files and copy/move them
Home-page: https://gitlab.com/kad/shotfirst
License: MIT
Keywords: inotify,backup
Author: Jorge Gallegos
Author-email: kad@blegh.net
Requires-Python: >=3.10,<4.0
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: System :: Archiving :: Backup
Classifier: Topic :: Utilities
Requires-Dist: enzyme (>=0.4.1,<0.5.0)
Requires-Dist: pdfrw (>=0.4,<0.5)
Requires-Dist: pillow (>=10.2.0,<11.0.0)
Requires-Dist: pyinotify (>=0.9.6,<0.10.0)
Description-Content-Type: text/x-rst

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

