[GRASS-SVN] r65757 - in grass/trunk/scripts/g.extension: . testsuite testsuite/data testsuite/data/sample_modules testsuite/data/sample_modules/r.plus.example

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jul 21 08:57:14 PDT 2015


Author: wenzeslaus
Date: 2015-07-21 08:57:14 -0700 (Tue, 21 Jul 2015)
New Revision: 65757

Added:
   grass/trunk/scripts/g.extension/testsuite/data/sample_modules/
   grass/trunk/scripts/g.extension/testsuite/data/sample_modules/r.plus.example.tar.gz
   grass/trunk/scripts/g.extension/testsuite/data/sample_modules/r.plus.example.zip
   grass/trunk/scripts/g.extension/testsuite/data/sample_modules/r.plus.example/
   grass/trunk/scripts/g.extension/testsuite/data/sample_modules/r.plus.example/Makefile
   grass/trunk/scripts/g.extension/testsuite/data/sample_modules/r.plus.example/r.plus.example.html
   grass/trunk/scripts/g.extension/testsuite/data/sample_modules/r.plus.example/r.plus.example.py
   grass/trunk/scripts/g.extension/testsuite/data/sample_modules/r.plus.example_sep.tar.gz
Modified:
   grass/trunk/scripts/g.extension/g.extension.py
   grass/trunk/scripts/g.extension/testsuite/test_addons_modules.py
   grass/trunk/scripts/g.extension/testsuite/test_addons_toolboxes.py
Log:
g.extension: support tar without root directory, fix install prefix for relative paths, add tests

Modified: grass/trunk/scripts/g.extension/g.extension.py
===================================================================
--- grass/trunk/scripts/g.extension/g.extension.py	2015-07-21 14:00:53 UTC (rev 65756)
+++ grass/trunk/scripts/g.extension/g.extension.py	2015-07-21 15:57:14 UTC (rev 65757)
@@ -919,13 +919,14 @@
     if len(files) == 1:
         shutil.copytree(os.path.join(extract_dir, files[0]), target_dir)
     else:
+        os.mkdir(target_dir)
         for file_name in files:
             actual_file = os.path.join(extract_dir, file_name)
             if os.path.isdir(actual_file):
                 shutil.copytree(actual_file,
                                 os.path.join(target_dir, file_name))
             else:
-                shutil.copy(actual_file, target_dir)
+                shutil.copy(actual_file, os.path.join(target_dir, file_name))
 
 
 # Original copyright and license of the original version of the CRLF function
@@ -1022,6 +1023,7 @@
         grass.fatal(_("Unknown extension (addon) source type '{}'."
                       " Please report this to the grass-user mailing list.")
                     .format(source))
+    assert os.path.isdir(directory)
 
 
 def install_extension_std_platforms(name, source, url):
@@ -1372,7 +1374,7 @@
     # together with file names
     if not path.endswith(os.path.sep):
         path = path + os.path.sep
-    return path
+    return os.path.abspath(path)  # make likes absolute paths
 
 
 def resolve_xmlurl_prefix(url):
@@ -1447,7 +1449,7 @@
                             _("Not using {service} as known hosting service"
                               " because the URL ends with '{suffix}'")
                                 .format(service=key, suffix=suffix))
-                        return None
+                        return None, None
     if match:
         if not actual_start:
             actual_start = match['url_start']
@@ -1460,7 +1462,7 @@
                         .format(url))
         return 'remote_zip', url
     else:
-        return None
+        return None, None
 
 
 def resolve_source_code(url):
@@ -1529,14 +1531,14 @@
         return 'dir', os.path.abspath(url)
     elif os.path.exists(url):
         if url.endswith('.zip'):
-                return 'zip', os.path.abspath(url)
+            return 'zip', os.path.abspath(url)
         for suffix in extract_tar.supported_formats:
             if url.endswith('.' + suffix):
                 return suffix, os.path.abspath(url)
     else:
-        result = resolve_known_host_service(url)
-        if result:
-            return result
+        source, url = resolve_known_host_service(url)
+        if source:
+            return source, url
         # we allow URL to end with =zip or ?zip and not only .zip
         # unfortunately format=zip&version=89612 would require something else
         # special option to force the source type would solve it

Added: grass/trunk/scripts/g.extension/testsuite/data/sample_modules/r.plus.example/Makefile
===================================================================
--- grass/trunk/scripts/g.extension/testsuite/data/sample_modules/r.plus.example/Makefile	                        (rev 0)
+++ grass/trunk/scripts/g.extension/testsuite/data/sample_modules/r.plus.example/Makefile	2015-07-21 15:57:14 UTC (rev 65757)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = r.plus.example
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script

Added: grass/trunk/scripts/g.extension/testsuite/data/sample_modules/r.plus.example/r.plus.example.html
===================================================================
--- grass/trunk/scripts/g.extension/testsuite/data/sample_modules/r.plus.example/r.plus.example.html	                        (rev 0)
+++ grass/trunk/scripts/g.extension/testsuite/data/sample_modules/r.plus.example/r.plus.example.html	2015-07-21 15:57:14 UTC (rev 65757)
@@ -0,0 +1,25 @@
+<h2>DESCRIPTION</h2>
+
+<em>r.plus.example</em>
+
+<h2>NOTES</h2>
+
+<h2>EXAMPLES</h2>
+
+<div class="code"><pre>
+r.plus.example
+</pre></div>
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="g.region.html">g.region</a>
+</em>
+
+
+<h2>AUTHORS</h2>
+
+Vaclav Petras, NCSU OSGeoREL<br>
+
+<p>
+<i>Last changed: $Date: 2015-06-07 07:21:31 -0400 (Sun, 07 Jun 2015) $</i>

Added: grass/trunk/scripts/g.extension/testsuite/data/sample_modules/r.plus.example/r.plus.example.py
===================================================================
--- grass/trunk/scripts/g.extension/testsuite/data/sample_modules/r.plus.example/r.plus.example.py	                        (rev 0)
+++ grass/trunk/scripts/g.extension/testsuite/data/sample_modules/r.plus.example/r.plus.example.py	2015-07-21 15:57:14 UTC (rev 65757)
@@ -0,0 +1,36 @@
+#!/usr/bin/env python
+
+#%module
+#% description: Adds the values of two rasters (A + B)
+#% keyword: raster
+#% keyword: algebra
+#% keyword: sum
+#%end
+#%option G_OPT_R_INPUT
+#% key: araster
+#% description: Name of input raster A in an expression A + B
+#%end
+#%option G_OPT_R_INPUT
+#% key: braster
+#% description: Name of input raster B in an expression A + B
+#%end
+#%option G_OPT_R_OUTPUT
+#%end
+
+
+import grass.script as gscript
+
+
+def main():
+    options, flags = gscript.parser()
+    araster = options['araster']
+    braster = options['braster']
+    output = options['output']
+
+    gscript.mapcalc('{r} = {a} + {b}'.format(r=output, a=araster, b=braster))
+
+    return 0
+
+
+if __name__ == "__main__":
+    main()

Added: grass/trunk/scripts/g.extension/testsuite/data/sample_modules/r.plus.example.tar.gz
===================================================================
(Binary files differ)


Property changes on: grass/trunk/scripts/g.extension/testsuite/data/sample_modules/r.plus.example.tar.gz
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: grass/trunk/scripts/g.extension/testsuite/data/sample_modules/r.plus.example.zip
===================================================================
(Binary files differ)


Property changes on: grass/trunk/scripts/g.extension/testsuite/data/sample_modules/r.plus.example.zip
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: grass/trunk/scripts/g.extension/testsuite/data/sample_modules/r.plus.example_sep.tar.gz
===================================================================
(Binary files differ)


Property changes on: grass/trunk/scripts/g.extension/testsuite/data/sample_modules/r.plus.example_sep.tar.gz
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Modified: grass/trunk/scripts/g.extension/testsuite/test_addons_modules.py
===================================================================
--- grass/trunk/scripts/g.extension/testsuite/test_addons_modules.py	2015-07-21 14:00:53 UTC (rev 65756)
+++ grass/trunk/scripts/g.extension/testsuite/test_addons_modules.py	2015-07-21 15:57:14 UTC (rev 65757)
@@ -15,6 +15,7 @@
 from grass.gunittest.case import TestCase
 from grass.gunittest.main import test
 from grass.gunittest.gmodules import SimpleModule
+from grass.gunittest.utils import silent_rmtree
 
 import os
 
@@ -49,7 +50,7 @@
 
     url = 'file://' + os.path.abspath('data')
 
-    def test_limits(self):
+    def test_listing(self):
         """Test if results is in expected limits"""
         module = SimpleModule('g.extension', flags='l', svnurl=self.url)
         self.assertModule(module)
@@ -57,5 +58,68 @@
         self.assertMultiLineEqual(stdout, MODULES_OUTPUT)
 
 
+class TestModulesFromDifferentSources(TestCase):
+
+    url = 'file://' + os.path.abspath('data/sample_modules')
+    path = os.path.join('data', 'sample_modules')
+    install_prefix = 'gextension_test_install_path'
+    # TODO: this is wrong for MS Win
+    files = [
+        os.path.join(install_prefix, 'scripts', 'r.plus.example'),
+        os.path.join(install_prefix, 'docs', 'html', 'r.plus.example.html'),
+    ]
+    # to create archives from the source, the following was used:
+    # zip r.plus.example.zip r.plus.example/*
+    # tar czvf r.plus.example.tar.gz r.plus.example
+    # cd r.plus.example/
+    # tar czvf ../r.plus.example_sep.tar.gz *    
+
+    def setUp(self):
+        """Make sure we are not dealing with some old files"""
+        if os.path.exists(self.install_prefix):
+            files = os.listdir(self.install_prefix)
+            if files:
+                RuntimeError("Install prefix path '{}' contains files {}"
+                             .format(self.install_prefix, files))
+
+    def tearDown(self):
+        """Remove created files"""
+        silent_rmtree(self.install_prefix)
+
+    def test_directory_install(self):
+        """Test if results is in expected limits"""
+        self.assertModule('g.extension', extension='r.plus.example',
+                          svnurl=os.path.join(self.path, 'r.plus.example'),
+                          prefix=self.install_prefix)
+        # TODO: this is wrong for MS Win
+        for file in self.files:
+            self.assertFileExists(file)
+
+    def test_targz_install(self):
+        """Test if results is in expected limits"""
+        self.assertModule('g.extension', extension='r.plus.example',
+                          svnurl=os.path.join(self.path,
+                                              'r.plus.example.tar.gz'),
+                          prefix=self.install_prefix)
+        for file in self.files:
+            self.assertFileExists(file)
+
+    def test_remote_targz_without_dir_install(self):
+        """Test if results is in expected limits"""
+        self.assertModule('g.extension', extension='r.plus.example',
+                          svnurl=self.url + '/' + 'r.plus.example_sep.tar.gz',
+                          prefix=self.install_prefix, verbose=True)
+        for file in self.files:
+            self.assertFileExists(file)
+
+    def test_remote_zip_install(self):
+        """Test if results is in expected limits"""
+        self.assertModule('g.extension', extension='r.plus.example',
+                          svnurl=self.url + '/' + 'r.plus.example.zip',
+                          prefix=self.install_prefix)
+        for file in self.files:
+            self.assertFileExists(os.path.join(file))
+
+
 if __name__ == '__main__':
     test()

Modified: grass/trunk/scripts/g.extension/testsuite/test_addons_toolboxes.py
===================================================================
--- grass/trunk/scripts/g.extension/testsuite/test_addons_toolboxes.py	2015-07-21 14:00:53 UTC (rev 65756)
+++ grass/trunk/scripts/g.extension/testsuite/test_addons_toolboxes.py	2015-07-21 15:57:14 UTC (rev 65757)
@@ -40,7 +40,7 @@
 
     url = 'file://' + os.path.abspath('data')
 
-    def test_limits(self):
+    def test_listing(self):
         """Test if results is in expected limits"""
         module = SimpleModule('g.extension', flags='lt', svnurl=self.url)
         self.assertModule(module)



More information about the grass-commit mailing list