\n"
else:
short += "Query:\n\n"
longText += "Query:\n\n"
continue # skip this line - it is only here for this.
elif line.startswith("@B"): # bind values part
short += "
\nBind Values:\n\n"
longText += "
\nBind Values:\n\n"
blockCount = 0
aqlState = AQL_STATE_BINDV
continue # skip this line - it is only here for this.
elif line.startswith("@R"): # result part
shortable = True
if blockType == "EXPLAIN":
longText += "
\nExplain output:\n\n"
else:
longText += "
\nQuery results:\n\n"
blockCount = 0
aqlState = AQL_STATE_RESULT
continue # skip this line - it is only here for this.
if aqlState == AQL_STATE_QUERY or aqlState == AQL_STATE_BINDV:
short = short + line
shortLines += 1
blockCount += 1
longText += line
longLines += 1
if lastline != None:
short += lastline
shortLines += 1
infile.close()
if longLines - shortLines < 5:
shortable = False
# python3: urllib.parse.quote_plus
# write example
fh.write(unicode("\n"))
utag = urllib.quote_plus(tag) + '_container'
ustr = u"\uE9CB"
anchor = u""
longTag = "%s_long" % tag
shortTag = "%s_short" % tag
shortToggle = "$('#%s').hide(); $('#%s').show();" % (shortTag, longTag)
longToggle = "$('#%s').hide(); $('#%s').show(); window.location.hash='%s';" % (longTag, shortTag, utag)
fh.write(unicode("\n" % utag))
fh.write(unicode(anchor))
if shortable:
fh.write(unicode("
\n" % longTag))
else:
fh.write(unicode("
\n" % longTag))
if blockType != "AQL" and blockType != "EXPLAIN":
fh.write(unicode("
\n"))
fh.write(unicode("%s" % longText))
fh.write(unicode("
\n"))
if shortable:
hideText=""
if blockType == "arangosh":
hideText = u"Hide execution results"
elif blockType == "curl":
hideText = u"Hide response body"
elif blockType == "AQL":
hideText = u"Hide query result"
elif blockType == "EXPLAIN":
hideText = u"Hide explain output"
else:
hideText = u"Hide"
fh.write(unicode('
%s
' % (
utag,
longToggle,
hideText
)))
fh.write(unicode("
\n"))
if shortable:
fh.write(unicode("
\n" % (shortTag, shortToggle)))
if blockType != "AQL" and blockType != "EXPLAIN":
fh.write(unicode("
\n"))
fh.write(unicode("%s" % short))
if blockType == "arangosh":
fh.write(unicode("
Show execution results
\n"))
elif blockType == "curl":
fh.write(unicode("
Show response body
\n"))
elif blockType == "AQL":
fh.write(unicode("
Show query result
\n"))
elif blockType == "EXPLAIN":
fh.write(unicode("
Show explain output
\n"))
else:
fh.write(unicode("
Show
\n"))
fh.write(unicode("
\n"))
fh.write(unicode("
\n"))
fh.write(unicode("\n"))
def fetch_comments(dirpath, forceDokuBlockContent):
""" Fetches comments from files and writes to a file in required format.
"""
global fullSuccess
global validExtensions
comments_filename = "allComments.txt"
fh = io.open(comments_filename, "a", encoding="utf-8", newline="")
shouldIgnoreLine = False
for root, directories, files in os.walk(dirpath):
for filename in files:
if filename.endswith(validExtensions) and (filename.find("#") < 0):
filepath = os.path.join(root, filename)
file_comments = file_content(filepath, forceDokuBlockContent)
for comment in file_comments:
fh.write(unicode("\n\n" % filepath))
explain = False
for _com in comment:
if "@EXPLAIN{TRUE}" in _com:
explain = True
for _com in comment:
_text = re.sub(r"//(/)+\s*\n", "
\n", _com) # place in temporary brs...
_text = re.sub(r"///+(\s+\s+)([-\*\d])", r" \2", _text)
_text = re.sub(r"///\s", "", _text)
_text = _text.strip("\n")
if _text:
if not shouldIgnoreLine:
if ("@startDocuBlock" in _text) or \
("@endDocuBlock" in _text):
fh.write(unicode("%s\n\n" % _text))
elif ("@EXAMPLE_ARANGOSH_OUTPUT" in _text or \
"@EXAMPLE_ARANGOSH_RUN" in _text or \
"@EXAMPLE_AQL" in _text):
blockType=""
if "@EXAMPLE_ARANGOSH_OUTPUT" in _text:
blockType = "arangosh"
elif "@EXAMPLE_ARANGOSH_RUN" in _text:
blockType = "curl"
elif "@EXAMPLE_AQL" in _text:
if explain:
blockType = "EXPLAIN"
else:
blockType = "AQL"
shouldIgnoreLine = True
try:
_filename = re.search("{(.*)}", _text).group(1)
except Exception as x:
print "failed to match file name in %s while parsing %s " % (_text, filepath)
raise x
dirpath = os.path.abspath(os.path.join(os.path.dirname( __file__ ), os.pardir, "Examples", _filename + ".generated"))
if os.path.isfile(dirpath):
example_content(dirpath, fh, _filename, blockType, filepath)
else:
fullSuccess = False
print "Could not find the generated example for " + _filename + " found in " + filepath
else:
fh.write(unicode("%s\n" % _text))
elif ("@END_EXAMPLE_ARANGOSH_OUTPUT" in _text or \
"@END_EXAMPLE_ARANGOSH_RUN" in _text or \
"@END_EXAMPLE_AQL" in _text):
shouldIgnoreLine = False
else:
fh.write(unicode("\n"))
fh.close()
if __name__ == "__main__":
errorsFile = io.open("../../lib/Basics/errors.dat", "r", encoding="utf-8", newline=None)
commentsFile = io.open("allComments.txt", "w", encoding="utf-8", newline="")
commentsFile.write(unicode("@startDocuBlock errorCodes \n"))
for line in errorsFile:
commentsFile.write(unicode(line + "\n"))
commentsFile.write(unicode("@endDocuBlock \n"))
commentsFile.close()
errorsFile.close()
for i in searchPaths:
print "Searching for docublocks in " + i[0] + ": "
dirpath = os.path.abspath(os.path.join(os.path.dirname( __file__ ), os.pardir,"ArangoDB/../../"+i[0]))
fetch_comments(dirpath, i[1])
os.path.abspath(os.path.join(os.path.dirname( __file__ ), '..', 'templates'))
if not fullSuccess:
sys.exit(1)