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

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Aug 26 07:12:47 PDT 2018


Author: lucadelu
Date: 2018-08-26 07:12:47 -0700 (Sun, 26 Aug 2018)
New Revision: 73184

Added:
   grass-addons/tools/check_examples_screenshots_tests.py
Removed:
   grass-addons/tools/check_examples_screenshots.py
Log:
check_examples_screenshots.py: added capability to check if modules have tests or not and renamed to check_examples_screenshots_tests.py

Deleted: grass-addons/tools/check_examples_screenshots.py
===================================================================
--- grass-addons/tools/check_examples_screenshots.py	2018-08-25 21:42:21 UTC (rev 73183)
+++ grass-addons/tools/check_examples_screenshots.py	2018-08-26 14:12:47 UTC (rev 73184)
@@ -1,98 +0,0 @@
-#!/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

Copied: grass-addons/tools/check_examples_screenshots_tests.py (from rev 73183, grass-addons/tools/check_examples_screenshots.py)
===================================================================
--- grass-addons/tools/check_examples_screenshots_tests.py	                        (rev 0)
+++ grass-addons/tools/check_examples_screenshots_tests.py	2018-08-26 14:12:47 UTC (rev 73184)
@@ -0,0 +1,122 @@
+#!/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 check_tests():
+    test = glob.glob('test*')
+    if len(test) >= 1:
+	for t in test:
+	    if os.path.isdir(t):
+		return False
+	return True
+    else:
+	return True
+
+def main(args):
+    """Main function"""
+    examples = []
+    screens = []
+    tests = []
+    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)
+            if args['t']:
+                if check_tests():
+		    tests.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['t']:
+		if not fnmatch.filter(dirnames, 'test*'):
+		    fil = os.path.split(root)[-1]
+		    right = is_module(fil)
+		    if right:
+			tests.append(fil)
+    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 args['t']:
+        tests.sort()
+        print("Modules missing tests:\n{lis}".format(lis='\n'.join(tests)))
+
+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('-t', dest='t', action='store_true',
+                        default=False, help='Check for tests')
+    parser.add_argument('-r', dest='r', action='store_true',
+                        default=False, help='Check recursively')
+    
+    args = parser.parse_args()
+    main(args.__dict__)



More information about the grass-commit mailing list