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
|
#! /usr/bin/python
import sys;
import os;
class Reader():
def __init__(self, suffix):
self.suffix = suffix;
#
def checkOk(self, pathname):
for suffix in self.suffix:
if pathname.endswith(suffix):
return True;
return False;
def read(self, pathname):
f = open(pathname, 'r');
input_string = f.read();
f.close();
return self.getOutputString(input_string);
def getOutputString(self, input_string):
return ''
#
class AsciidocReader(Reader):
def __init__(self):
Reader.__init__(self, ['.asciidoc',
'.adoc',
'.ascii',
]);
def getOutputString(self, input_string):
return input_string;
#
class InReader(Reader):
def __init__(self, suffix, start_string, end_string):
Reader.__init__(self, suffix);
self.start_string = start_string;
self. end_string = end_string;
def getOutputString(self, input_string):
start_index = 0;
ret = ''
while True:
start = input_string.find(self.start_string, start_index);
if start == -1:
break;
end = input_string.find(self.end_string,
start + len(self.start_string));
if end == -1:
break;
start_index = end + len(self.end_string);
ret += input_string[start + len(self.start_string) : end];
index = 0;
while index < len(ret):
if index == 0 or ret[index - 1] == "\n":
if ret[index] == ' ' or ret == "\t":
ret = ret[:index] + ret[index + 1:];
else:
index += 1;
else:
index += 1;
return ret;
#
class CppReader(InReader):
def __init__(self):
InReader.__init__(self,
['.c', '.cpp', '.h', '.hpp'],
'@asciidoc',
'@asciidoc-');
#
readers = [AsciidocReader(),
CppReader(),
];
if len(sys.argv) <= 1: readme = 'README.asciidoc';
else : readme = sys.argv[1];
readme_f = open(readme, 'w');
for (root, sub_folders, files) in os.walk('./'):
for reader in readers:
for filename in files:
path = os.path.join(root, filename);
if path == './' + readme:
continue;
if reader.checkOk(filename):
readme_f.write(reader.read(path));
files.remove(filename);
readme_f.close();
|