climate-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jo...@apache.org
Subject svn commit: r1562332 - /incubator/climate/trunk/ocw-ui/backend/local_file_metadata_extractors.py
Date Wed, 29 Jan 2014 00:48:48 GMT
Author: joyce
Date: Wed Jan 29 00:48:48 2014
New Revision: 1562332

URL: http://svn.apache.org/r1562332
Log:
CLIMATE-326 - Add lfme list_vars endpoint

Modified:
    incubator/climate/trunk/ocw-ui/backend/local_file_metadata_extractors.py

Modified: incubator/climate/trunk/ocw-ui/backend/local_file_metadata_extractors.py
URL: http://svn.apache.org/viewvc/incubator/climate/trunk/ocw-ui/backend/local_file_metadata_extractors.py?rev=1562332&r1=1562331&r2=1562332&view=diff
==============================================================================
--- incubator/climate/trunk/ocw-ui/backend/local_file_metadata_extractors.py (original)
+++ incubator/climate/trunk/ocw-ui/backend/local_file_metadata_extractors.py Wed Jan 29 00:48:48
2014
@@ -179,3 +179,43 @@ def list_latlon(file_path):
     if request.query.callback:
         return '%s(%s)' % (request.query.callback, output)
     return output
+
+@lfme_app.route('/list_vars/<file_path:path>')
+def list_vars(file_path):
+    ''' Retrieve variable names from file.
+
+    :param file_path: Path to the NetCDF file from which variable information
+        should be extracted
+    :type file_path: String:
+
+    :returns: Dictionary containing variable information if succesful, otherwise
+        failure information is returned.
+
+    * Example successful JSON return *
+
+    .. sourcecode: javascript
+
+        {
+            "success": true,
+            "variables": List of variable names in the file
+        }
+
+    * Example failure JSON return *
+
+    .. sourcecode: javascript
+
+        {
+            "success": false
+        }
+    '''
+    try:
+        in_file = netCDF4.Dataset(file_path, mode='r')
+    except RuntimeError:
+        output = {'success': False}
+    else:
+        output = {'success': True, 'variables': in_file.variables.keys()}
+        in_file.close()
+    finally:
+        if request.query.callback:
+          return "%s(%s)" % (request.query.callback, output)
+        return output



Mime
View raw message