-
Notifications
You must be signed in to change notification settings - Fork 2
/
manage.py
71 lines (61 loc) · 2.43 KB
/
manage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import os, shutil
from datetime import datetime
from app import create_app, freezer, pages
from flask.ext.script import Manager, Shell, prompt_bool
app = create_app(os.getenv('FLASK_CONFIG') or 'default')
manager = Manager(app)
@manager.command
def freeze(debug=False):
if debug:
freezer.run(debug=True)
freezer.freeze()
from config import basedir
pagesdir = os.path.join(basedir, 'app/pages')
@manager.command
def new_post(title):
"""
creates a new file in 'pages' directory with
indicated title, formatted yaml header, and opens
new file in sublime text editor
"""
yaml_header = 'title: %s' % title + '\n' +\
'date: %s' % datetime.now()[:-7] + '\n\n'
filename = title.replace(' ','_') + '.md'
filepath = os.path.join(pagesdir, filename)
with open(filepath, 'w') as thefile:
thefile.write(yaml_header)
os.system("subl %s" % filepath)
@manager.command
def publish(push=False, remote='origin', branch='master'):
"""adds blog post pages in root directory to git staging, commits,
and optionally those blog posts to github"""
freezer.freeze()
for page in pages:
os.system('git add %s' % page.path)
os.system('git add %s' % os.path.join(basedir,'app/pages/'))
for page in pages:
os.system('git add %s' % os.path.join(basedir, page.path))
os.system('git commit -m "publishing articles %s"' % ' '.join(
[page.path for page in pages]))
if push or prompt_bool(
"push from branch '%s' to remote '%s'? [y]" % (remote, branch)):
os.system('git push %s %s' % (remote, branch))
@manager.command
def remove(filename, push=False, remote='origin', branch='master'):
"""removes a blog post completely from the system"""
try:
filepath = os.path.join(basedir,'app/pages/%s.md'%filename)
os.remove(filepath)
os.system('git add -u %s' % filepath)
except OSError: print '"%s.md" does not exist or has been removed' % filename
try:
dirpath = os.path.join(basedir, filename)
shutil.rmtree(dirpath)
os.system('git add -u %s' % dirpath)
except OSError: print '"%s" does not exist or has been removed'
os.system('git commit -m "removed %s"'%filename)
if push or prompt_bool(
"push from branch '%s' to remote '%s'? [y]" % (remote, branch)):
os.system('git push %s %s' % (remote, branch))
if __name__ == '__main__':
manager.run()