[glibmm/glibmm-2-58] docextract_to_xml.py: Add --exclude-file option



commit fd221ec5347935d4710e7953e9f71827aacee303
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date:   Fri Dec 28 16:59:16 2018 +0100

    docextract_to_xml.py: Add --exclude-file option
    
    * tools/defs_gen/docextract.py:
    * tools/defs_gen/docextract_to_xml.py: Add -x or --exclude-file option.
    Useful when generating gio_docs.xml or (in gtkmm-3) gtk_docs.xml.
    Remove the -d and -o options, which have been accepted, but have done
    nothing.

 tools/defs_gen/docextract.py        | 12 +++++++-----
 tools/defs_gen/docextract_to_xml.py | 35 ++++++++++++++++++++---------------
 2 files changed, 27 insertions(+), 20 deletions(-)
---
diff --git a/tools/defs_gen/docextract.py b/tools/defs_gen/docextract.py
index 1b18f56c..4428c803 100644
--- a/tools/defs_gen/docextract.py
+++ b/tools/defs_gen/docextract.py
@@ -457,21 +457,22 @@ def process_final_sections(fp, line, cur_doc):
 
     return line
 
-def parse_dir(dir, doc_dict):
+def parse_dir(dir, exclude_files, doc_dict):
     for file in os.listdir(dir):
         if file in ('.', '..'): continue
         path = os.path.join(dir, file)
+        if path in exclude_files: continue
         if os.path.isdir(path):
             if not no_recursion:
-                parse_dir(path, doc_dict)
+                parse_dir(path, exclude_files, doc_dict)
         elif len(file) > 2 and file[-2:] in ('.c', '.h'):
             sys.stderr.write("Processing " + path + '\n')
             parse_file(open(path, 'r'), doc_dict)
 
-def extract(dirs, doc_dict=None):
+def extract(dirs, exclude_files, doc_dict=None):
     if not doc_dict: doc_dict = {}
     for dir in dirs:
-        parse_dir(dir, doc_dict)
+        parse_dir(dir, exclude_files, doc_dict)
     return doc_dict
 
 tmpl_section_pattern = re.compile(r'^<!-- ##### (\w+) (\w+) ##### -->$')
@@ -509,12 +510,13 @@ def parse_tmpl(fp, doc_dict):
 
         line = fp.readline()
 
-def extract_tmpl(dirs, doc_dict=None):
+def extract_tmpl(dirs, exclude_files, doc_dict=None):
     if not doc_dict: doc_dict = {}
     for dir in dirs:
         for file in os.listdir(dir):
             if file in ('.', '..'): continue
             path = os.path.join(dir, file)
+            if path in exclude_files: continue
             if os.path.isdir(path):
                 continue
             if len(file) > 5 and file[-5:] == '.sgml':
diff --git a/tools/defs_gen/docextract_to_xml.py b/tools/defs_gen/docextract_to_xml.py
index a3221350..7c73cc0c 100755
--- a/tools/defs_gen/docextract_to_xml.py
+++ b/tools/defs_gen/docextract_to_xml.py
@@ -14,8 +14,10 @@ import docextract
 
 def usage():
     sys.stderr.write('usage: docextract_to_xml.py ' +
-        '[-s /src/dir | --source-dir=/src/dir] [-a | --with-annotations] ' +
-        '[-p | --with-properties] [-c | --with-sections] [-r | --no-recursion] ' +
+        '[-s /src/dir | --source-dir=/src/dir] ' +
+        '[-x /src/dir/file-to-exclude | --exclude-file=/src/dir/file-to-exclude] ' +
+        '[-a | --with-annotations] [-p | --with-properties] ' +
+        '[-c | --with-sections] [-r | --no-recursion] ' +
         '[-n | --no-since] [-i | --no-signals ] [-e | --no-enums ]\n')
     sys.exit(1)
 
@@ -61,15 +63,16 @@ def print_annotations(annotations):
 
 if __name__ == '__main__':
     try:
-        opts, args = getopt.getopt(sys.argv[1:], "d:s:o:apcrnie",
-                                   ["source-dir=", "with-annotations",
-                                    "with-properties", "with-sections",
-                                    "no-recursion", "no-since",
+        opts, args = getopt.getopt(sys.argv[1:], "s:x:apcrnie",
+                                   ["source-dir=", "exclude-file=",
+                                    "with-annotations", "with-properties",
+                                    "with-sections", "no-recursion", "no-since",
                                     "no-signals", "no-enums"])
     except getopt.error as e:
         sys.stderr.write('docextract_to_xml.py: %s\n' % e)
         usage()
     source_dirs = []
+    exclude_files = []
     with_annotations = False
     with_signals = True
     with_properties = False
@@ -78,25 +81,27 @@ if __name__ == '__main__':
     for opt, arg in opts:
         if opt in ('-s', '--source-dir'):
             source_dirs.append(arg)
-        if opt in ('-a', '--with-annotations'):
+        elif opt in ('-x', '--exclude-file'):
+            exclude_files.append(arg)
+        elif opt in ('-a', '--with-annotations'):
             with_annotations = True
-        if opt in ('-p', '--with-properties'):
+        elif opt in ('-p', '--with-properties'):
             with_properties = True
-        if opt in ('-c', '--with-sections'):
+        elif opt in ('-c', '--with-sections'):
             with_sections = True
-        if opt in ('-r', '--no-recursion'):
+        elif opt in ('-r', '--no-recursion'):
             docextract.no_recursion = True
-        if opt in ('-n', '--no-since'):
+        elif opt in ('-n', '--no-since'):
             docextract.no_since = True
-        if opt in ('-i', '--no-signals'):
+        elif opt in ('-i', '--no-signals'):
             with_signals = False
-        if opt in ('-e', '--no-enums'):
+        elif opt in ('-e', '--no-enums'):
             with_enums = False
     if len(args) != 0:
         usage()
 
-    docs = docextract.extract(source_dirs);
-    docextract.extract_tmpl(source_dirs, docs); #Try the tmpl sgml files too.
+    docs = docextract.extract(source_dirs, exclude_files);
+    docextract.extract_tmpl(source_dirs, exclude_files, docs); #Try the tmpl sgml files too.
 
     # print d.docs
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]