Пример #1
0
    def publish(self, gateway_server, gateway_title, gateway_icon,
                gateway_sel_kernel):
        self.server = gateway_server.strip("/ ")
        self.contents['notebook']['metadata']['pixiedust'].update({
            "title":
            gateway_title,
            "icon":
            gateway_icon
        })
        if gateway_sel_kernel != "Default":
            self.contents['notebook']['metadata']['pixiedust'].update(
                {"kernel": gateway_sel_kernel})
        self.compute_imports()
        setUserPreference("pixie_gateway_server", gateway_server)
        response = requests.post("{}/publish/{}".format(
            self.server, self.contents['name']),
                                 json=self.contents['notebook'])
        if response.status_code == requests.codes.ok:
            self.pixieapp_model = response.json()
            return """
<style type="text/css">
.publish{
    font-size: larger;
    margin-left: 30px;
}
.publish .logmessages{
}
.publish .logmessage{
    color: darkblue;
}
.publish .summary{
    font-size: xx-large;
    text-align: center;
}
</style>
<div class="publish">
    <div class="logmessages">
        {%for message in this.pixieapp_model['log']%}
        <div class="logmessage">
            {{message}}
        </div>
        {%endfor%}
    </div>
    <div class="summary">
        <div>Notebook Successfully published</div>
        <div>
            <a href="{{this.server}}/pixieapp/{{this.pixieapp_model['name']}}" target="blank">
                {{this.contents['name']}}
            </a>
        </div>
    </div>
</div>
            """

        return "<div>An Error occured while publishing this notebook: {}".format(
            response.text)
Пример #2
0
    def publish(self, gateway_server, gateway_title, gateway_icon, gateway_sel_kernel):
        self.server = gateway_server.strip("/ ")
        self.contents['notebook']['metadata']['pixiedust'].update({
            "title":gateway_title, "icon":gateway_icon, "security": self.security
        })
        if gateway_sel_kernel != "Default":
            self.contents['notebook']['metadata']['pixiedust'].update({"kernel":gateway_sel_kernel})
        self.compute_imports()
        setUserPreference("pixie_gateway_server", gateway_server)
        response = requests.post(
            "{}/publish/{}".format(self.server, self.contents['name']), 
            json = self.contents['notebook']
        )
        if response.status_code == requests.codes.ok:
            self.pixieapp_model = response.json()
            return """
<style type="text/css">
.publish{
    font-size: larger;
    margin-left: 30px;
}
.publish .logmessages{
}
.publish .logmessage{
    color: darkblue;
}
.publish .summary{
    font-size: xx-large;
    text-align: center;
}
</style>
<div class="publish">
    <div class="logmessages">
        {%for message in this.pixieapp_model['log']%}
        <div class="logmessage">
            {{message}}
        </div>
        {%endfor%}
    </div>
    <div class="summary">
        <div>Notebook Successfully published</div>
        <div>
            <a href="{{this.pixieapp_model['url']}}" target="blank">
                {{this.contents['name']}}
            </a>
        </div>
    </div>
</div>
            """
        
        return "<div>An Error occured while publishing this notebook: {}".format(response.text)
Пример #3
0
    def shareIt(self, gateway_server, gateway_description):
        self.server = gateway_server.strip('/')
        setUserPreference("pixie_gateway_server", gateway_server)
        rendererid = ''
        with capture_output() as buf:
            try:
                command = self.parent_command
                #add any options from the current cell metadata
                if self.cell_metadata is not None and 'pixiedust' in self.cell_metadata and 'displayParams' in self.cell_metadata['pixiedust']:
                    for key,value in iteritems(self.cell_metadata['pixiedust']['displayParams']):
                        command = self.update_command(command, key, value)
                        if key == 'rendererId':
                            rendererid = value
                command = self.update_command(command, "nostore_figureOnly", "true")
                command = self.update_command(command, "chart_share", "true")
                command = self.update_command(command, "runInDialog", "false")
                self.debug("Share command: {}".format(command))
                sys.modules['pixiedust.display'].pixiedust_display_callerText = command
                for key in ShellAccess:
                    locals()[key] = ShellAccess[key]
                eval(command, globals(), locals())
            finally:
                del sys.modules['pixiedust.display'].pixiedust_display_callerText

        payload = {
            "chart": "\n".join([output._repr_html_() for output in buf.outputs]),
            "description": gateway_description,
            "rendererId": rendererid
        }
        
        try:
            share_url = "{}/chart".format(self.server)
            response = requests.post(share_url, json = payload)
            if response.status_code == requests.codes.ok:
                self.chart_model = response.json()
                return """
    <style type="text/css">
    .share{
        font-size: larger;
        margin-left: 30px;
    }
    .share h2 {
        padding-bottom: 15px;
    }
    .share h2:not(:first-child) {
        margin-top: 50px;
    }
    .publish .summary{
        font-size: xx-large;
        text-align: center;
    }
    .share textarea{
        font-family: monospace;
        resize: none;
    }
    </style>
    <div class="share">
        <div class="summary">
            <h2>Chart Successfully shared</h2>
            <div>
                <a href="{{this.server}}/chart/{{this.chart_model['CHARTID']}}" target="blank">
                    {{this.server}}/chart/{{this.chart_model['CHARTID']}}
                </a>
            </div>
            <h2>Embed the chart into your web app</h2>
            <div>
                <textarea class="form-control" rows="4"  readonly>
&lt;object type="text/html" data="{{this.server}}/embed/{{this.chart_model['CHARTID']}}/600/400" width="600" height="400"&gt;
    &lt;a href="{{this.server}}/embed/{{this.chart_model['CHARTID']}}"&gt;View Chart&lt;/a&gt;
&lt;/object&gt;
                </textarea>
            </div>
        </div>
    </div>
                """
            
            return "<div>An Error occured while sharing this chart: {}".format(response.text)
        except Exception as ex:
            return "<div>Unexcepted error, Please check that PixieGateway server {} is reachable: {}".format(self.server, ex)
Пример #4
0
    def shareIt(self, gateway_server, gateway_description):
        self.server = gateway_server.strip('/')
        setUserPreference("pixie_gateway_server", gateway_server)
        rendererid = ''
        with capture_output() as buf:
            try:
                command = self.parent_command
                #add any options from the current cell metadata
                if self.cell_metadata is not None and 'pixiedust' in self.cell_metadata and 'displayParams' in self.cell_metadata[
                        'pixiedust']:
                    for key, value in iteritems(
                            self.cell_metadata['pixiedust']['displayParams']):
                        command = self.update_command(command, key, value)
                        if key == 'rendererId':
                            rendererid = value
                command = self.update_command(command, "nostore_figureOnly",
                                              "true")
                command = self.update_command(command, "chart_share", "true")
                sys.modules[
                    'pixiedust.display'].pixiedust_display_callerText = command
                for key in ShellAccess:
                    locals()[key] = ShellAccess[key]
                eval(command, globals(), locals())
            finally:
                del sys.modules[
                    'pixiedust.display'].pixiedust_display_callerText

        payload = {
            "chart":
            "\n".join([output._repr_html_() for output in buf.outputs]),
            "description": gateway_description,
            "rendererId": rendererid
        }

        try:
            share_url = "{}/chart".format(self.server)
            response = requests.post(share_url, json=payload)
            if response.status_code == requests.codes.ok:
                self.chart_model = response.json()
                return """
    <style type="text/css">
    .share{
        font-size: larger;
        margin-left: 30px;
    }
    .share h2 {
        padding-bottom: 15px;
    }
    .share h2:not(:first-child) {
        margin-top: 50px;
    }
    .publish .summary{
        font-size: xx-large;
        text-align: center;
    }
    .share textarea{
        font-family: monospace;
        resize: none;
    }
    </style>
    <div class="share">
        <div class="summary">
            <h2>Chart Successfully shared</h2>
            <div>
                <a href="{{this.server}}/chart/{{this.chart_model['CHARTID']}}" target="blank">
                    {{this.server}}/chart/{{this.chart_model['CHARTID']}}
                </a>
            </div>
            <h2>Embed the chart into your web app</h2>
            <div>
                <textarea class="form-control" rows="4"  readonly>
&lt;object type="text/html" data="{{this.server}}/embed/{{this.chart_model['CHARTID']}}/600/400" width="600" height="400"&gt;
    &lt;a href="{{this.server}}/embed/{{this.chart_model['CHARTID']}}"&gt;View Chart&lt;/a&gt;
&lt;/object&gt;
                </textarea>
            </div>
        </div>
    </div>
                """

            return "<div>An Error occured while sharing this chart: {}".format(
                response.text)
        except Exception as ex:
            return "<div>Unexcepted error, Please check that PixieGateway server {} is reachable: {}".format(
                self.server, ex)