How to use the commoncode.fileutils.file_base_name function in commoncode

To help you get started, we’ve selected a few commoncode 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 nexB / scancode-toolkit / tests / commoncode / test_fileutils.py View on Github external
def test_file_base_name_on_path_and_location_9(self):
        test_dir = self.get_test_loc('fileutils/basename')
        test_file = 'f.a/'
        expected_name = 'f.a'
        result = fileutils.file_base_name(test_file)
        assert expected_name == result
        result = fileutils.file_base_name((os.path.join(test_dir, test_file)))
        assert expected_name == result
github nexB / scancode-toolkit / tests / commoncode / test_fileutils.py View on Github external
def test_file_base_name_on_path_and_location_1(self):
        test_dir = self.get_test_loc('fileutils/basename')
        test_file = 'a/.a/file'
        expected_name = 'file'
        result = fileutils.file_base_name(test_file)
        assert expected_name == result
        result = fileutils.file_base_name((os.path.join(test_dir, test_file)))
        assert expected_name == result
github nexB / conan / tests / test_image_v11.py View on Github external
def test_load_image_config(self):
        test_dir = self.get_test_loc('images/config')
        expected_dir = self.get_test_loc('images/config_expected')
        for config_file in os.listdir(test_dir):
            base_name = fileutils.file_base_name(config_file)
            config_file = os.path.join(test_dir, config_file)
            image = Image.load_image_config(config_file)
            expected = os.path.join(expected_dir, base_name + '.expected.json')
            result = image.as_dict()
            check_expected(result, expected, regen=False)
github nexB / scancode-toolkit / tests / commoncode / test_fileutils.py View on Github external
def test_file_base_name_on_path_and_location_3(self):
        test_dir = self.get_test_loc('fileutils/basename')
        test_file = 'a/b/.a.b'
        expected_name = '.a'
        result = fileutils.file_base_name(test_file)
        assert expected_name == result
        result = fileutils.file_base_name((os.path.join(test_dir, test_file)))
        assert expected_name == result
github nexB / scancode-toolkit / tests / commoncode / test_fileutils.py View on Github external
def test_file_base_name_on_path_and_location_8(self):
        test_dir = self.get_test_loc('fileutils/basename')
        test_file = 'f.a/a.c'
        expected_name = 'a'
        result = fileutils.file_base_name(test_file)
        assert expected_name == result
        result = fileutils.file_base_name((os.path.join(test_dir, test_file)))
        assert expected_name == result
github nexB / scancode-toolkit / src / extractcode / uncompress.py View on Github external
def uncompress_file(location, decompressor):
    """
    Uncompress a compressed file at location and return a temporary location of
    the uncompressed file and a list of warning messages. Raise Exceptions on
    errors. Use the `decompressor` object for decompression.
    """
    # FIXME: do not create a sub-directory and instead strip the "compression"
    # extension such gz, etc. or introspect the archive header to get the file
    # name when present.
    assert location
    assert decompressor

    warnings = []
    base_name = fileutils.file_base_name(location)
    target_location = os.path.join(fileutils.get_temp_dir(prefix='scancode-extract-'), base_name)
    with decompressor(location, 'rb') as compressed:
        with open(target_location, 'wb') as uncompressed:
            buffer_size = 32 * 1024 * 1024
            while True:
                chunk = compressed.read(buffer_size)
                if not chunk:
                    break
                uncompressed.write(chunk)
        if getattr(decompressor, 'has_trailing_garbage', False):
            warnings.append(location + ': Trailing garbage found and ignored.')
    return target_location, warnings
github nexB / scancode-toolkit / src / formattedcode / format_templated.py View on Github external
def get_html_app_files_dirs(output_file):
    """
    Return a tuple of (parent_dir, dir_name) directory named after the
    `output_file` file object file_base_name (stripped from extension) and a
    `_files` suffix Return empty strings if output is to stdout.
    """
    if is_stdout(output_file):
        return '', ''

    file_name = output_file.name
    parent_dir = os.path.dirname(file_name)
    dir_name = fileutils.file_base_name(file_name) + '_files'
    return parent_dir, dir_name
github nexB / scancode-toolkit / src / formattedcode / output_html.py View on Github external
def get_html_app_files_dirs(output_file):
    """
    Return a tuple of (parent_dir, dir_name) directory named after the
    `output_file` file-like object file_base_name (stripped from extension) and
    a `_files` suffix Return empty strings if output is to stdout.
    """
    if is_stdout(output_file):
        return '', ''

    # FIXME: what if there is no name attribute??
    file_name = output_file.name
    parent_dir = dirname(file_name)
    dir_name = file_base_name(file_name) + '_files'
    return parent_dir, dir_name
github nexB / scancode-toolkit / src / scancode / resource.py View on Github external
def _get_or_create_parent(self, path, parent_by_path):
        """
        Return a parent resource for a given `path` from `parent_by_path`.

        If a parent resource for a `path` does not exist in `parent_by_path`, it is created recursively.

        Note: the root path and root Resource must already be in `parent_by_path` or else this
        function does not work.
        """
        parent_path = parent_directory(path).rstrip('/').rstrip('\\')
        existing_parent = parent_by_path.get(parent_path)
        if existing_parent:
            return existing_parent
        parent_parent = self._get_or_create_parent(parent_path, parent_by_path)
        parent_name = file_base_name(parent_path)
        parent_is_file = False
        parent_resource_data = self._create_empty_resource_data()
        parent_resource = self._create_resource(parent_name, parent_parent, parent_is_file, parent_path, parent_resource_data)
        parent_by_path[parent_path] = parent_resource
        return parent_resource