This repository has been archived by the owner on Feb 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage.py
executable file
·53 lines (42 loc) · 1.75 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import yaml
from os import path as p
from pprint import pprint
from io import open
from flask import current_app as app
from flask.ext.script import Manager
from app import create_app
manager = Manager(create_app)
manager.add_option(
'-m', '--cfgmode', dest='config_mode', default='Development')
manager.add_option('-f', '--cfgfile', dest='config_file', type=p.abspath)
manager.main = manager.run # Needed to do `manage <command>` from the cli
def make_safe(name):
return name.replace(' ', '_').replace('&', 'and').replace('/', '-').lower()
def render_app(app, style, otype):
"""Renders the markup"""
with app.test_client() as c:
response = c.get('/render/%s/%s/' % (style, otype))
encoding = response.charset
return response.data.decode(encoding)
@manager.option('-i', '--info', help='the client info file, defaults to info.yml')
@manager.option('-s', '--style', help='the proposal style, defaults to development')
@manager.option('-t', '--otype', help='the output type, defaults to html')
def propose(info=None, style=None, otype=None):
"""Create Proposal"""
style = (style or app.config['STYLE'])
otype = (otype or app.config['TYPE'])
app.config['INFO_PATH'] = (info or app.config['INFO_PATH'])
stream = file(app.config['INFO_PATH'], 'r')
details = yaml.safe_load(stream)
client_name = details['short_company_name'] or details['client_name']
projec_name = details['project_name']
safe_name = make_safe('%s_%s' % (client_name, projec_name))
proposal_name = '%s_proposal.%s' % (safe_name, otype)
proposal_file = p.join(app.config['EXPORT_DIR'], proposal_name)
content = render_app(app, style, otype)
with open(proposal_file, 'w', encoding='utf-8') as f:
f.write(content)
if __name__ == '__main__':
manager.run()