Skip to content

Commit 883f6ec

Browse files
Added timestamp generation to README.md
1 parent 15ac5d6 commit 883f6ec

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

tools/generate-api-docs.py

+24-12
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import glob
1111
import argparse
1212
import urllib2
13+
import datetime
1314

1415
DEBUG = False
1516

@@ -19,6 +20,7 @@
1920
STARTMARKER = "[//]: <> (LUADOC-BEGIN:"
2021
ENDMARKER = "[//]: <> (LUADOC-END:"
2122
SUMMARYFILE = "SUMMARY.md"
23+
READMEFILE = "README.md"
2224
DOCBASE = "https://raw.githubusercontent.com/opentx/lua-reference-guide/master/"
2325

2426
def logDebug(txt):
@@ -47,7 +49,7 @@ def parseParameters(lines):
4749
def extractItems(item, doc):
4850
# find all items
4951
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)
5153
#logDebug("Found %d %s items in %s" % (len(items), item, repr(doc)))
5254

5355
# remove found items from the text
@@ -168,7 +170,7 @@ def addExamples(moduleName, funcName):
168170
# png files are linked as images
169171
doc += "![](%s)" % os.path.basename(fileName)
170172
doc += "\n\n"
171-
return doc
173+
return doc
172174

173175
def generateFunctionDoc(f):
174176
# f = (moduleName, funcName, funcDefinition, description, params, retvals, notices)
@@ -179,7 +181,7 @@ def generateFunctionDoc(f):
179181

180182
# description
181183
doc += "%s" % f[3]
182-
doc += "\n"
184+
doc += "\n"
183185

184186
# params
185187
doc += "#### Parameters\n\n"
@@ -220,6 +222,13 @@ def mkdir_p(path):
220222

221223
def insertSection(newContents, sectionName):
222224
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+
223232
newContents.append(" * [%s Functions](%s/%s_functions.md) %s%s)\n" % (sectionName.capitalize(), sectionName, sectionName, STARTMARKER, sectionName))
224233

225234
# look for an overview for the section and insert it if found
@@ -233,16 +242,16 @@ def insertSection(newContents, sectionName):
233242

234243
newContents[-1] = "%s %s%s)\n" % (newContents[-1].rstrip(),ENDMARKER, sectionName)
235244

236-
def processSummary():
245+
def replaceSections(fileName):
237246
newContents = []
238247
ignoreLine = False
239-
with open(SUMMARYFILE, "r") as summary:
240-
sumContents = summary.readlines()
248+
with open(fileName, "r") as data:
249+
contents = data.readlines()
241250

242-
for line in sumContents:
243-
if line.find(STARTMARKER) > 0:
251+
for line in contents:
252+
if line.find(STARTMARKER) >= 0:
244253
ignoreLine = True
245-
elif line.find(ENDMARKER) > 0:
254+
elif line.find(ENDMARKER) >= 0:
246255
# parse the section name and call insertSection
247256
sectionName = line.split(ENDMARKER)[1].split(")")[0]
248257
insertSection(newContents, sectionName)
@@ -251,10 +260,10 @@ def processSummary():
251260
if not ignoreLine:
252261
newContents.append(line)
253262

254-
with open(SUMMARYFILE, "w+") as out:
263+
with open(fileName, "w+") as out:
255264
for line in newContents:
256265
out.write(line)
257-
logInfo("generated %s" % SUMMARYFILE)
266+
logInfo("generated %s" % fileName)
258267

259268
# start of main program
260269

@@ -301,4 +310,7 @@ def processSummary():
301310
print(summary)
302311

303312
#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

Comments
 (0)