docs: better docs, mv doxygen to sphinx
[vpp.git] / src / scripts / fts.py
index 2499704..f2b877f 100755 (executable)
@@ -2,6 +2,7 @@
 
 import sys
 import os
+import os.path
 import ipaddress
 import yaml
 from pprint import pprint
@@ -10,6 +11,7 @@ from jsonschema import validate, exceptions
 import argparse
 from subprocess import run, PIPE
 from io import StringIO
+import urllib.parse
 
 # VPP feature JSON schema
 schema = {
@@ -55,6 +57,7 @@ schema = {
     },
 }
 
+DEFAULT_REPO_LINK = "https://github.com/FDio/vpp/blob/master/"
 
 def filelist_from_git_status():
     filelist = []
@@ -99,10 +102,10 @@ class MarkDown():
         write = self.stream.write
         if type(o) is list:
             write('Maintainers: ' +
-                  ', '.join(f'{m}' for m in
+                  ', '.join('{m}'.format(m=m) for m in
                             o) + '  \n')
         else:
-            write(f'Maintainer: {o}  \n')
+            write('Maintainer: {o}  \n'.format(o=o))
 
     _dispatch['maintainer'] = print_maintainer
 
@@ -112,39 +115,37 @@ class MarkDown():
             indentstr = ' ' * indent
             if type(f) is dict:
                 for k, v in f.items():
-                    write(f'{indentstr}- {k}\n')
+                    write('{indentstr}- {k}\n'.format(indentstr=indentstr, k=k))
                     self.print_features(v, indent + 2)
             else:
-                write(f'{indentstr}- {f}\n')
+                write('{indentstr}- {f}\n'.format(indentstr=indentstr, f=f))
         write('\n')
     _dispatch['features'] = print_features
 
     def print_markdown_header(self, o):
         write = self.stream.write
-        write(f'## {o}\n')
-        version = version_from_git()
-        write(f'VPP version: {version}\n\n')
+        write('## {o}\n'.format(o=o))
     _dispatch['markdown_header'] = print_markdown_header
 
     def print_name(self, o):
         write = self.stream.write
-        write(f'### {o}\n')
+        write('### {o}\n'.format(o=o))
         self.toc.append(o)
     _dispatch['name'] = print_name
 
     def print_description(self, o):
         write = self.stream.write
-        write(f'\n{o}\n\n')
+        write('\n{o}\n\n'.format(o=o))
     _dispatch['description'] = print_description
 
     def print_state(self, o):
         write = self.stream.write
-        write(f'Feature maturity level: {o}  \n')
+        write('Feature maturity level: {o}  \n'.format(o=o))
     _dispatch['state'] = print_state
 
     def print_properties(self, o):
         write = self.stream.write
-        write(f'Supports: {" ".join(o)}  \n')
+        write('Supports: {s}  \n'.format(s=" ".join(o)))
     _dispatch['properties'] = print_properties
 
     def print_missing(self, o):
@@ -155,7 +156,7 @@ class MarkDown():
 
     def print_code(self, o):
         write = self.stream.write
-        write(f'Source Code: [{o}]({o}) \n')
+        write('Source Code: [{o}]({o}) \n'.format(o=o))
     _dispatch['code'] = print_code
 
     def print(self, t, o):
@@ -167,11 +168,11 @@ class MarkDown():
 
 def output_toc(toc, stream):
     write = stream.write
-    write('## VPP Feature list:\n')
+    write('# VPP Supported Features\n')
 
     for t in toc:
         ref = t.lower().replace(' ', '-')
-        write(f'[{t}](#{ref})  \n')
+        write('[{t}](#{ref})  \n'.format(t=t, ref=ref))
 
 def featuresort(k):
     return k[1]['name']
@@ -189,12 +190,12 @@ def featurelistsort(k):
     }
     return orderedfields[k[0]]
 
-def output_markdown(features, fields, notfields):
+def output_markdown(features, fields, notfields, repository_url):
     stream = StringIO()
     m = MarkDown(stream)
     m.print('markdown_header', 'Feature Details:')
     for path, featuredef in sorted(features.items(), key=featuresort):
-        codeurl = 'https://git.fd.io/vpp/tree/src/' + '/'.join(os.path.normpath(path).split('/')[1:-1])
+        codeurl = urllib.parse.urljoin(repository_url, os.path.dirname(path))
         featuredef['code'] = codeurl
         for k, v in sorted(featuredef.items(), key=featurelistsort):
             if notfields:
@@ -214,6 +215,9 @@ def main():
     parser = argparse.ArgumentParser(description='VPP Feature List.')
     parser.add_argument('--validate', dest='validate', action='store_true',
                         help='validate the FEATURE.yaml file')
+    parser.add_argument("--repolink", metavar="repolink", default=DEFAULT_REPO_LINK,
+                help="Link to public repository [%s]" %
+                     DEFAULT_REPO_LINK)
     parser.add_argument('--git-status', dest='git_status', action='store_true',
                         help='Get filelist from git status')
     parser.add_argument('--all', dest='all', action='store_true',
@@ -253,14 +257,14 @@ def main():
         try:
             validate(instance=cfg, schema=schema)
         except exceptions.ValidationError:
-            print(f'File does not validate: {featurefile}',
-                  file=sys.stderr)
+            print('File does not validate: {featurefile}' \
+                  .format(featurefile=featurefile), file=sys.stderr)
             raise
         features[featurefile] = cfg
 
     if args.markdown:
         stream = StringIO()
-        tocstream, stream = output_markdown(features, fields, notfields)
+        tocstream, stream = output_markdown(features, fields, notfields, args.repolink)
         print(tocstream.getvalue())
         print(stream.getvalue())
         stream.close()