-
Notifications
You must be signed in to change notification settings - Fork 15
/
makemd.py
executable file
·102 lines (70 loc) · 2.88 KB
/
makemd.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""Make markdown file versions of issue-pack user story files
LICENSE
ComplianceLib SystemCompliance is a class for representing compliance as code for an information system.
Copyright (C) 2016 GovReady PBC.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Example python CLI
------------------
python makemd.py
"""
__author__ = "Greg Elin ([email protected])"
__version__ = "$Revision: 0.1.0 $"
__date__ = "$Date: 2017/03/14 20:13:00 $"
__copyright__ = "Copyright (c) 2017 GovReady PBC"
__license__ = "GNU General Public License v3 (GPLv3)"
import os
import json
import yaml
import re
import sys
import glob
if sys.version_info >= (3, 0):
from urllib.parse import urlparse
from urllib.request import urlopen
if sys.version_info < (3, 0) and sys.version_info >= (2, 5):
from urlparse import urlparse
from urllib2 import urlopen
print ("Generating markdown files from source Issue Pack YAML files")
# read all yaml files
path = "./"
# for each yaml file
for yaml_file in glob.glob( os.path.join(path, '*.yaml') ):
# ignore template.yaml
if yaml_file == "{}template.yaml".format(path):
continue
# log file working on
print("processing {}".format(yaml_file.strip(".yaml")))
# read yaml file
yaml_stories = yaml.load(open(yaml_file,"r"))
# start document with name of issue pack
md_text = "# {}\n\n".format(yaml_stories['name'])
# append reminder this file is generated by a script and not to edit
md_text += "This file is generated by a script. To modify, update source file [{}]({}).\n\n".format(yaml_file, yaml_file)
# for each story in yaml file
for issue in yaml_stories['issues']:
# append title as markdown to md_text
# print(issue['title'][0:30])
md_text += "## {}\n".format(issue['title'])
# append body as markdown to md_text
# print(issue['body'][0:30])
md_text += "{}".format(issue['body'].encode('utf-8','ignore'))
# append labels
if 'labels' in issue:
md_text += "\n*Labels:*\n"
for label in issue['labels']:
md_text += "* {}\n".format(label.encode('utf-8','ignore'))
# write md_text to file
with open("{}{}.md".format(path, yaml_file.strip(".yaml")), "w") as md_file:
md_file.write(md_text)
print("Whew! Done")