[GRASS-SVN] r71568 - grass-addons/tools

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Oct 20 05:02:59 PDT 2017


Author: lucadelu
Date: 2017-10-20 05:02:59 -0700 (Fri, 20 Oct 2017)
New Revision: 71568

Added:
   grass-addons/tools/check_examples_screenshots.py
Log:
added script to check modules without example or screenshot

Added: grass-addons/tools/check_examples_screenshots.py
===================================================================
--- grass-addons/tools/check_examples_screenshots.py	                        (rev 0)
+++ grass-addons/tools/check_examples_screenshots.py	2017-10-20 12:02:59 UTC (rev 71568)
@@ -0,0 +1,98 @@
+#!/usr/bin/env python2
+# -*- coding: utf-8 -*-
+"""
+Created on Fri Oct 20 10:29:51 2017
+
+ at author: lucadelu
+"""
+
+import argparse
+import glob
+import os
+import fnmatch
+
+modules = ['d.', 'db.', 'g.', 'i.', 'm.', 'r3.', 'r.', 't.', 'v.', 'wxGUI.']
+
+def is_module(name):
+    """Check if html page is refering to a module or not"""
+    right = False
+    for mod in modules:
+        if name.startswith(mod):
+            right = True
+    return right
+
+def check_file(fil, example=False, screen=False):
+    """check if HTML file contain EXAMPLE word and more then one <img> tag
+    (one <img> tag is in all pages since there is GRASS logo)
+    """
+    f = open(fil)
+    lines = f.read()
+    output = [False, False]
+    if example:
+        if 'EXAMPLE' in lines:
+            output[0] = True
+    else:
+        output[0] = True
+    if screen:
+        if lines.count('<img') > 1:
+            output[1] = True
+    else:
+        output[1] = True
+    return output
+
+def main(args):
+    """Main function"""
+    examples = []
+    screens = []
+    if not args['r']:
+        files = glob.glob('*.html')
+        for fil in files:
+            name = fil.replace('.html','')
+            right = is_module(fil)
+            if not right:
+                continue
+            res = check_file(fil, args['e'], args['s'])
+            if not res[0]:
+                examples.append(name)
+            if not res[1]:
+                screens.append(name)
+    else:
+        for root, dirnames, filenames in os.walk('.'):
+            for name in fnmatch.filter(filenames, '*.html'):
+                right = is_module(name)
+                if not right:
+                    continue
+                fil = os.path.join(root, name)
+                res = check_file(fil, args['e'], args['s'])
+                if not res[0]:
+                    examples.append(name)
+                if not res[1]:
+                    screens.append(name)
+    if args['e']:
+        examples.sort()
+        print("Modules missing examples:\n{lis}".format(lis='\n'.join(examples)))
+    if args['s']:
+        screens.sort()
+        print("Modules missing screenshots:\n{lis}".format(lis='\n'.join(screens)))
+            
+
+if __name__ == "__main__":
+
+    parser = argparse.ArgumentParser(description='Check modules without '
+                                     ' examples or screenshots',
+                                     formatter_class=argparse.RawTextHelpFormatter,
+                                     epilog="Run into docs/html"
+                                     " folder to get modules without examples:"
+                                     "\n check_examples_screenshots.py -e"
+                                     "\nRun into grass7 folder in grass-addons"
+                                     " to get modules without screenshots:"
+                                     "\n check_examples_screenshots.py -s -r")
+    parser.add_argument('-e', dest='e', action='store_true',
+                        default=False, help='Check for examples')
+    parser.add_argument('-s', dest='s', action='store_true',
+                        default=False, help='Check for screenshots')
+    parser.add_argument('-r', dest='r', action='store_true',
+                        default=False, help='Check recursively')
+    
+    args = parser.parse_args()
+    main(args.__dict__)
\ No newline at end of file


Property changes on: grass-addons/tools/check_examples_screenshots.py
___________________________________________________________________
Added: svn:mime-type
   + text/x-python
Added: svn:eol-style
   + native



More information about the grass-commit mailing list