2018-11-26 13:45:32 +01:00
|
|
|
#!/usr/bin/env python2
|
2018-11-20 11:33:07 +01:00
|
|
|
|
|
|
|
from __future__ import print_function
|
|
|
|
import os
|
|
|
|
import ConfigParser
|
|
|
|
|
|
|
|
|
2018-11-25 14:59:02 +01:00
|
|
|
def generate_modules(abs_module, entities):
|
2018-11-20 11:33:07 +01:00
|
|
|
MODULE = os.path.split(abs_module)[-1]
|
|
|
|
module = MODULE.lower()
|
|
|
|
if module == "dummy":
|
|
|
|
return
|
|
|
|
|
|
|
|
with open( os.path.join(abs_module,'README.rst'), 'r' ) as f:
|
|
|
|
readme = f.read()
|
|
|
|
rst = [
|
|
|
|
".. _%s:"%(module), "",
|
|
|
|
".. program:: %s"%(module), "",
|
|
|
|
".. default-role:: option", "",
|
|
|
|
readme, "",
|
|
|
|
]
|
|
|
|
|
|
|
|
EZFIO = os.path.join(abs_module,'EZFIO.cfg')
|
|
|
|
if os.path.exists(EZFIO):
|
|
|
|
rst += [ "", "EZFIO parameters", "----------------", "" ]
|
|
|
|
config_file = ConfigParser.ConfigParser()
|
|
|
|
with open(EZFIO,'r') as f:
|
|
|
|
config_file.readfp(f)
|
|
|
|
for section in config_file.sections():
|
|
|
|
doc = config_file.get(section,"doc")
|
2018-11-26 13:45:32 +01:00
|
|
|
doc = " " + doc.replace("\n","\n\n ")+"\n"
|
2018-11-20 11:33:07 +01:00
|
|
|
try:
|
|
|
|
default = config_file.get(section,"default")
|
2018-11-26 13:45:32 +01:00
|
|
|
default = " " + "Default: %s\n"%default
|
2018-11-20 11:33:07 +01:00
|
|
|
except:
|
|
|
|
default = ""
|
|
|
|
rst += [ ".. option:: %s\n"%(section), doc, default ]
|
|
|
|
|
2018-11-25 14:59:02 +01:00
|
|
|
providers = []
|
|
|
|
subroutines = []
|
2018-11-26 13:45:32 +01:00
|
|
|
for k in sorted(entities.keys()):
|
2018-11-25 14:59:02 +01:00
|
|
|
e = entities[k]
|
2018-11-26 13:45:32 +01:00
|
|
|
if e["module"].lower() == module.lower():
|
2018-11-25 14:59:02 +01:00
|
|
|
if "/" not in e["file"] and e["file"] != "ezfio_interface.irp.f":
|
|
|
|
if e["type"] == 's':
|
|
|
|
subroutines.append(e)
|
|
|
|
elif e["type"] == 'p':
|
|
|
|
providers.append(e)
|
|
|
|
|
|
|
|
if providers:
|
|
|
|
rst += [ "", "Providers", "---------", "" ]
|
|
|
|
for p in providers:
|
|
|
|
rst += [ """
|
2018-11-26 13:45:32 +01:00
|
|
|
.. c:var:: %s
|
2018-11-25 14:59:02 +01:00
|
|
|
|
|
|
|
.. code:: text
|
|
|
|
|
|
|
|
%s
|
|
|
|
|
2018-11-26 13:45:32 +01:00
|
|
|
File: :file:`%s`
|
2018-11-25 14:59:02 +01:00
|
|
|
|
|
|
|
%s
|
|
|
|
|
|
|
|
|
|
|
|
""" % ( p["name"],
|
|
|
|
"\n ".join(p["decl"]),
|
|
|
|
p["file"],
|
2018-11-26 13:45:32 +01:00
|
|
|
" ".join(p["doc"]).replace("\n ","\n "),
|
|
|
|
) ]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if subroutines:
|
|
|
|
rst += [ "", "Subroutines / functions", "-----------------------", "" ]
|
|
|
|
for p in subroutines:
|
|
|
|
rst += [ """
|
|
|
|
|
|
|
|
.. c:function:: %s
|
|
|
|
|
|
|
|
.. code:: text
|
|
|
|
|
|
|
|
%s
|
|
|
|
|
|
|
|
File: :file:`%s`
|
|
|
|
|
|
|
|
%s
|
|
|
|
|
|
|
|
|
|
|
|
""" % ( p["name"],
|
|
|
|
"\n ".join(p["decl"]),
|
|
|
|
p["file"],
|
|
|
|
" ".join(p["doc"]).replace("\n ","\n "),
|
2018-11-25 14:59:02 +01:00
|
|
|
) ]
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-20 11:33:07 +01:00
|
|
|
rst_file = os.path.join('modules',module+".rst")
|
|
|
|
with open(rst_file,'w') as f:
|
|
|
|
f.write("\n".join(rst))
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-25 14:59:02 +01:00
|
|
|
def generate_providers(abs_module):
|
|
|
|
|
|
|
|
MODULE = os.path.split(abs_module)[-1]
|
|
|
|
module = MODULE.lower()
|
|
|
|
if module == "dummy":
|
|
|
|
return
|
|
|
|
|
|
|
|
files = {}
|
|
|
|
entities = {}
|
|
|
|
mandir = os.path.join(abs_module,'IRPF90_man')
|
|
|
|
if not os.path.exists(mandir):
|
|
|
|
return {}
|
|
|
|
|
|
|
|
for f in os.listdir(mandir):
|
|
|
|
|
|
|
|
filename = os.path.join(mandir,f)
|
|
|
|
if f not in files:
|
|
|
|
files[f] = 0
|
|
|
|
name = f.split('.')[0]
|
|
|
|
with open(filename, 'r') as f:
|
|
|
|
state = 0
|
|
|
|
entity = { "decl": [], "doc": [] ,
|
|
|
|
"name": name , "module": module }
|
|
|
|
for line in f.readlines():
|
|
|
|
line = line.strip()
|
|
|
|
if line.startswith(".SH Declaration"):
|
|
|
|
state = 1
|
|
|
|
continue
|
|
|
|
elif line.startswith(".nf"): continue
|
|
|
|
elif line.startswith(".ni"): continue
|
|
|
|
elif line.startswith(".P"): continue
|
|
|
|
if line.startswith(".SH Description"):
|
|
|
|
state = 2
|
|
|
|
continue
|
|
|
|
elif line.startswith(".SH File"):
|
|
|
|
state = 3
|
|
|
|
continue
|
|
|
|
if line.startswith(".SH Need"):
|
2018-11-26 13:45:32 +01:00
|
|
|
state = 0
|
|
|
|
continue
|
2018-11-25 14:59:02 +01:00
|
|
|
if line.startswith(".SH Instability"):
|
2018-11-26 13:45:32 +01:00
|
|
|
state = 0
|
|
|
|
continue
|
2018-11-25 14:59:02 +01:00
|
|
|
if line.startswith(".SH Call"):
|
2018-11-26 13:45:32 +01:00
|
|
|
state = 0
|
|
|
|
continue
|
2018-11-25 14:59:02 +01:00
|
|
|
|
|
|
|
if state == 1:
|
|
|
|
entity["decl"] += [ line ]
|
|
|
|
if line.startswith("subroutine") \
|
|
|
|
or line.startswith("function ") \
|
|
|
|
or " function " in line:
|
|
|
|
entity["type"] = 's'
|
|
|
|
else:
|
|
|
|
entity["type"] = 'p'
|
|
|
|
elif state == 2:
|
2018-11-26 13:45:32 +01:00
|
|
|
if line.startswith(".br"):
|
|
|
|
line = "\n"
|
2018-11-25 14:59:02 +01:00
|
|
|
entity["doc"] += [ line ]
|
|
|
|
elif state == 3:
|
|
|
|
if line.startswith(".br"):
|
|
|
|
continue
|
2018-11-26 13:45:32 +01:00
|
|
|
entity["file"] = line.split("/")[-1]
|
|
|
|
try:
|
|
|
|
entity["module"] = line.split("/")[-2]
|
|
|
|
except: pass
|
|
|
|
break
|
2018-11-25 14:59:02 +01:00
|
|
|
|
|
|
|
entities [ entity["name"] ] = entity
|
|
|
|
|
|
|
|
return entities
|
|
|
|
|
|
|
|
|
2018-11-26 13:45:32 +01:00
|
|
|
def generate_index(entities):
|
|
|
|
|
|
|
|
rst_file = os.path.join('programmers_guide','index_providers.rst')
|
|
|
|
|
|
|
|
with open(rst_file,'w') as f:
|
|
|
|
rst = [ "Index of Providers",
|
|
|
|
"------------------",
|
|
|
|
"" ]
|
|
|
|
|
|
|
|
for e in sorted(entities.keys()):
|
|
|
|
e = entities[e]
|
|
|
|
if e["type"] == 'p':
|
|
|
|
rst.append("* :c:data:`%s`" % (e["name"]))
|
|
|
|
|
|
|
|
rst += [ "",
|
|
|
|
"Index of Subroutines/Functions",
|
|
|
|
"------------------------------",
|
|
|
|
"" ]
|
|
|
|
|
|
|
|
for e in sorted(entities.keys()):
|
|
|
|
e = entities[e]
|
|
|
|
if e["type"] == 's':
|
|
|
|
rst.append("* :c:func:`%s`" % (e["name"]))
|
|
|
|
|
|
|
|
f.write("\n".join(rst))
|
|
|
|
|
2018-11-25 14:59:02 +01:00
|
|
|
|
|
|
|
|
2018-11-20 11:33:07 +01:00
|
|
|
def main():
|
|
|
|
|
|
|
|
if "QP_ROOT" in os.environ:
|
|
|
|
QP_ROOT=os.environ["QP_ROOT"]
|
|
|
|
else:
|
|
|
|
QP_ROOT="../../"
|
|
|
|
|
|
|
|
SRC = os.path.join(QP_ROOT, "src")
|
|
|
|
|
2018-11-25 14:59:02 +01:00
|
|
|
entities = {}
|
2018-11-20 11:33:07 +01:00
|
|
|
for abs_module in os.listdir(SRC):
|
|
|
|
abs_module = os.path.join(SRC,abs_module)
|
|
|
|
if os.path.exists( os.path.join(abs_module, "README.rst") ):
|
2018-11-25 14:59:02 +01:00
|
|
|
read_entities = generate_providers(abs_module)
|
|
|
|
if read_entities:
|
|
|
|
for k in read_entities:
|
|
|
|
entities[k] = read_entities[k]
|
2018-11-26 13:45:32 +01:00
|
|
|
|
|
|
|
for abs_module in os.listdir(SRC):
|
|
|
|
abs_module = os.path.join(SRC,abs_module)
|
|
|
|
if os.path.exists( os.path.join(abs_module, "README.rst") ):
|
|
|
|
generate_modules(abs_module,entities)
|
|
|
|
|
|
|
|
generate_index(entities)
|
2018-11-20 11:33:07 +01:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|
|
|
|
|