10
10
import glob
11
11
import argparse
12
12
import urllib2
13
+ import datetime
13
14
14
15
DEBUG = False
15
16
19
20
STARTMARKER = "[//]: <> (LUADOC-BEGIN:"
20
21
ENDMARKER = "[//]: <> (LUADOC-END:"
21
22
SUMMARYFILE = "SUMMARY.md"
23
+ READMEFILE = "README.md"
22
24
DOCBASE = "https://raw.githubusercontent.com/opentx/lua-reference-guide/master/"
23
25
24
26
def logDebug (txt ):
@@ -47,7 +49,7 @@ def parseParameters(lines):
47
49
def extractItems (item , doc ):
48
50
# find all items
49
51
pattern = "^@" + item + ".*?\n \s*\n "
50
- items = re .findall (pattern , doc , flags = re .DOTALL | re .MULTILINE )
52
+ items = re .findall (pattern , doc , flags = re .DOTALL | re .MULTILINE )
51
53
#logDebug("Found %d %s items in %s" % (len(items), item, repr(doc)))
52
54
53
55
# remove found items from the text
@@ -168,7 +170,7 @@ def addExamples(moduleName, funcName):
168
170
# png files are linked as images
169
171
doc += "" % os .path .basename (fileName )
170
172
doc += "\n \n "
171
- return doc
173
+ return doc
172
174
173
175
def generateFunctionDoc (f ):
174
176
# f = (moduleName, funcName, funcDefinition, description, params, retvals, notices)
@@ -179,7 +181,7 @@ def generateFunctionDoc(f):
179
181
180
182
# description
181
183
doc += "%s" % f [3 ]
182
- doc += "\n "
184
+ doc += "\n "
183
185
184
186
# params
185
187
doc += "#### Parameters\n \n "
@@ -220,6 +222,13 @@ def mkdir_p(path):
220
222
221
223
def insertSection (newContents , sectionName ):
222
224
logDebug ("Inserting section: %s" % sectionName )
225
+
226
+ if sectionName == "timestamp" :
227
+ newContents .append ("%s%s)\n " % (STARTMARKER , sectionName ))
228
+ newContents .append ("<div class=\" footer\" >last updated on %s</div>\n " % datetime .datetime .utcnow ().strftime ('%Y/%m/%d %H:%M:%S UTC' ))
229
+ newContents .append ("%s%s)\n " % (ENDMARKER , sectionName ))
230
+ return
231
+
223
232
newContents .append (" * [%s Functions](%s/%s_functions.md) %s%s)\n " % (sectionName .capitalize (), sectionName , sectionName , STARTMARKER , sectionName ))
224
233
225
234
# look for an overview for the section and insert it if found
@@ -233,16 +242,16 @@ def insertSection(newContents, sectionName):
233
242
234
243
newContents [- 1 ] = "%s %s%s)\n " % (newContents [- 1 ].rstrip (),ENDMARKER , sectionName )
235
244
236
- def processSummary ( ):
245
+ def replaceSections ( fileName ):
237
246
newContents = []
238
247
ignoreLine = False
239
- with open (SUMMARYFILE , "r" ) as summary :
240
- sumContents = summary .readlines ()
248
+ with open (fileName , "r" ) as data :
249
+ contents = data .readlines ()
241
250
242
- for line in sumContents :
243
- if line .find (STARTMARKER ) > 0 :
251
+ for line in contents :
252
+ if line .find (STARTMARKER ) >= 0 :
244
253
ignoreLine = True
245
- elif line .find (ENDMARKER ) > 0 :
254
+ elif line .find (ENDMARKER ) >= 0 :
246
255
# parse the section name and call insertSection
247
256
sectionName = line .split (ENDMARKER )[1 ].split (")" )[0 ]
248
257
insertSection (newContents , sectionName )
@@ -251,10 +260,10 @@ def processSummary():
251
260
if not ignoreLine :
252
261
newContents .append (line )
253
262
254
- with open (SUMMARYFILE , "w+" ) as out :
263
+ with open (fileName , "w+" ) as out :
255
264
for line in newContents :
256
265
out .write (line )
257
- logInfo ("generated %s" % SUMMARYFILE )
266
+ logInfo ("generated %s" % fileName )
258
267
259
268
# start of main program
260
269
@@ -301,4 +310,7 @@ def processSummary():
301
310
print (summary )
302
311
303
312
#now update SUMMARY.MD replacing the outdated sections
304
- processSummary ()
313
+ replaceSections (SUMMARYFILE )
314
+
315
+ #now update the timestamp in README.md
316
+ replaceSections (READMEFILE )
0 commit comments