Skip to content

Commit

Permalink
Merge branch 'release/0.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
datashaman committed Feb 8, 2017
2 parents c2a7fa2 + ba56323 commit e050c6b
Show file tree
Hide file tree
Showing 11 changed files with 165 additions and 30 deletions.
1 change: 1 addition & 0 deletions .env.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PUTIO_TOKEN=personal_oauth_token
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

application.db
application.log
config.py
supervisor.log
supervisor.log.*
tmp/
/config.py
/.env
/tmp/
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM debian:jessie-slim

RUN apt-get update \
&& apt-get install -y --no-install-recommends build-essential python2.7 python2.7-dev python-pip supervisor \
&& rm -rf /var/lib/apt/lists/*

RUN mkdir -p \
/app/logs /app/run \
/files/incomplete /files/downloads /files/torrents \
&& touch /app/run/app.db \
&& chown -R www-data /app/run /files

COPY app.py manage.py README.md requirements.txt /app/src/

RUN cd /app/src \
&& pip install -U pip \
&& pip install -r requirements.txt

COPY etc/supervisor /etc/supervisor/
COPY etc/config.py /app/src/

VOLUME ["/files/incomplete", "/files/downloads", "/files/torrents"]

EXPOSE 9001

CMD [ "supervisord", "-n", "-c", "/etc/supervisor/supervisord.conf", "--logfile", "/dev/stdout", "--logfile_maxbytes", "0" ]
29 changes: 28 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
TAG = datashaman/putio-automator

HOST_DOWNLOADS = `pwd`/tmp/downloads
HOST_INCOMPLETE = `pwd`/tmp/incomplete
HOST_TORRENTS = `pwd`/tmp/torrents

clean:
find . -name '*.pyc' -delete

restart-watcher:
sudo supervisorctl restart watcher
sudo supervisorctl restart watcher

docker-build:
docker build -t $(TAG) .

docker-run:
docker run --rm -it \
-e PUTIO_TOKEN=$(PUTIO_TOKEN) \
-p 9001:9001 \
-v $(HOST_INCOMPLETE):/files/incomplete \
-v $(HOST_DOWNLOADS):/files/downloads \
-v $(HOST_TORRENTS):/files/torrents \
$(TAG)

docker-bash:
docker run --rm -it \
-e PUTIO_TOKEN=$(PUTIO_TOKEN) \
-p 9001:9001 \
-v $(HOST_INCOMPLETE):/files/incomplete \
-v $(HOST_DOWNLOADS):/files/downloads \
-v $(HOST_TORRENTS):/files/torrents \
$(TAG) /bin/bash
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,31 @@ monitor that folder and download to the same folder used for post-processing in

To the people who installed the first version, apologies for the change in direction. It's a lot easier to rely on cron to schedule things than to fiddle with threads.

## Docker

Pull the latest image:

docker pull datashaman/putio-automator

Run the image:

docker run --rm -it \
-e PUTIO_TOKEN=oauth_token \
-p 9001:9001 \
-v /local/incomplete:/files/incomplete \
-v /local/downloads:/files/downloads \
-v /local/torrents:/files/torrents \
datashaman/putio-automator

Open http://localhost:9001 to manage processes. Drop torrent files in `/local/torrents`, and they'll be uploaded to Put.IO.

Start the `downloader` service to download the torrents to `/local/downloads`.

### TODO

- Runtime configure immediate or scheduled downloads.
- Fix logging (currently not visible).

## Setup

Create a virtualenv (recommended, assuming you're using virtualenvwrapper):
Expand Down
20 changes: 15 additions & 5 deletions config.py.dist
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import logging
import os

from dotenv import load_dotenv

BASE_DIR = os.path.abspath(os.path.dirname(__file__))

dotenv_path = os.path.join(BASE_DIR, '.env')
if os.path.isfile(dotenv_path):
load_dotenv(dotenv_path)

DATABASE = 'application.db'
LOG_FILENAME = None
LOG_LEVEL = logging.WARNING
PUTIO_TOKEN = 'TOKEN'
INCOMPLETE = '/somefolder/Incomplete'
TORRENTS = '/somefolder/Torrents'
DOWNLOADS = '/somefolder/Downloads'
LOG_LEVEL = os.getenv('LOG_LEVEL', 'WARNING')
PUTIO_TOKEN = os.getenv('PUTIO_TOKEN')

DOWNLOADS = '/data/downloads'
INCOMPLETE = '/data/incomplete'
TORRENTS = '/data/torrents'

UPNP_PORT = 42000
14 changes: 14 additions & 0 deletions etc/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import logging
import os

DATABASE = '/app/run/app.db'
LOG_FILENAME = None
LOG_LEVEL = os.getenv('LOG_LEVEL')

PUTIO_TOKEN = os.getenv('PUTIO_TOKEN')

DOWNLOADS = '/files/downloads'
INCOMPLETE = '/files/incomplete'
TORRENTS = '/files/torrents'

UPNP_PORT = 42000
19 changes: 0 additions & 19 deletions etc/supervisor.conf

This file was deleted.

21 changes: 21 additions & 0 deletions etc/supervisor/conf.d/app.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[program:watcher]
user=www-data
directory=/app/src
command=python manage.py torrents_watch
environment=PUTIO_TOKEN="%(ENV_PUTIO_TOKEN)s"
autostart=true
autorestart=false
redirect_stderr=true
stopasgroup=true
stdout_logfile=/app/logs/app.log

[program:downloader]
user=www-data
directory=/app/src
command=python manage.py files_download
environment=PUTIO_TOKEN="%(ENV_PUTIO_TOKEN)s"
autostart=false
autorestart=unexpected
redirect_stderr=true
stopasgroup=true
stdout_logfile=/app/logs/app.log
32 changes: 32 additions & 0 deletions etc/supervisor/supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[unix_http_server]
file=/app/run/supervisord.sock ; (the path to the socket file)
chmod=0700 ; sockef file mode (default 0700)

[inet_http_server]
port=9001

[supervisord]
nodaemon=true
loglevel=warn
logfile=/dev/stdout
logfile_maxbytes=0
pidfile=/app/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)

; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///app/run/supervisord.sock ; use a unix:// URL for a unix socket

; The [include] section can just contain the "files" setting. This
; setting can list multiple files (separated by whitespace or
; newlines). It can also contain wildcards. The filenames are
; interpreted as relative to this file. Included files *cannot*
; include files themselves.

[include]
files = /etc/supervisor/conf.d/*.conf

1 change: 0 additions & 1 deletion manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
level=app.config.get('LOG_LEVEL', logging.WARNING),
format='%(asctime)s | %(levelname)-8s | %(name)-12s | %(message)s')


def date_handler(obj):
if isinstance(obj, datetime.datetime) or isinstance(obj, datetime.date):
return obj.isoformat()
Expand Down

0 comments on commit e050c6b

Please sign in to comment.