How to use the sos.utils.env.logger.warning function in sos

To help you get started, we’ve selected a few sos examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github stephenslab / dsc / src / dsc_parser.py View on Github external
tmp_chunk_name = item[0].split('@')
                    if len(tmp_chunk_name) > 1:
                        rmd_chunk_pattern = tmp_chunk_name[0]
                        item[0] = tmp_chunk_name[-1]
                fpath = locate_file(item[0], self.path)
                if fpath is None:
                    # must be a system executable
                    # FIXME: need to do it differently if host is involved
                    # ie, to check the remote computer not the current computer
                    if not executable(item[0]).target_exists():
                        raise FormatError(
                            f"Cannot find executable ``{item[0]}`` in DSC \"exec_path\" or system \"PATH\"."
                        )
                    self.exe['path'].append(item[0])
                    if etype in ['PY', 'R']:
                        env.logger.warning(
                            f'Cannot find script ``{item[0]}`` in path ``{self.path}``. DSC will treat it a command line executable.'
                        )
                else:
                    # try determine self.exe['type']
                    if etype == '':
                        etype = 'unknown'
                    if self.exe['type'] == 'unknown':
                        self.exe['type'] = etype
                    if self.exe['type'] != etype:
                        raise FormatError(
                            f"Cannot mix ``{etype}`` and ``{self.exe['type']}`` codes, near ``{item[0]}``."
                        )
                    # load contents
                    if etype != 'unknown':
                        self.exe['content'].extend(
                            open(fpath, 'r').readlines() if not is_rmd else
github stephenslab / dsc / src / __main__.py View on Github external
env.logger.error(
                    f'No help information is available for script {sys.argv[1]}: ``{e}``'
                )
                sys.exit(1)
    try:
        args, unknown_args = p.parse_known_args()
    except Exception as e:
        env.logger.error(e)
        env.logger.info("Please type ``{} -h`` to view available options".\
                        format(os.path.basename(sys.argv[0])))
        sys.exit(1)
    #
    env.verbosity = args.verbosity
    # keep `args.__recover__` to maintain backwards compatibility for `--touch` option.
    if args.__recover__:
        env.logger.warning(
            f'Option ``--touch`` is deprecated. Please use ``-s existing`` next time.'
        )
        args.__construct__ = 'existing'
    with Timer(verbose=True if (args.verbosity > 0) else False) as t:
        try:
            args.func(args, unknown_args)
        except KeyboardInterrupt:
            t.disable()
            sys.exit('KeyboardInterrupt')
        except Exception as e:
            if args.debug:
                raise
            if args.verbosity > 2:
                sys.stderr.write(get_traceback())
            t.disable()
            env.logger.error(e)
github vatlab / sos / src / sos / targets_r.py View on Github external
if ({package_loaded}) cur_version <- packageVersion(package) else cur_version <- NULL
            if (!is.null(cur_version) && {version_satisfied}) {{
                write(paste(package, cur_version, "AVAILABLE"), file={repr(output_file)})
            }} else {{
                write(paste(package, cur_version, "MISSING"), file={repr(output_file)})
            }}
            '''
        # temporarily change the run mode to run to execute script
        try:
            with open(script_file, 'w') as sfile:
                sfile.write(install_script)
            #
            p = subprocess.Popen(['Rscript', '--default-packages=utils', script_file])
            ret = p.wait()
            if ret != 0:
                env.logger.warning('Failed to detect or install R library')
                return False
        except Exception as e:
            env.logger.error(f'Failed to execute script: {e}')
            return False
        finally:
            os.remove(script_file)

        ret_val = False
        with open(output_file) as tmp:
            for line in tmp:
                lib, cur_version, status = line.split()
                if status.strip() == "MISSING":
                    env.logger.warning(
                        f'R Library {lib} is not available.')
                elif status.strip() == 'AVAILABLE':
                    env.logger.debug(f'R library {lib} ({cur_version}) is available')
github vatlab / sos-notebook / src / sos_notebook / magics.py View on Github external
})
        for line in ret.split('\n'):
            if not line.strip():
                continue
            try:
                # return creation time, start time, and duration
                tid, tst = line.split('\t')
                self.sos_kernel.send_frontend_msg(
                    'task_status', {
                        'update_only': True,
                        'queue': args.queue,
                        'task_id': tid,
                        'status': tst
                    })
            except Exception as e:
                env.logger.warning(
                    f'Unrecognized response "{line}" ({e.__class__.__name__}): {e}'
                )
github vatlab / sos / src / sos / PBS / sos_task.py View on Github external
def query_tasks(self, tasks=None, verbosity=1, html=False, start_time=True, age=None):
        if verbosity <= 2:
            status_lines = super(PBS_TaskEngine, self).query_tasks(tasks, verbosity, html, start_time, age=age)
            # there is a change that a job is submitted, but failed before the sos command is executed
            # so we will have to ask the task engine about the submitted jobs #608
            if not html:
                res = ''
                for line in status_lines.split('\n'):
                    if not line.strip():
                        continue
                    fields = line.split('\t')
                    if len(fields) < verbosity:
                        env.logger.error(fields)
                        env.logger.warning('Suspicious status line {}'.format(line))
                        continue
                    task_id = fields[0]
                    if fields[verbosity] == 'submitted':
                        try:
                            job_id = self._get_job_id(task_id)
                            if not job_id:
                                raise RuntimeError('failed to obtain job id for task {}'.format(task_id))
                            self._query_job_status(job_id, task_id)
                        except Exception as e:
                            env.logger.trace('Failed to query status for task {}: {}'.format(task_id, e))
                            fields[verbosity] = 'failed'
                    res += '\t'.join(fields) + '\n'
                return res
            else:
                # ID line: ID5173b80bf85d3d03153b96f9a5b4d6cc
                task_id = status_lines.split('>ID<', 1)[-1].split('')[-1]
github vatlab / sos / src / sos / targets_r.py View on Github external
quit("no")
                }}
            }} else {{
                if (!is.null(cur_version)) write(paste(package, cur_version, "VERSION_MISMATCH"), file={repr(output_file)}) else write(paste(package, cur_version, "UNAVAILABLE"), file={repr(output_file)})
            }}
            '''
        # temporarily change the run mode to run to execute script
        try:
            with open(script_file, 'w') as sfile:
                sfile.write(install_script)
            #
            p = subprocess.Popen(
                ['Rscript', '--default-packages=utils', script_file])
            ret = p.wait()
            if ret != 0:
                env.logger.warning(
                    f'Failed to detect or install R library {name}')
                return False
        except Exception as e:
            env.logger.error(f'Failed to execute script: {e}')
            return False
        finally:
            os.remove(script_file)

        ret_val = False
        with open(output_file) as tmp:
            for line in tmp:
                lib, cur_version, status = line.split(' ', 2)
                if status.strip() == "MISSING":
                    env.logger.error(
                        f'R library {lib} is not available and cannot be installed.'
                    )
github vatlab / sos-notebook / src / sos_notebook / kernel.py View on Github external
def update_existing(idx):
            x = self._kernel_list[idx]

            #  [Bash, some_sh, ....]
            # but the provided kernel does not match...
            if (kernel is not None and kernel != x.kernel):
                env.logger.warning(
                    f"Overriding kernel {x.kernel} used by subkernel {x.name} with kernel {kernel}."
                )
                self._kernel_list[idx].kernel = kernel
                if notify_frontend:
                    self.notify_frontend()
            #  similarly, identified by kernel but language names are different
            if language not in (None, '', 'None') and language != x.language:
                env.logger.warning(
                    f"Overriding language {x.language} used by subkernel {x.name} with language {language}."
                )
                self._kernel_list[idx].language = language
                if notify_frontend:
                    self.notify_frontend()
            if codemirror_mode:
                self._kernel_list[idx].codemirror_mode = codemirror_mode
            if color is not None:
github vatlab / sos / sos / sos_executor.py View on Github external
def dryrun(self, targets=None):
        '''Execute the script in dryrun mode.'''
        try:
            self.run(targets=targets, mode='dryrun')
        # only runtime errors are ignored
        except RuntimeError as e:
            env.logger.warning('Workflow cannot be completed in dryrun mode: {}'.format(e))