Example #1
0
 def _which_display(log, output):
     lst_len = 30762
     lines = re.split(r'[\n]\s*', log)
     i = 0
     elog = []
     for line in lines:
         # logger.debug("In lines loop")
         i += 1
         e = []
         if line.startswith('ERROR'):
             e = lines[(max(i - 15, 0)):(min(i + 16, len(lines)))]
         elog = elog + e
     if len(elog) == 0 and len(output) > lst_len:  # no error and LST output
         return HTML(output)
     elif len(elog) == 0 and len(output) <= lst_len:  # no error and no LST
         color_log = highlight(
             log, SASLogLexer(),
             HtmlFormatter(full=True,
                           style=SASLogStyle,
                           lineseparator="<br>"))
         return HTML(color_log)
     elif len(elog) > 0 and len(output) <= lst_len:  # error and no LST
         color_log = highlight(
             log, SASLogLexer(),
             HtmlFormatter(full=True,
                           style=SASLogStyle,
                           lineseparator="<br>"))
         return HTML(color_log)
     else:  # errors and LST
         color_log = highlight(
             log, SASLogLexer(),
             HtmlFormatter(full=True,
                           style=SASLogStyle,
                           lineseparator="<br>"))
         return HTML(color_log + output)
Example #2
0
    def _which_display(self, log, output):
        lines = re.split(r'[\n]\s*', log)
        i = 0
        elog = []
        for line in lines:
            i += 1
            e = []
            if line.startswith('ERROR'):
                logger.debug("In ERROR Condition")
                e = lines[(max(i - 15, 0)):(min(i + 16, len(lines)))]
            elog = elog + e
        tlog = '\n'.join(elog)
        logger.debug("elog count: " + str(len(elog)))
        logger.debug("tlog: " + str(tlog))

        color_log = highlight(log, SASLogLexer(), HtmlFormatter(full=True, style=SASLogStyle, lineseparator="<br>"))
        # store the log for display in the showSASLog nbextension
        self.cachedlog = color_log
        # Are there errors in the log? if show the lines on each side of the error
        if len(elog) == 0 and len(output) > self.lst_len:  # no error and LST output
            debug1 = 1
            logger.debug("DEBUG1: " + str(debug1) + " no error and LST output ")
            return HTML(output)
        elif len(elog) == 0 and len(output) <= self.lst_len:  # no error and no LST
            debug1 = 2
            logger.debug("DEBUG1: " + str(debug1) + " no error and no LST")
            return HTML(color_log)
        elif len(elog) > 0 and len(output) <= self.lst_len:  # error and no LST
            debug1 = 3
            logger.debug("DEBUG1: " + str(debug1) + " error and no LST")
            return HTML(color_log)
        else:  # errors and LST
            debug1 = 4
            logger.debug("DEBUG1: " + str(debug1) + " errors and LST")
            return HTML(color_log + output)
Example #3
0
    def do_execute_direct(self, code: str, silent: bool = False) -> str:
        """
        This is the main method that takes code from the Jupyter cell and submits it to the SAS server

        :param code: code from the cell
        :param silent:
        :return: str with either the log or list
        """
        if not code.strip():
            return {
                'status': 'ok',
                'execution_count': self.execution_count,
                'payload': [],
                'user_expressions': {}
            }

        if self.mva is None:
            self._allow_stdin = True
            self._start_sas()

        if self.lst_len < 0:
            self._get_lst_len()

        if code.startswith('Obfuscated SAS Code'):
            logger.debug("decoding string")
            tmp1 = code.split()
            decode = base64.b64decode(tmp1[-1])
            code = decode.decode('utf-8')

        if code.startswith('showSASLog_11092015') == False and code.startswith(
                "CompleteshowSASLog_11092015") == False:
            logger.debug("code type: " + str(type(code)))
            logger.debug("code length: " + str(len(code)))
            logger.debug("code string: " + code)
            if code.startswith("/*SASKernelTest*/"):
                res = self.mva.submit(code, "text")
            else:
                res = self.mva.submit(code, prompt=self.promptDict)
                self.promptDict = {}
            if res['LOG'].find("SAS process has terminated unexpectedly") > -1:
                print(res['LOG'], '\n' "Restarting SAS session on your behalf")
                self.do_shutdown(True)
                return res['LOG']

            output = res['LST']
            log = res['LOG']
            dis = self._which_display(log, output)
            return dis
        elif code.startswith(
                "CompleteshowSASLog_11092015") == True and code.startswith(
                    'showSASLog_11092015') == False:
            full_log = highlight(
                self.mva.saslog(), SASLogLexer(),
                HtmlFormatter(full=True,
                              style=SASLogStyle,
                              lineseparator="<br>",
                              title="Full SAS Log"))
            return full_log.replace('\n', ' ')
        else:
            return self.cachedlog.replace('\n', ' ')
Example #4
0
 def line_showFullLog(self):
     """
     SAS Kernel magic to show the entire SAS log since the kernel was started (last restarted)
     This magic is only available within the SAS Kernel
     """
     if self.kernel.mva is None:
         self.kernel._allow_stdin = True
         self.kernel._start_sas()
         print("Session Started probably not the log you want")
     full_log = highlight(self.kernel.mva.saslog(), SASLogLexer(), HtmlFormatter(full=True, style=SASLogStyle, lineseparator="<br>"))
     return self.kernel.Display(HTML(full_log))
Example #5
0
    def _which_display(self, log: str, output: str) -> HTML:
        """
        Determines if the log or lst should be returned as the results for the cell based on parsing the log
        looking for errors and the presence of lst output.

        :param log: str log from code submission
        :param output: None or str lst output if there was any
        :return: The correct results based on log and lst
        :rtype: str
        """
        lines = re.split(r'[\n]\s*', log)
        i = 0
        elog = []
        for line in lines:
            i += 1
            e = []
            if line.startswith('ERROR'):
                logger.debug("In ERROR Condition")
                e = lines[(max(i - 15, 0)):(min(i + 16, len(lines)))]
            elog = elog + e
        tlog = '\n'.join(elog)
        logger.debug("elog count: " + str(len(elog)))
        logger.debug("tlog: " + str(tlog))

        color_log = highlight(
            log, SASLogLexer(),
            HtmlFormatter(full=True, style=SASLogStyle, lineseparator="<br>"))
        # store the log for display in the showSASLog nbextension
        self.cachedlog = color_log
        # Are there errors in the log? if show the lines on each side of the error
        if len(elog) == 0 and len(
                output) > self.lst_len:  # no error and LST output
            debug1 = 1
            logger.debug("DEBUG1: " + str(debug1) +
                         " no error and LST output ")
            return HTML(output)
        elif len(elog
                 ) == 0 and len(output) <= self.lst_len:  # no error and no LST
            debug1 = 2
            logger.debug("DEBUG1: " + str(debug1) + " no error and no LST")
            return HTML(color_log)
        elif len(elog) > 0 and len(output) <= self.lst_len:  # error and no LST
            debug1 = 3
            logger.debug("DEBUG1: " + str(debug1) + " error and no LST")
            return HTML(color_log)
        else:  # errors and LST
            debug1 = 4
            logger.debug("DEBUG1: " + str(debug1) + " errors and LST")
            return HTML(color_log + output)
Example #6
0
    def SASLOG(self, line):
        """
        %SASLOG

        This line magic will return the SAS log from the current notebooks SAS session.
        A SAS session is created with the first submit of a cell with an associated SAS magic such as:
              %%SAS, %%OPTMODEL, %%IML, %%SASPROC
        Without any line options the magic will return the log from the last cell that used a SAS magic.  
        
        Use the line option -FULL to request the full log of the current SAS Session.
        This will include the log for all cells that have been computed with a SAS magic in the current session
        
        Note that a session will only include submissions within the current notebook session.  
        A SAS session clears when notebooks are halted.

        """
        if line.lower() == '-full':
            res = self.mva._log
        else:
            res = self.mva._logr
        color_log = highlight(
            res, SASLogLexer(),
            HtmlFormatter(full=True, style=SASLogStyle, lineseparator="<br>"))
        return HTML(color_log)
Example #7
0
 def _colorLog(self, log: str) -> str:
     color_log = highlight(
         log, SASLogLexer(),
         HtmlFormatter(full=True, style=SASLogStyle, lineseparator="<br>"))
     return color_log