Skip to content

Commit

Permalink
refactor: renamed data directory to mismatch_data (intel#4356)
Browse files Browse the repository at this point in the history
* fixes intel#4350

Signed-off-by: Meet Soni <meetsoni3017@gmail.com>
  • Loading branch information
inosmeet authored Aug 16, 2024
1 parent bceb2c0 commit 36ff40f
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cve_bin_tool/mismatch_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions doc/mismatch_cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ 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
```

## 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
Expand Down Expand Up @@ -95,7 +95,7 @@ python -m mismatch.cli loader [--dir <data_dir>] [--database <db_file>]
```

**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:**
Expand Down
10 changes: 5 additions & 5 deletions doc/mismatch_data.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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
Expand All @@ -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)
2 changes: 1 addition & 1 deletion mismatch/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion test/test_mismatch_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
)
Expand Down
2 changes: 1 addition & 1 deletion test/test_mismatch_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 36ff40f

Please sign in to comment.