Skip to content

Commit

Permalink
Merge pull request #2 from waynew/develop
Browse files Browse the repository at this point in the history
Updated codes
  • Loading branch information
waynew committed Jan 15, 2014
2 parents 41af8cc + 3f870ac commit a8877ab
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 36 deletions.
44 changes: 39 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,46 @@ Draft in a Flask
:target: https://crate.io/packages/draftin-a-flask?version=latest


A simple Flask server that allows you to publish Pelican blags from http://draftin.com
A simple Flask server that allows you to publish Pelican blags from
http://draftin.com using
[WebHooks](https://draftin.com/documents/69898?token=5fjKKlZ0-AeBzqj_RAftAGdzRzl9VBfBHj5wpSWm_gU)

* Free software: BSD license
* Free software: MIT license
* Documentation: http://draftin-a-flask.rtfd.org.

Features
--------
Usage
-----

* TODO
::

$ pip install draftin_a_flask
$ env DIF_CONTENT=/path/to/content \
DIF_OUTPUT=/path/to/output \
DIF_PELICAN=/path/to/pelican_binary draftican
Listening at endpoint QRFky1tR0KqHGM3cJoitwEi8tTpknaNnMpNHHiTIm8
* Running on http://0.0.0.0:5678/
* Restarting with reloader
Listening at endpoint QRFky1tR0KqHGM3cJoitwEi8tTpknaNnMpNHHiTIm8
(Yes, it displays the print twice. I'm sure there's a way to get around it. If
it bothers you, I accept pull requests!)

Setup your WebHook from within Draft, and now you can write your blog posts in
Draft and easily publish.


Future Features
---------------

* Automatic uploads using rsync/ssh/file copy
* Settings provided in a file
* Improved error handling (e.g. missing title, etc.)


Known Bugs
----------

* If you're missing important fields (like title and date) it probably will
skip publishing that doc.
* Right now it doesn't use your pelican settings file. That'll probably be
the first thing I fix.
22 changes: 3 additions & 19 deletions draftin_a_flask/draftin_a_flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@
from flask import Flask, request

app = Flask(__name__)
OUTPUT = 'path/to/output'
CONTENT = 'path/to/input'
OUTPUT = os.environ.get('DIF_OUTPUT', 'path/to/output')
CONTENT = os.environ.get('DIF_CONTENT', 'path/to/input')
PELICAN = os.environ.get('DIF_PELICAN', '/path/to/pelican')
ROOT = os.path.dirname(os.path.abspath(__file__))
SECRET_FILE = os.path.join(ROOT, 's3kret.key')
PELICAN = '/path/to/pelican'
SSH_PORT = 22
SSH_USER = 'pelican'
SSH_HOST = 'localhost'
SSH_TARGET_DIR = '/path/to/blog-root/'


def setup():
Expand Down Expand Up @@ -53,18 +49,6 @@ def publish(name, content):
CONTENT,
'-o',
OUTPUT])
subprocess.check_output(['rsync',
'-e',
'"ssh -p {}"'.format(SSH_PORT),
'-P',
'-rvz',
'--delete',
os.path.join(OUTPUT, '*'),
'{}@{}:{}'.format(SSH_USER,
SSH_HOST,
SSH_TARGET_DIR),
])
# rsync -e "ssh -p $(SSH_PORT)" -P -rvz --delete $(OUTPUTDIR)/* $(SSH_USER)@$(SSH_HOST):$(SSH_TARGET_DIR)


if __name__ == "__main__":
Expand Down
2 changes: 2 additions & 0 deletions scripts/draftican
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python
from __future__ import print_function
from draftin_a_flask import draftin_a_flask
print('Listening at endpoint', draftin_a_flask.app.secret_key)
draftin_a_flask.app.run('0.0.0.0', port=5678, debug=True)
28 changes: 16 additions & 12 deletions tests/test_draftin_a_flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,25 +145,29 @@ def test_publish_should_actually_write_content():
shutil.rmtree(os.path.join(draftin_a_flask.ROOT, draftin_a_flask.CONTENT))


def test_passing_content_to_publish_should_call_pelican_and_rsync():
def test_passing_content_to_publish_should_call_pelican():
draftin_a_flask.subprocess = MagicMock()
expected = [call.check_output([draftin_a_flask.PELICAN,
draftin_a_flask.CONTENT,
'-o',
draftin_a_flask.OUTPUT]),
call.check_output(['rsync',
'-e',
'"ssh -p {}"'.format(draftin_a_flask.SSH_PORT),
'-P',
'-rvz',
'--delete',
os.path.join(draftin_a_flask.OUTPUT, '*'),
'{}@{}:{}'.format(draftin_a_flask.SSH_USER,
draftin_a_flask.SSH_HOST,
draftin_a_flask.SSH_TARGET_DIR),
])
]

draftin_a_flask.publish('a name', 'This is some content')

assert draftin_a_flask.subprocess.mock_calls == expected


def test_if_environment_values_are_set_they_should_be_preferred():
pelican = 'pelican or pelicant?'
content = "Well isn't that special?"
output = 'Buuuuuurrrrp' # get it?
os.environ['DIF_PELICAN'] = pelican
os.environ['DIF_CONTENT'] = content
os.environ['DIF_OUTPUT'] = output

reload(draftin_a_flask)

assert draftin_a_flask.PELICAN == pelican
assert draftin_a_flask.CONTENT == content
assert draftin_a_flask.OUTPUT == output

0 comments on commit a8877ab

Please sign in to comment.