Эх сурвалжийг харах

[notebook] Support a default list of snippets

Useful when the hue.ini was not updated with the [notebook] section.
user is not used yet
Romain Rigaux 10 жил өмнө
parent
commit
72fa7d8a0e

+ 1 - 1
desktop/core/src/desktop/lib/conf.py

@@ -80,7 +80,7 @@ import sys
 try:
   from collections import OrderedDict
 except ImportError:
-  from ordereddict import OrderedDict
+  from ordereddict import OrderedDict # Python 2.6
 
 
 # Magical object for use as a "symbol"

+ 51 - 6
desktop/libs/notebook/src/notebook/conf.py

@@ -15,22 +15,31 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+try:
+  from collections import OrderedDict
+except ImportError:
+  from ordereddict import OrderedDict # Python 2.6
+
 from django.utils.translation import ugettext_lazy as _t
 
 from desktop.lib.conf import Config, UnspecifiedConfigSection, ConfigSection,\
   coerce_json_dict, coerce_string
 
 
-def get_interpreters():
+def get_interpreters(user=None):  
+  if not INTERPRETERS.get():
+    _default_interpreters()
+
+  interpreters = INTERPRETERS.get()
+
   return [{
-      "name": INTERPRETERS.get()[i].NAME.get(),
+      "name": interpreters[i].NAME.get(),
       "type": i,
-      "interface": INTERPRETERS.get()[i].INTERFACE.get(),
-      "options": INTERPRETERS.get()[i].OPTIONS.get()}
-      for i in INTERPRETERS.get()
+      "interface": interpreters[i].INTERFACE.get(),
+      "options": interpreters[i].OPTIONS.get()}
+      for i in interpreters
   ]
 
-
 INTERPRETERS = UnspecifiedConfigSection(
   "interpreters",
   help="One entry for each type of snippet. The first 5 will appear in the wheel.",
@@ -92,3 +101,39 @@ GITHUB_CLIENT_SECRET = Config(
     type=coerce_string,
     default=""
 )
+
+def _default_interpreters():
+  INTERPRETERS.set_for_testing(OrderedDict((
+      ('hive', {
+          'name': 'Hive', 'interface': 'hiveserver2', 'options': {}
+      }),
+      ('impala', {
+          'name': 'Impala', 'interface': 'hiveserver2', 'options': {}
+      }),
+      ('spark', {
+          'name': 'Scala', 'interface': 'livy', 'options': {}
+      }),
+      ('pyspark', {
+          'name': 'PySpark', 'interface': 'livy', 'options': {}
+      }),
+      ('r', {
+          'name': 'R', 'interface': 'livy', 'options': {}
+      }),
+      ('jar', {
+          'name': 'Spark Submit Jar', 'interface': 'livy-batch', 'options': {}
+      }),
+      ('py', {
+          'name': 'Spark Submit Python', 'interface': 'livy-batch', 'options': {}
+      }),
+      ('pig', {
+          'name': 'Pig', 'interface': 'pig', 'options': {}
+      }),
+      ('text', {
+          'name': 'Text', 'interface': 'text', 'options': {}
+      }),
+      ('markdown', {
+          'name': 'Markdown', 'interface': 'text', 'options': {}
+      })
+    ))
+  )
+

+ 1 - 1
desktop/libs/notebook/src/notebook/connectors/base.py

@@ -88,7 +88,7 @@ def get_api(user, snippet, fs, jt):
   from notebook.connectors.text import TextApi
 
 
-  interpreter = [interpreter for interpreter in get_interpreters() if interpreter['type'] == snippet['type']]
+  interpreter = [interpreter for interpreter in get_interpreters(user) if interpreter['type'] == snippet['type']]
   if not interpreter:
     raise PopupException(_('Snippet type %(type)s is not configured in hue.ini') % snippet)
   interpreter = interpreter[0]

+ 1 - 1
desktop/libs/notebook/src/notebook/views.py

@@ -60,7 +60,7 @@ def notebook(request):
   return render('notebook.mako', request, {
       'notebooks_json': json.dumps([notebook.get_data()]),
       'options_json': json.dumps({
-          'languages': get_interpreters(),
+          'languages': get_interpreters(request.user),
           'session_properties': SparkApi.PROPERTIES
       }),
       'autocomplete_base_url': autocomplete_base_url,