forked from shibu/pyspec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
maintainance.py
executable file
·115 lines (88 loc) · 3.59 KB
/
maintainance.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import sys, os
sys.path.append(os.path.join(os.path.abspath("."), "sample", "rst2codeplex"))
document_source_list = ["usage-jp", "reference-jp", "legacy_test",
"tutorial", "usage", "reference", "dbc",
"why_is_pyspec_so_fat"]
def create_html_doc_from_rest():
if not os.path.exists("htmldoc"):
os.makedirs("htmldoc")
from docutils.core import publish_cmdline, default_description
description = ('Generates (X)HTML documents from standalone reStructuredText '
'sources. ' + default_description)
for source in document_source_list:
source_path = "doc/%s.txt" % source
output_path = "htmldoc/%s.html" % source
print "generating... ", output_path
publish_cmdline(writer_name='html', description=description,
argv=[source_path, output_path])
def create_codeplex_source_from_rest():
if not os.path.exists("codeplex"):
os.makedirs("codeplex")
from docutils.core import publish_cmdline, default_description
import rst2codeplex
description = ("Generates CodePlex's wiki source from standalone "
"reStructuredText sources. " + default_description)
for source in document_source_list:
source_path = "doc/%s.txt" % source
output_path = "codeplex/%s.txt" % source
print "generating... ", output_path
publish_cmdline(writer_name='codeplex', description=description,
writer=rst2codeplex.Writer(translator=rst2codeplex.CodePlexTranslator),
argv=[source_path, output_path, "--traceback"])
def append_change_log():
import time
changelog = """%s Shibukawa Yoshiki <yoshiki@shibu.jp>
\t*%s
""" % (time.ctime(), " ") + file("ChangeLog.txt").read()
file("ChangeLog.txt", "w").write(changelog)
def create_pydoc():
import sys, os
from epydoc.cli import cli
for x in "-v -o pyspec_epydoc --name pyspec --graph all --dotpath".split():
sys.argv.append(x)
sys.argv.append(r"C:\Program Files\ATT\Graphviz\bin\dot.exe")
sys.argv.append("pyspec")
cli()
def trailing_whitespace(path="."):
for name in os.listdir(path):
fullpath = os.path.abspath(os.path.join(path, name))
if os.path.isdir(fullpath):
trailing_whitespace(fullpath)
elif os.path.isfile(fullpath):
ext = os.path.splitext(name)[1]
if ext in (".py", ".pyw", ".txt", ".html", ".css", ".psproj",
".xrc", ".in") or name=="PKG-INFO":
trailing_whitespace_of_file(fullpath)
def trailing_whitespace_of_file(path):
contents = file(path, "rb").read()
contents = contents.replace("\r\n", "\n")
result = ["%s\n" % line.replace('\r', '').rstrip() for line in contents.splitlines()]
output = file(path, "wb")
output.writelines(result)
def main():
import sys
if "pydoc" in sys.argv:
create_pydoc()
elif "changelog" in sys.argv:
append_change_log()
elif "htmldoc" in sys.argv:
create_html_doc_from_rest()
elif "codeplex" in sys.argv:
create_codeplex_source_from_rest()
elif "whitespace" in sys.argv:
trailing_whitespace()
else:
print """maintainance tool for pyspec.
- maintainance.py pydoc
create pydoc document
- maintainance.py changelog
append change log
- maintainance.py htmldoc
create html document from reST document
- maintainance.py codeplex
create codeplex wiki from reST document
- maintainance.py whitespace
trailing whitespace(for git)
"""
if __name__ == "__main__":
main()