Browse Source

Make script compatible with both Python 2 and 3

Vasilij Schneidermann 10 năm trước cách đây
mục cha
commit
080266ac04
1 tập tin đã thay đổi với 24 bổ sung23 xóa
  1. 24 23
      doc/manual-src/en/mkapiref.py

+ 24 - 23
doc/manual-src/en/mkapiref.py

@@ -32,6 +32,7 @@
 # files in the program, then also delete it here.
 #
 # Generates API reference from C++ source code.
+from __future__ import print_function
 import re, sys, argparse
 
 class FunctionDoc:
@@ -41,10 +42,10 @@ class FunctionDoc:
         self.domain = domain
 
     def write(self, out):
-        print '''.. {}:: {}'''.format(self.domain, self.name)
-        print ''
+        print('''.. {}:: {}'''.format(self.domain, self.name))
+        print()
         for line in self.content:
-            print '    {}'.format(line)
+            print('    {}'.format(line))
 
 class TypedefDoc:
     def __init__(self, name, content):
@@ -52,10 +53,10 @@ class TypedefDoc:
         self.content = content
 
     def write(self, out):
-        print '''.. type:: {}'''.format(self.name)
-        print ''
+        print('''.. type:: {}'''.format(self.name))
+        print()
         for line in self.content:
-            print '    {}'.format(line)
+            print('    {}'.format(line))
 
 class StructDoc:
     def __init__(self, name, content, domain, members, member_domain):
@@ -67,19 +68,19 @@ class StructDoc:
 
     def write(self, out):
         if self.name:
-            print '''.. {}:: {}'''.format(self.domain, self.name)
-            print ''
+            print('''.. {}:: {}'''.format(self.domain, self.name))
+            print()
             for line in self.content:
-                print '    {}'.format(line)
-            print ''
+                print('    {}'.format(line))
+            print()
             for name, content in self.members:
-                print '''    .. {}:: {}'''.format(\
+                print('''    .. {}:: {}'''.format(\
                     'function' if name.endswith(')') else self.member_domain,
-                    name)
-                print ''
+                    name))
+                print()
                 for line in content:
-                    print '''        {}'''.format(line)
-            print ''
+                    print('''        {}'''.format(line))
+            print()
 
 class MacroDoc:
     def __init__(self, name, content):
@@ -87,10 +88,10 @@ class MacroDoc:
         self.content = content
 
     def write(self, out):
-        print '''.. macro:: {}'''.format(self.name)
-        print ''
+        print('''.. macro:: {}'''.format(self.name))
+        print()
         for line in self.content:
-            print '    {}'.format(line)
+            print('    {}'.format(line))
 
 def make_api_ref(infiles):
     macros = []
@@ -124,12 +125,12 @@ def make_api_ref(infiles):
     for title, docs in alldocs:
         if not docs:
             continue
-        print title
-        print '-'*len(title)
+        print(title)
+        print('-'*len(title))
         for doc in docs:
             doc.write(sys.stdout)
-            print ''
-        print ''
+            print()
+        print()
 
 def process_macro(infile):
     content = read_content(infile)
@@ -263,6 +264,6 @@ if __name__ == '__main__':
                         help='source file')
     args = parser.parse_args()
     if args.header:
-        print args.header.read()
+        print(args.header.read())
     for infile in args.files:
         make_api_ref(args.files)