def clean(outputdir, drivers=None):
    """Remove driver executables from the specified outputdir.

    drivers can be a list of drivers to filter which executables
    to remove. Specify a version using an equal sign i.e.: 'chrome=2.2'
    """
    if drivers:
        # Generate a list of tuples: [(driver_name, requested_version)]
        # If driver string does not contain a version, the second element
        # of the tuple is None.
        # Example:
        # [('driver_a', '2.2'), ('driver_b', None)]
        drivers_split = [helpers.split_driver_name_and_version(x) for x in
                         drivers]
        file_data = [(helpers.normalize_driver_name(x[0]), x[1]) for x in
                     drivers_split]
    else:
        file_data = [(x, None) for x in config.ALL_DRIVERS]

    files = [file for file in os.listdir(outputdir)
             if os.path.isfile(os.path.join(outputdir, file))]
    for file in files:
        for data in file_data:
            prefix, version = data
            starts_with = file.startswith(prefix)
            version_match = 'N/A'
            if version is not None:
                file_version = helpers.extract_version_from_filename(file)
                if file_version == version:
                    version_match = True
                else:
                    version_match = False
            if starts_with and version_match in [True, 'N/A']:
                filepath = os.path.join(outputdir, file)
                try:
                    os.remove(filepath)
                except OSError:
                    pass
                finally:
                    logger.info('removed {}'.format(file))
                    break
def clean ( outputdir , drivers = None ) : if drivers : drivers_split = [ helpers . split_driver_name_and_version ( x ) for x in drivers ] file_data = [ ( helpers . normalize_driver_name ( x [ 0 ] ) , x [ 1 ] ) for x in drivers_split ] else : file_data = [ ( x , None ) for x in config . ALL_DRIVERS ] files = [ file for file in os . listdir ( outputdir ) if os . path . isfile ( os . path . join ( outputdir , file ) ) ] for file in files : for data in file_data : prefix , version = data starts_with = file . startswith ( prefix ) version_match = 'N/A' if version is not None : file_version = helpers . extract_version_from_filename ( file ) if file_version == version : version_match = True else : version_match = False if starts_with and version_match in [ True , 'N/A' ] : filepath = os . path . join ( outputdir , file ) try : os . remove ( filepath ) except OSError : pass finally : logger . info ( 'removed {}' . format ( file ) ) break
Remove driver executables from the specified outputdir.

    drivers can be a list of drivers to filter which executables
    to remove. Specify a version using an equal sign i.e.: 'chrome=2.2'