Python os.name() Examples

The following are 30 code examples of os.name(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module os , or try the search function .
Example #1
Source File: get_data.py    From dynamic-training-with-apache-mxnet-on-aws with Apache License 2.0 10 votes vote down vote up
def get_cifar10(data_dir):
    if not os.path.isdir(data_dir):
        os.system("mkdir " + data_dir)
    cwd = os.path.abspath(os.getcwd())
    os.chdir(data_dir)
    if (not os.path.exists('train.rec')) or \
       (not os.path.exists('test.rec')) :
        import urllib, zipfile, glob
        dirname = os.getcwd()
        zippath = os.path.join(dirname, "cifar10.zip")
        urllib.urlretrieve("http://data.mxnet.io/mxnet/data/cifar10.zip", zippath)
        zf = zipfile.ZipFile(zippath, "r")
        zf.extractall()
        zf.close()
        os.remove(zippath)
        for f in glob.glob(os.path.join(dirname, "cifar", "*")):
            name = f.split(os.path.sep)[-1]
            os.rename(f, os.path.join(dirname, name))
        os.rmdir(os.path.join(dirname, "cifar"))
    os.chdir(cwd)

# data 
Example #2
Source File: os_utils.py    From godot-mono-builds with MIT License 9 votes vote down vote up
def run_command(command, args=[], cwd=None, env=None, name='command'):
    def cmd_args_to_str(cmd_args):
        return ' '.join([arg if not ' ' in arg else '"%s"' % arg for arg in cmd_args])

    assert isinstance(command, str) and isinstance(args, list)
    args = [command] + args

    check_call_args = {}
    if cwd is not None:
        check_call_args['cwd'] = cwd
    if env is not None:
        check_call_args['env'] = env

    import subprocess
    try:
        print('Running command \'%s\': %s' % (name, subprocess.list2cmdline(args)))
        subprocess.check_call(args, **check_call_args)
        print('Command \'%s\' completed successfully' % name)
    except subprocess.CalledProcessError as e:
        raise BuildError('\'%s\' exited with error code: %s' % (name, e.returncode)) 
Example #3
Source File: __init__.py    From pyhanlp with Apache License 2.0 6 votes vote down vote up
def write_config(root=None):
    if root and os.name == 'nt':
        root = root.replace('\\', '/')  # For Windows
    if root and platform.system().startswith('CYGWIN'):  # For cygwin
        if root.startswith('/usr/lib'):
            cygwin_root = os.popen('cygpath -w /').read().strip().replace('\\', '/')
            root = cygwin_root + root[len('/usr'):]
        elif STATIC_ROOT.startswith('/cygdrive'):
            driver = STATIC_ROOT.split('/')
            cygwin_driver = '/'.join(driver[:3])
            win_driver = driver[2].upper() + ':'
            root = root.replace(cygwin_driver, win_driver)
    content = []
    with open_(PATH_CONFIG, encoding='utf-8') as f:
        for line in f:
            if root:
                if line.startswith('root'):
                    line = 'root={}{}'.format(root, os.linesep)
            content.append(line)
    with open_(PATH_CONFIG, 'w', encoding='utf-8') as f:
        f.writelines(content) 
Example #4
Source File: test_states.py    From cherrypy with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_SIGTERM(self):
        'SIGTERM should shut down the server whether daemonized or not.'
        self._require_signal_and_kill('SIGTERM')

        # Spawn a normal, undaemonized process.
        p = helper.CPProcess(ssl=(self.scheme.lower() == 'https'))
        p.write_conf(
            extra='test_case_name: "test_SIGTERM"')
        p.start(imports='cherrypy.test._test_states_demo')
        # Send a SIGTERM
        os.kill(p.get_pid(), signal.SIGTERM)
        # This might hang if things aren't working right, but meh.
        p.join()

        if os.name in ['posix']:
            # Spawn a daemonized process and test again.
            p = helper.CPProcess(ssl=(self.scheme.lower() == 'https'),
                                 wait=True, daemonize=True)
            p.write_conf(
                extra='test_case_name: "test_SIGTERM_2"')
            p.start(imports='cherrypy.test._test_states_demo')
            # Send a SIGTERM
            os.kill(p.get_pid(), signal.SIGTERM)
            # This might hang if things aren't working right, but meh.
            p.join() 
Example #5
Source File: display.py    From vergeml with MIT License 6 votes vote down vote up
def getvalue(self):
        
        title_row = [""]
        title_row.extend(self.titles)
        cat_rows = []
       

        for cat in self.cats:
            row = [cat]
            for title in self.titles:
                name, fmt = self.by_cat[cat][title]
                if name in self.data:
                    value = self.data[name]
                    fmt = "{:" +  fmt.lstrip("{").rstrip("}").lstrip(":") + "}"
                    row.append(fmt.format(value))
                else:
                    row.append("-")
            cat_rows.append(row)
        
        data = [title_row] + cat_rows
      
        t = Table(data, left_align=self.left_align)
        return t.getvalue(fit=False) + "\n" 
Example #6
Source File: utilities.py    From svviz with MIT License 6 votes vote down vote up
def launchFile(filepath):
    if sys.platform.startswith('darwin'):
        subprocess.call(('open', filepath))
    elif os.name == 'nt':
        os.startfile(filepath)
    elif os.name == 'posix':
        subprocess.call(('xdg-open', filepath))


############################ String utilities ############################ 
Example #7
Source File: os_utils.py    From godot-mono-builds with MIT License 6 votes vote down vote up
def find_executable(name) -> str:
    is_windows = os.name == 'nt'
    windows_exts = os.environ['PATHEXT'].split(ENV_PATH_SEP) if is_windows else None
    path_dirs = os.environ['PATH'].split(ENV_PATH_SEP)

    search_dirs = path_dirs + [os.getcwd()] # cwd is last in the list

    for dir in search_dirs:
        path = os.path.join(dir, name)

        if is_windows:
            for extension in windows_exts:
                path_with_ext = path + extension

                if os.path.isfile(path_with_ext) and os.access(path_with_ext, os.X_OK):
                    return path_with_ext
        else:
            if os.path.isfile(path) and os.access(path, os.X_OK):
                return path

    return '' 
Example #8
Source File: download.py    From gog-galaxy-plugin-downloader with GNU General Public License v3.0 6 votes vote down vote up
def process_template_strings(data):
    """
    Replaces $variables in strings with corresponding variables in plugin data
    """
    for plugin_name, plugin_data in data.items():
        version = plugin_data['version']
        guid = plugin_data['guid']

        for key, value in plugin_data.items():
            if key == 'version':
                continue
            if not isinstance(value, str):
                continue

            # Replace references to $name and $version with the real values
            data[plugin_name][key] = Template(value).substitute(
                                        name=plugin_name,
                                        version=version,
                                        guid=guid)

    return data 
Example #9
Source File: display.py    From vergeml with MIT License 6 votes vote down vote up
def __init__(self, conf, width=70, pad=4, left_align=set()):
        self.conf = conf
        self.data = {}
        self.width = width
        self.pad = pad
        self.left_align = left_align

        self.by_cat = {}
        self.cats = []
        self.titles = []

        for item in self.conf:
            self.by_cat.setdefault(item['category'], {})

            if not item['category'] in self.cats:
                self.cats.append(item['category'])

            if not item['title'] in self.titles:
                self.titles.append(item['title'])
            
            self.by_cat[item['category']][item['title']] = (item['name'], item['format']) 
Example #10
Source File: mkl_fft.py    From FRIDA with MIT License 6 votes vote down vote up
def load_libmkl():
    if os.name == 'posix':
        try:
            lib_mkl = os.getenv('LIBMKL')
            return _ctypes.cdll.LoadLibrary(lib_mkl)
        except:
            pass
        try:
            return _ctypes.cdll.LoadLibrary("libmkl_rt.dylib")
        except:
            raise ValueError('MKL Library not found')

    else:
        try:
            return _ctypes.cdll.LoadLibrary("mk2_rt.dll")
        except:
            raise ValueError('MKL Library not found') 
Example #11
Source File: analysis_mg.py    From CAMISIM with Apache License 2.0 6 votes vote down vote up
def parse(self, line):
        lineArray = line.split()
        if len(lineArray) != 2:
            print '_MothurOutFileParser: wrong line', line
            return
        name = re.sub(r'^([0-9]+_[0-9]+)_[0-9]+_[0-9]+_[pr]+[0-2]$',r'\1', lineArray[0])
        tag = re.sub(r'^[0-9]+_[0-9]+_([0-9]+_[0-9]+_[pr]+[0-2])$',r'\1', lineArray[0])
        placementList = lineArray[1].replace('unclassified;', '').rsplit(';')
        if len(placementList) < 2:
            #print '_MothurOutFileParser: skip line', line
            return

        placement = placementList[-2]
        try:
            clade = int(re.sub('([0-9]+)\(.*', r'\1' , placement))
        except ValueError:
            return
        weight = float(re.sub('[0-9]+\(([0-9\.]+)\)', r'\1' , placement))

        entry = str(str(name) + '\t' + str(clade) + '\t' + str(weight) + '\t' + str(self.source) + '\t' + str(tag))
        if self.outBuffer.isEmpty():
            self.outBuffer.writeText(entry)
        else:
            self.outBuffer.writeText(str('\n' + entry)) 
Example #12
Source File: pastebin_crawler.py    From pastebin-monitor with GNU General Public License v2.0 6 votes vote down vote up
def log ( self, message, is_bold=False, color='', log_time=True):
        prefix = ''
        suffix = ''

        if log_time:
            prefix += '[{:s}] '.format(get_timestamp())

        if os.name == 'posix':
            if is_bold:
                prefix += self.shell_mod['BOLD']
            prefix += self.shell_mod[color.upper()]

            suffix = self.shell_mod['RESET']

        message = prefix + message + suffix
        print ( message )
        sys.stdout.flush() 
Example #13
Source File: lint.py    From dynamic-training-with-apache-mxnet-on-aws with Apache License 2.0 6 votes vote down vote up
def get_header_guard_dmlc(filename):
    """Get Header Guard Convention for DMLC Projects.
    For headers in include, directly use the path
    For headers in src, use project name plus path
    Examples: with project-name = dmlc
        include/dmlc/timer.h -> DMLC_TIMTER_H_
        src/io/libsvm_parser.h -> DMLC_IO_LIBSVM_PARSER_H_
    """
    fileinfo = cpplint.FileInfo(filename)
    file_path_from_root = fileinfo.RepositoryName()
    inc_list = ['include', 'api', 'wrapper']

    if file_path_from_root.find('src/') != -1 and _HELPER.project_name is not None:
        idx = file_path_from_root.find('src/')
        file_path_from_root = _HELPER.project_name +  file_path_from_root[idx + 3:]
    else:
        for spath in inc_list:
            prefix = spath + os.sep
            if file_path_from_root.startswith(prefix):
                file_path_from_root = re.sub('^' + prefix, '', file_path_from_root)
                break
    return re.sub(r'[-./\s]', '_', file_path_from_root).upper() + '_' 
Example #14
Source File: utilities.py    From svviz with MIT License 6 votes vote down vote up
def __init__(self, chr_, start, end, strand):
        """
        :param chr: chromosome name (string)
        :param strand: '+' or '-' (or '.' for an ambidexterous locus)
        :param start: start coordinate of the locus
        :param end: coord of the last nucleotide (inclusive) """
        coords = [start,end]
        coords.sort()
        # this method for assigning chromosome should help avoid storage of
        # redundant strings.
        self._chr = chr_
        self._strand = strand
        self._start = int(coords[0])
        self._end = int(coords[1])

        if self._start < 0:
            raise Exception("Locus start coordinate cannot be negative: {}".format(start)) 
Example #15
Source File: cli.py    From quart with MIT License 6 votes vote down vote up
def get_command(self, ctx: click.Context, name: str) -> click.Command:
        """Return the relevant command given the context and name.

        .. warning::

            This differs substantially from Flask in that it allows
            for the inbuilt commands to be overridden.
        """
        info = ctx.ensure_object(ScriptInfo)
        command = None
        try:
            command = info.load_app().cli.get_command(ctx, name)
        except NoAppException:
            pass
        if command is None:
            command = super().get_command(ctx, name)
        return command 
Example #16
Source File: freeze.py    From wuy with GNU General Public License v2.0 6 votes vote down vote up
def build(path,inConsole=False,addWeb=False):
    params=[path,"--noupx","--onefile"]

    if not inConsole:
        params.append( "--noconsole")
    
    web=os.path.join( os.path.dirname(path), "web" )
    if addWeb and os.path.isdir(web):
        sep = (os.name == 'nt') and ";" or ":"
        params.append("--add-data=%s%sweb" % (web,sep))

    temp=os.path.join(tempfile.gettempdir(),".build")
    params.append( "--workpath" )
    params.append( temp )

    params.append( "--distpath" )
    params.append( os.path.dirname(path) )

    print( "PYINSTALLER:",params )
    pyi.run( params ) 
Example #17
Source File: test_smbclient_os.py    From smbprotocol with MIT License 6 votes vote down vote up
def test_walk_bottomup(smb_share):
    smbclient.makedirs("%s\\dir1\\dir2\\dir3" % smb_share)

    for name in ["file1.txt", "dir1\\file2.txt", "dir1\\dir2\\file3.txt", "dir1\\dir2\\dir3\\file4.txt"]:
        with smbclient.open_file("%s\\%s" % (smb_share, name), mode='w') as fd:
            fd.write(u"content")

    scanned_files = []
    scanned_dirs = []
    for root, dirs, files in smbclient.walk(smb_share, topdown=False):
        if dirs:
            scanned_dirs.append(dirs[0])
        scanned_files.append(files[0])

    assert scanned_files == ['file4.txt', 'file3.txt', 'file2.txt', 'file1.txt']
    assert scanned_dirs == ['dir3', 'dir2', 'dir1'] 
Example #18
Source File: test_smbclient_os.py    From smbprotocol with MIT License 6 votes vote down vote up
def test_walk_topdown(smb_share):
    smbclient.makedirs("%s\\dir1\\dir2\\dir3" % smb_share)

    for name in ["file1.txt", "dir1\\file2.txt", "dir1\\dir2\\file3.txt", "dir1\\dir2\\dir3\\file4.txt"]:
        with smbclient.open_file("%s\\%s" % (smb_share, name), mode='w') as fd:
            fd.write(u"content")

    scanned_files = []
    scanned_dirs = []
    for root, dirs, files in smbclient.walk(smb_share):
        scanned_dirs.append(dirs[0])

        # Test out removing a dir entry will affect the further walks.
        if files == ['file3.txt']:
            del dirs[0]
        scanned_files.append(files[0])

    assert scanned_files == ['file1.txt', 'file2.txt', 'file3.txt']
    assert scanned_dirs == ['dir1', 'dir2', 'dir3'] 
Example #19
Source File: test_smbclient_os.py    From smbprotocol with MIT License 6 votes vote down vote up
def test_scandir_with_symlink(smb_share):
    with smbclient.open_file("%s\\file.txt" % smb_share, mode='w') as fd:
        fd.write(u"content")
    smbclient.symlink("%s\\file.txt" % smb_share, "%s\\link.txt" % smb_share)

    smbclient.mkdir("%s\\dir" % smb_share)
    smbclient.symlink("%s\\dir" % smb_share, "%s\\link-dir" % smb_share, target_is_directory=True)

    for entry in smbclient.scandir(smb_share):
        # This is tested in other tests, we only care about symlinks.
        if entry.name in ['file.txt', 'dir']:
            continue

        assert entry.is_symlink()
        assert entry.is_dir(follow_symlinks=False) is False
        assert entry.is_file(follow_symlinks=False) is False

        if entry.name == 'link.txt':
            assert entry.is_dir() is False
            assert entry.is_file() is True
        else:
            assert entry.is_dir() is True
            assert entry.is_file() is False 
Example #20
Source File: test_smbclient_os.py    From smbprotocol with MIT License 6 votes vote down vote up
def test_scamdir_with_pattern(smb_share):
    for filename in ["file.txt", "file-test1.txt", "file-test1a.txt"]:
        with smbclient.open_file("%s\\%s" % (smb_share, filename), mode="w") as fd:
            fd.write(u"content")

    count = 0
    names = []
    for dir_entry in smbclient.scandir(smb_share, search_pattern="file-test*.txt"):
        names.append(dir_entry.name)
        count += 1

    assert count == 2
    assert "file-test1.txt" in names
    assert "file-test1a.txt" in names

    names = []
    for dir_entry in smbclient.scandir(smb_share, search_pattern="file-test?.txt"):
        names.append(dir_entry.name)

    assert names == ["file-test1.txt"] 
Example #21
Source File: test_smbclient_shutil.py    From smbprotocol with MIT License 6 votes vote down vote up
def test_rmtree(smb_share):
    mkdir("%s\\dir2" % smb_share)
    mkdir("%s\\dir2\\dir3" % smb_share)

    with open_file("%s\\dir2\\dir3\\file1" % smb_share, mode='w') as fd:
        fd.write(u"content")

    with open_file("%s\\dir2\\file2" % smb_share, mode='w') as fd:
        fd.write(u"content")

    if os.name == "nt" or os.environ.get('SMB_FORCE', False):
        # File symlink
        symlink("%s\\dir2\\file2" % smb_share, "%s\\dir2\\file3" % smb_share)
        symlink("missing", "%s\\dir2\\file3-broken" % smb_share)

        # Dir symlink
        symlink("%s\\dir2\\dir3" % smb_share, "%s\\dir2\\dir-link" % smb_share)
        symlink("missing", "%s\\dir2\\dir-link-broken" % smb_share, target_is_directory=True)

    assert exists("%s\\dir2" % smb_share) is True

    rmtree("%s\\dir2" % smb_share)

    assert exists("%s\\dir2" % smb_share) is False 
Example #22
Source File: lint.py    From dynamic-training-with-apache-mxnet-on-aws with Apache License 2.0 6 votes vote down vote up
def get_header_guard_dmlc(filename):
    """Get Header Guard Convention for DMLC Projects.

    For headers in include, directly use the path
    For headers in src, use project name plus path

    Examples: with project-name = dmlc
        include/dmlc/timer.h -> DMLC_TIMTER_H_
        src/io/libsvm_parser.h -> DMLC_IO_LIBSVM_PARSER_H_
    """
    fileinfo = cpplint.FileInfo(filename)
    file_path_from_root = fileinfo.RepositoryName()
    inc_list = ['include', 'api', 'wrapper']

    if file_path_from_root.find('src/') != -1 and _HELPER.project_name is not None:
        idx = file_path_from_root.find('src/')
        file_path_from_root = _HELPER.project_name +  file_path_from_root[idx + 3:]
    else:
        for spath in inc_list:
            prefix = spath + os.sep
            if file_path_from_root.startswith(prefix):
                file_path_from_root = re.sub('^' + prefix, '', file_path_from_root)
                break
    return re.sub(r'[-./\s]', '_', file_path_from_root).upper() + '_' 
Example #23
Source File: freeze.py    From wuy with GNU General Public License v2.0 5 votes vote down vote up
def list(self,path):
        np=lambda x: os.path.realpath(os.path.join(path,x))
        ll=[ dict(name="..",isdir=True, path=np("..")) ]
        try:
            ll.extend( [dict(name=i,isdir=os.path.isdir( np(i) ),path=np(i)) for i in os.listdir(path)] )
            ll=list(filter(lambda x: x["isdir"] or x["name"].lower().endswith(".py"),ll))
        except PermissionError:
            pass
        return ll 
Example #24
Source File: test_states.py    From cherrypy with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_signal_handler_unsubscribe(self):
        self._require_signal_and_kill('SIGTERM')

        # Although Windows has `os.kill` and SIGTERM is defined, the
        #  platform does not implement signals and sending SIGTERM
        #  will result in a forced termination of the process.
        #  Therefore, this test is not suitable for Windows.
        if os.name == 'nt':
            self.skip('SIGTERM not available')

        # Spawn a normal, undaemonized process.
        p = helper.CPProcess(ssl=(self.scheme.lower() == 'https'))
        p.write_conf(
            extra="""unsubsig: True
test_case_name: "test_signal_handler_unsubscribe"
""")
        p.start(imports='cherrypy.test._test_states_demo')
        # Ask the process to quit
        os.kill(p.get_pid(), signal.SIGTERM)
        # This might hang if things aren't working right, but meh.
        p.join()

        # Assert the old handler ran.
        log_lines = list(open(p.error_log, 'rb'))
        assert any(
            line.endswith(b'I am an old SIGTERM handler.\n')
            for line in log_lines
        ) 
Example #25
Source File: test_io_processes.py    From fastteradata with MIT License 5 votes vote down vote up
def test_combine_partitioned_files_valid_remove():
    import os
    if os.name == "nt":
        assert valid_rm_cmd_windows == remove_cmd
    else:
        assert valid_rm_cmd_linux == remove_cmd 
Example #26
Source File: test_io_processes.py    From fastteradata with MIT License 5 votes vote down vote up
def test_combine_partitioned_files_valid_concat():
    import os
    if os.name == "nt":
        assert valid_concat_str_windows == concat_str
    else:
        assert valid_concat_str_linux == concat_str 
Example #27
Source File: api.py    From fastteradata with MIT License 5 votes vote down vote up
def load_table(abs_path, df, table_name, env, db, connector = "teradata", clear_table=True):


    if not os.path.isdir(f"{abs_path}/data_loading"):
        os.makedirs(f"{abs_path}/data_loading")
    if not os.path.isdir(f"{abs_path}/data_loading_scripts"):
        os.makedirs(f"{abs_path}/data_loading_scripts")

    file_delim = ""
    if os.name == "nt":
        file_delim = "\\"
    else:
        file_delim = "/"

    f, _ = generate_fastload_script(abs_path, df, table_name, env, db)

    prep_load_table(df, table_name, env, db, connector, clear_table)

    df.to_csv(f"{abs_path}{file_delim}data_loading{file_delim}{table_name}.csv", sep="|", index=False)

    import subprocess
    print(f"Calling Fast Load on file...  {f}")
    subprocess.call(f"fastload < {f}", shell=True)



    return 
Example #28
Source File: download.py    From gog-galaxy-plugin-downloader with GNU General Public License v3.0 5 votes vote down vote up
def fix_plugin_directories(dest):
    """
    Loops through all folders in the output directory, reads the their manifest
    file, and renames the directory to the standard <platform>_<guid> format
    """
    # Loop through directories in the destination directory
    for existing_dir in os.listdir(dest):
        existing_path = os.path.join(dest, existing_dir)

        # Skip non-directories
        if not os.path.isdir(existing_path):
            continue

        try:
            with open(os.path.join(existing_path, 'manifest.json')) as m:
                data = json.load(m)
                platform = data['platform']
                guid = data['guid']

                # Close json file
                m.close()

                expected_dir = platform + '_' + guid
                expected_path = os.path.join(dest, expected_dir)

                if existing_path != expected_path:
                    print('NOTICE: Folder should be "{}", but it is named "{}"'
                          .format(expected_dir, existing_dir))

                    if os.path.isdir(expected_path):
                        print('NOTICE: Correct pathed plugin already exists,'
                              + ' deleting extra plugin')
                        shutil.rmtree(existing_path)
                    else:
                        print('NOTICE: Renaming folder to proper name')
                        shutil.move(existing_path, expected_path)
        except (FileNotFoundError, json.decoder.JSONDecodeError, KeyError):
            print('ERROR: Could not read plugin data from {} folder'
                  .format(existing_path)) 
Example #29
Source File: test_smbclient_os.py    From smbprotocol with MIT License 5 votes vote down vote up
def test_read_byte_file(smb_share):
    file_path = "%s\\%s" % (smb_share, "file.txt")
    file_contents = b"\x00\x01\x02\x03"

    expected = "[NtStatus 0xc0000034] No such file or directory"
    with pytest.raises(SMBOSError, match=re.escape(expected)):
        smbclient.open_file(file_path, mode='rb')

    with smbclient.open_file(file_path, mode='wb') as fd:
        fd.write(file_contents)

    with smbclient.open_file(file_path, mode='rb') as fd:
        assert isinstance(fd, io.BufferedReader)
        assert fd.closed is False
        assert fd.name == file_path

        actual = fd.read()
        assert actual == file_contents

        actual = fd.read()
        assert actual == b""

        fd.seek(0)
        actual = fd.read()
        assert actual == file_contents

        with pytest.raises(IOError):
            fd.write(b"Fail")
    assert fd.closed 
Example #30
Source File: download.py    From gog-galaxy-plugin-downloader with GNU General Public License v3.0 5 votes vote down vote up
def delete_old_plugins(data, dest):
    """
    Deletes versions of plugins that don't match the yaml manifest. In theory
    this should only be older versions, but any version that doesn't match
    the yaml definition will be deleted

    This explicitly does not touch other directories that do not match the
    known plugin names.

    If the version doesn't match the yaml definition, the directory is removed
    """
    # Loop over each plugin
    for name, data in data.items():
        expected_plugin_dir = name + '_' + data['guid']

        # Loop through directories in the destination directory
        for item in os.listdir(dest):
            full_path = os.path.join(dest, item)

            # Skip non-directories
            if not os.path.isdir(full_path):
                continue

            # Skip directory names that are in the valid plugin directory array
            if item == expected_plugin_dir:
                continue

            # If any other directory begins with <plugin_name>_, delete it
            if item.startswith(name + '_'):
                print('Deleting wrong version "{}" from "{}"'
                      .format(item, dest))
                shutil.rmtree(full_path)