예제 #1
0
    def load_licenses(cls, product=None):
        """Load license files."""
        logger.debug(product)
        res = []
        # This is used instead of _license.find_licenses to have the path
        # for each file
        for license_path in cls.license_paths():
            try:
                licenses = _license.read_licenses(license_path)
            except Exception:
                logger.warning(
                    "Can't read licenses from folder {0}".format(license_path))
                licenses = []

            for lic in licenses:
                product_name = lic.get('product')
                product_filter = product == product_name if product else True
                if product_name in VALID_PRODUCT_LICENSES and product_filter:
                    valid = cls.is_valid_license(lic)
                    lic['__valid__'] = valid
                    lic['__status__'] = 'Valid' if valid else 'Invalid'
                    lic['__type__'] = lic.get('type', 'Enterprise').lower()
                    lic[LICENSE_PATH] = license_path
                    res.append(lic)
        return res
예제 #2
0
def py_in_console(activate=None, prog='python'):
    """
    Run (i)python in a new console, optionally running activate first
    on the given env name/path.
    """
    logger.debug("%s, %s", activate, prog)

    if not check_prog(prog, activate):
        logger.warning('Program not available in environment: %s, %s', prog,
                       activate)
        raise RuntimeError('Program not available in environment: %s, %s',
                           prog, activate)
    if prog == 'python':
        cmd = 'python -i'
    elif prog == 'ipython' or prog == 'jupyter console':
        cmd = 'ipython -i'
    elif prog == 'notebook' or prog == 'jupyter notebook':
        cmd = 'jupyter notebook'
    if os.name == 'nt':
        if activate:
            cmd = '"activate {} & {}"'.format(activate, cmd)
        else:
            cmd = '"{}"'.format(cmd)
        logger.debug('start cmd.exe /k ' + cmd)
        subprocess.Popen('start cmd.exe /k {}'.format(cmd), shell=True)
    elif sys.platform == 'darwin':
        if activate:
            if '/' not in activate:
                out = subprocess.check_output(['conda', 'env', 'list'])
                for line in out.decode().split('\n'):
                    if line and line.split()[0] == activate:
                        activate = line.split()[-1]
                        break
            cmd = activate + '/bin/' + cmd
        else:
            cmd = cmd
        fname = os.path.join(get_conf_path(), 'a.tool')
        open(fname, 'w').write(cmd)
        os.chmod(fname, 0o777)
        logger.debug('open ' + fname)
        subprocess.call(['open ' + fname], shell=True)
    else:  # Linux, solaris, etc
        if activate:
            run_cmd = "source activate " + activate + "; " + cmd
        try:
            run_cmd = ['gnome-terminal', '-x', 'bash', '-c', cmd]
            logger.debug(' '.join(run_cmd))
            subprocess.Popen(run_cmd)
            return
        except:
            pass
        try:
            run_cmd = ['xterm', '-e', cmd]
            logger.debug(' '.join(run_cmd))
            subprocess.Popen(run_cmd)
            return
        except:
            pass
예제 #3
0
 def remove_all_licenses(cls):
     """Remove all found licenses."""
     logger.debug('')
     paths = cls.license_paths()
     for path in paths:
         try:
             os.remove(path)
         except Exception:
             logger.warning('Could not remove license located at '
                            '{}'.format(path))
예제 #4
0
def loggerbot(qtbot, tmpfile):
    temp_log_folder = os.path.dirname(tmpfile)
    temp_log_filename = os.path.basename(tmpfile + '.log')

    setup_logger(log_level=logging.WARNING,
                 log_folder=temp_log_folder,
                 log_filename=temp_log_filename)
    logger.warning(TEST_TEXT)
    logger.warning(TEST_TEXT_EXTRA)
    widget = LogViewerDialog(log_folder=temp_log_folder,
                             log_filename=temp_log_filename)
    widget.show()
    qtbot.addWidget(widget)
    return qtbot, widget
예제 #5
0
    def remove_license(lic):
        """Remove license callback."""
        logger.debug(lic)
        path = lic.get(LICENSE_PATH)
        sig = lic.get('sig')

        with open(path) as f:
            licenses = json.load(f)

        for i, lic in enumerate(licenses):
            if lic.get('sig') == sig:
                break

        removed_license = licenses.pop(i)
        with open(path, 'w') as f:
            json.dump(licenses, f)

        head, tail = os.path.split(os.path.abspath(path))
        removed_folder = os.path.join(head, REMOVED_LICENSE_PATH)
        removed_path = os.path.join(removed_folder, tail)

        if not os.path.isdir(removed_folder):
            try:
                os.mkdir(removed_folder)
            except Exception:
                logger.warning('Could not create folder for removed licenses '
                               'at {}'.format(path))

        removed_licenses = [removed_license]
        if os.path.isfile(removed_path):
            # Merge removed files
            try:
                with open(removed_path) as f:
                    existing_removed_licenses = json.load(f)
                    removed_licenses.extend(existing_removed_licenses)
            except Exception:
                logger.warning('Could not remove license located at '
                               '{}'.format(removed_path))

        try:
            with open(removed_path, 'w') as f:
                json.dump(removed_licenses, f)
        except Exception:
            logger.warning('Could not store removed license on '
                           '{}'.format(removed_path))