From 36ff40f8c7e0576b413ddedb130a8a72275162ff Mon Sep 17 00:00:00 2001 From: Meet Soni <92802561+inosmeet@users.noreply.github.com> Date: Fri, 16 Aug 2024 23:04:37 +0530 Subject: [PATCH] refactor: renamed data directory to mismatch_data (#4356) * fixes #4350 Signed-off-by: Meet Soni --- cve_bin_tool/mismatch_loader.py | 2 +- doc/mismatch_cli.md | 10 +++++----- doc/mismatch_data.md | 10 +++++----- mismatch/cli.py | 2 +- .../pypi/zstandard/mismatch_relations.yml | 0 test/test_mismatch_cli.py | 2 +- test/test_mismatch_loader.py | 2 +- 7 files changed, 14 insertions(+), 14 deletions(-) rename {data => mismatch_data}/pypi/zstandard/mismatch_relations.yml (100%) diff --git a/cve_bin_tool/mismatch_loader.py b/cve_bin_tool/mismatch_loader.py index 6cade9fb6e..88526f5823 100644 --- a/cve_bin_tool/mismatch_loader.py +++ b/cve_bin_tool/mismatch_loader.py @@ -24,7 +24,7 @@ db_path = DISK_LOCATION_DEFAULT / DBNAME parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -data_dir = os.path.join(parent_dir, "data") +data_dir = os.path.join(parent_dir, "mismatch_data") def setup_sqlite(data_dir: str, db_file: str) -> bool: diff --git a/doc/mismatch_cli.md b/doc/mismatch_cli.md index 45b48b9973..e37c395a37 100644 --- a/doc/mismatch_cli.md +++ b/doc/mismatch_cli.md @@ -22,7 +22,7 @@ The script operates within a specific directory structure as shown below: ``` project_root/ │ -├── data/ # Directory containing the mismatch relations +├── mismatch_data/ # Directory containing the mismatch relations │ └── mismatch/ # Directory containing the script └── cli.py # The main script file @@ -30,14 +30,14 @@ project_root/ ## Data Directory -The `data/` directory is a key component of the Mismatch Database Management Tool. It houses the structured data files that are used to populate or refresh the mismatch database. +The `mismatch_data/` directory is a key component of the Mismatch Database Management Tool. It houses the structured data files that are used to populate or refresh the mismatch database. ### Directory Structure -The structure of the `data/` directory is organized as follows: +The structure of the `mismatch_data/` directory is organized as follows: ``` -data/ +mismatch_data/ └── namespace/ └── product/ └── mismatch_relations.yml @@ -95,7 +95,7 @@ python -m mismatch.cli loader [--dir ] [--database ] ``` **Parameters:** -- `--dir`: (Optional) Directory containing the data files to be loaded. Defaults to the \`data/\` directory in the project root. +- `--dir`: (Optional) Directory containing the data files to be loaded. Defaults to the `mismatch_data/` directory in the project root. - `--database`: (Optional) Path to the SQLite database file. Defaults to the pre-configured location if not provided. **Example:** diff --git a/doc/mismatch_data.md b/doc/mismatch_data.md index 1e8393bf1c..69d9f4b3fc 100644 --- a/doc/mismatch_data.md +++ b/doc/mismatch_data.md @@ -5,9 +5,9 @@ database. This document details the steps for adding data to the mismatch database. -## 1. Update `data/` directory +## 1. Update `mismatch_data/` directory -1. Make a new file with `namespace/product_name/mismatch_relations.yml` name under the `data/` directory. For example, `pypi/zstandard/mismatch_relations.yml` for zstandard +1. Make a new file with `namespace/product_name/mismatch_relations.yml` name under the `mismatch_data/` directory. For example, `pypi/zstandard/mismatch_relations.yml` for zstandard from pypi namespace. 2. Populate the file with `purl-invalid_vendor` information. @@ -20,13 +20,13 @@ from pypi namespace. ## 2. Run the populator script -The [`mismatch_loader`](../cve_bin_tool/mismatch_loader.py) script populates the the mismatch database with the contents of `data/` directory. +The [`mismatch_loader`](../cve_bin_tool/mismatch_loader.py) script populates the the mismatch database with the contents of `mismatch_data/` directory. ```python python -m cve_bin_tool.mismatch_loader ``` -The default directory is `data/`, and default database file is `cve.db`. +The default directory is `mismatch_data/`, and default database file is `cve.db`. To use a specific directory, use `--dir` flag: ```python @@ -43,5 +43,5 @@ To use a specific database file, use `--database` flag: If you find invalid relationship, please do following: - Fork the [repo](https://github.com/intel/cve-bin-tool) -- Update the `data/` directory with purl-invalid_vendor information like [this](../data/pypi/zstandard/mismatch_relations.yml) +- Update the `mismatch_data/` directory with purl-invalid_vendor information like [this](../data/pypi/zstandard/mismatch_relations.yml) - Create a pull request with the details of update. [Reference](https://github.com/intel/cve-bin-tool/pull/4239) diff --git a/mismatch/cli.py b/mismatch/cli.py index 081e2ba64d..3c00915461 100644 --- a/mismatch/cli.py +++ b/mismatch/cli.py @@ -8,7 +8,7 @@ DBNAME = "cve.db" DISK_LOCATION_DEFAULT = Path("~").expanduser() / ".cache" / "cve-bin-tool" parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -data_dir = os.path.join(parent_dir, "data") +data_dir = os.path.join(parent_dir, "mismatch_data") dbpath = DISK_LOCATION_DEFAULT / DBNAME diff --git a/data/pypi/zstandard/mismatch_relations.yml b/mismatch_data/pypi/zstandard/mismatch_relations.yml similarity index 100% rename from data/pypi/zstandard/mismatch_relations.yml rename to mismatch_data/pypi/zstandard/mismatch_relations.yml diff --git a/test/test_mismatch_cli.py b/test/test_mismatch_cli.py index e43a384c07..d21ea81e89 100644 --- a/test/test_mismatch_cli.py +++ b/test/test_mismatch_cli.py @@ -54,7 +54,7 @@ def test_lookup(capsys, monkeypatch, test_db): def test_loader(monkeypatch, tmpdir, test_db): # Test with custom directory and database path using the --dir and --database flags - data_dir = Path(__file__).resolve().parent.parent / "data" + data_dir = Path(__file__).resolve().parent.parent / "mismatch_data" monkeypatch.setattr( "sys.argv", ["main", "loader", "--dir", str(data_dir), "--database", test_db] ) diff --git a/test/test_mismatch_loader.py b/test/test_mismatch_loader.py index 5b088fb48d..0c9a4d8f71 100644 --- a/test/test_mismatch_loader.py +++ b/test/test_mismatch_loader.py @@ -11,7 +11,7 @@ def test_mismatch_loader(): temp_db = tempfile.NamedTemporaryFile(suffix=".db", delete=False) temp_db_path = Path(temp_db.name) - data_dir = Path(__file__).resolve().parent.parent / "data" + data_dir = Path(__file__).resolve().parent.parent / "mismatch_data" setup_sqlite(data_dir, temp_db_path) # Connect to the database and check if zstandard is present