Ejemplo n.º 1
0
def test_plugin_hdfs_add():
    dict1 = si_app.get_data_source_dict(ds_name=hdfs_ds_dict['ds_name'])
    assert dict1 is None

    si_app.add_data_soruce(hdfs_ds_dict)
    dict1 = si_app.get_data_source_dict(ds_name=hdfs_ds_dict['ds_name'])
    assert dict1['ds_param']['hdfs_web_url'] == 'http://localhost:50070'
Ejemplo n.º 2
0
def test_plugin_mysql_add(resource_a_setup):
    dict1 = si_app.get_data_source_dict(ds_name=ds_dict['ds_name'])
    assert dict1 is None

    si_app.add_data_soruce(ds_dict)
    dict1 = si_app.get_data_source_dict(ds_name=ds_dict['ds_name'])
    assert dict1['ds_param']['connect_string'] == ds_dict['ds_param'][
        'connect_string']
Ejemplo n.º 3
0
 def __init__(self,ds_dict=None, ds_name = None):
     if ds_dict is not None:
         self.ds_dict = ds_dict
     elif ds_name is not None:
             self.ds_dict = si_app.get_data_source_dict(ds_name = ds_name)
     else:
         si_app.logger.error('no data source is given!')
Ejemplo n.º 4
0
    def get(self):
        table_id = self.get_argument('table_id')
        ds_name = self.get_argument('ds_name')

        ds_dict = si_app.get_data_source_dict(ds_name=ds_name)
        the_engine = si_pm.get_reflect_plugin(
            ds_dict['ds_type'])['reflect_engine']
        a_ds = the_engine.ReflectEngine(ds_dict=ds_dict)
        new_snippet = a_ds.generate_notebook_snippet(table_id=table_id)

        replace_dict = {
            '$$cell1$$': '\\n'.join(new_snippet.split('\n')),
            '$$cell2$$': ''
        }

        # print(si_app.nb_server_app.__dict__)
        print('the config is: ', si_app.nb_server_app.config.__dict__)
        n_root_dir1 = si_app.nb_server_app.config['FileContentsManager'][
            'root_dir']
        n_root_dir = si_app.nb_server_app.notebook_dir
        print(n_root_dir)
        notebook_file_name = '__'.join(
            ('si_notebook_' + ds_name + '_' + table_id + '.ipynb').split('/'))
        generate_path = os.path.join(str(n_root_dir), notebook_file_name)
        print(generate_path)
        with open(
                os.path.join(si_app.config['main']['schemaflex_home'],
                             'jupyterext',
                             'schemaindex_notebook_template.ipynb'),
                "rt") as fin:
            with open(generate_path, "wt") as fout:
                for line in fin:
                    snippet_result = line
                    for key in replace_dict.keys():
                        snippet_result = snippet_result.replace(
                            key, replace_dict[key])
                    fout.write(snippet_result)

        #from subprocess import Popen
        #p = Popen(["jupyter", "notebook",  "--notebook-dir=" + si_app.config['main']['schemaflex_spec'], gen_loc]) # something long running

        # Info = {'result': 'started in another browser'}
        self.redirect(url=url_path_join(
            si_app.nb_server_app.web_app.settings['base_url'], 'notebooks',
            notebook_file_name))
Ejemplo n.º 5
0
    def post(self):
        ds_name = self.get_argument('ds_name')
        ds_dict = si_app.get_data_source_dict(ds_name=ds_name)
        ds_dict['delete_reflected_database_automatic'] = self.get_argument(
            'delete_reflected_database_automatic', default=None)

        result_message = si_app.delete_data_soruce(ds_dict)
        dbrs = si_app.get_data_source_rs()
        base_navigation_dict = {
            'selected_menu': 'database',
            'self.request.path': self.request.path,
            'dbrs': dbrs,
            'selected_add_data_source': True,
            'plugin_name_list': si_app.get_plugin_name_list(),
            'selected_schema_name': ds_dict['ds_name'],
            'message': result_message
        }
        if result_message['message_title'] == 'Error':
            #session = create_session(bind=engine)
            #dbrs1 = session.query(MDatasource).filter_by(ds_name = ds_dict['ds_name'])
            #db = dbrs1.first()
            base_navigation_dict['db'] = ds_dict
            base_navigation_dict[
                'tabrs'] = si_app.get_table_list_for_data_source_rs(
                    param_ds_name=ds_dict['ds_name'])
            base_navigation_dict['input_db_type'] = ds_dict['ds_type']
            plugin_info = si_app.get_plugin_info(
                p_plugin_name=ds_dict['ds_type'])
            base_navigation_dict['input_ds_param'] = json.loads(
                plugin_info.ds_param)

            #self.render("database_summary.html",
            #            base_navigation_dict=base_navigation_dict)

            self.write(
                self.render_template(
                    'database_summary.html',
                    base_navigation_dict=base_navigation_dict,
                ))

        self.redirect('./overview')
Ejemplo n.º 6
0
    def get(self):
        # self.write("Hello, world")
        # param_db_name = self.get_argument("table_group_name", None)
        # session = create_session(bind=engine)
        print(self.request.path)
        param_ds_name = self.get_argument("ds_name", None)
        if param_ds_name is None:
            si_app.logger.warn('error: no data source name is given (ds_name)')
            result_message = {
                'message_type': 'danger',
                'message_title': 'Error',
                'message_body': 'No data source name is given (ds_name)'
            }

            base_navigation_dict = {
                'selected_menu': 'datasources',
                'dbrs':
                si_app.get_data_source_rs(),  # session.query(MDatasource),
                'error': 'error: no schema name is given',
                'selected_add_data_source': False,
                'message': result_message,
                'db': None,
                'self.request.path': self.request.path,
            }
            # self.rend
            self.write(
                self.render_template(
                    'database_summary.html',
                    base_navigation_dict=base_navigation_dict,
                ))

        #dbrs1 = session.query(MDatasource).filter_by(ds_name = param_ds_name )
        # db = dbrs1.first()

        # 20180120, changed db from MDatasoruce to ds_dict.
        db = si_app.get_data_source_dict(ds_name=param_ds_name)
        if db is None:
            print('')
            si_app.logger.warn('error: did not find database' + param_ds_name +
                               ' after creation.')
            result_message = {
                'message_type': 'danger',
                'message_title': 'Error',
                'message_body': 'error: did not find database' + param_ds_name
            }

            base_navigation_dict = {
                'selected_menu': 'overview',
                'dbrs':
                si_app.get_data_source_rs(),  # session.query(MDatasource),
                'error': 'error: no schema name is given',
                'selected_add_data_source': False,
                'message': result_message,
                'self.request.path': self.request.path,
                'plugin_list': si_app.get_plugin_list(),
            }

            self.write(
                self.render_template(
                    'database_summary.html',
                    base_navigation_dict=base_navigation_dict,
                ))

        dbrs = si_app.get_data_source_rs()
        tabrs = si_app.get_table_list_for_data_source_rs(
            param_ds_name=param_ds_name)

        base_navigation_dict = {
            'selected_menu': 'datasources',
            'selected_add_data_source': False,
            'dbrs': dbrs,
            'selected_schema_name': param_ds_name,
            'db': db,
            'tabrs': tabrs,
            'self.request.path': self.request.path,
            'plugin_name_list': si_app.get_plugin_name_list(),
        }

        base_navigation_dict['input_db_type'] = db['ds_type']
        plugin_info = si_app.get_plugin_info(p_plugin_name=db['ds_type'])
        base_navigation_dict['input_ds_param'] = json.loads(
            plugin_info.ds_param)

        self.write(
            self.render_template(
                'database_summary.html',
                base_navigation_dict=base_navigation_dict,
            ))