DataManager API

class DataManager[source]

DataManager is a module that manages all the resources used in Attacker, Metric, Substitute, TextProcessors and utils.

It reads configuration files in OpenAttack/data/*.py, and initialize these resources when you load them.

You can use

for data_name in OpenAttack.DataManager.AVAILABLE_DATAS:
    OpenAttack.download(data_name)

to download all the available resources, but this is not recommend because of the huge network cost.

OpenAttack.load and OpenAttack.download is a alias of OpenAttack.DataManager.load and OpenAttack.DataManager.download, they are exactly equivalent. These two methods are useful for both developer and user, that’s the reason we provide shortter name for them.

classmethod disable_cdn()[source]

Disable cdn for all official downloads.

classmethod download(data_name, path=None, force=False)[source]

This method will check if data exists before getting it from “Data Server”.You can use force to skip this step.

Parameters
  • data_name (str) – Name of the data that you want to download.

  • path (Optional[str]) – Specify a path when before download. Leaves None for download to default path.

  • force (bool) – Force download the data.

Raises

UnknownDataException – For downloading an unavailable data.

classmethod enable_cdn()[source]

Enable cdn for all official downloads.

classmethod get(data_name)[source]
Parameters

data_name (str) – The name of data.

Returns

Relative path of data.

Return type

str

classmethod load(data_name, cached=True)[source]

Load data from local storage, and download it automatically if not exists.

Parameters
  • data_name (str) – The name of resource that you want to load. You can find all the available resource names in DataManager.AVAILABLE_DATAS. Note: all the names are CASE-SENSITIVE.

  • cached (bool) – If cached is True, DataManager will lookup the cache before load it to avoid duplicate disk IO. If cached is False, DataManager will directly load data from disk. Default: True.

Returns

The object returned by LOAD function of corresponding data.

Raises
  • UnknownDataException – For loading an unavailable data.

  • DataNotExistException – For loading a data that has not been downloaded. This appends when AutoDownload mechanism is disabled.

Return type

Any

classmethod loadAttackAssist(data_name, cached=True)[source]

This method is equivalent to DataManager.load("AttackAssist." + data_name).

classmethod loadTProcess(data_name, cached=True)[source]

This method is equivalent to DataManager.load("TProcess." + data_name).

classmethod loadVictim(data_name, cached=True)[source]

This method is equivalent to DataManager.load("Victim." + data_name).

classmethod setAutoDownload(enabled=True)[source]

AutoDownload mechanism is enabled by default.

Parameters

enabled (bool) – Change if DataManager automatically download the data when loading.

classmethod set_path(path, data_name=None)[source]

Set the path for a specific data or for all data.

If data_name is None, all paths will be changed to corresponding file under path directory.

If data_name is not None, the specific data path will be changed to path.

The default paths for all data are ./data/<data_name>, and you can manually change them using this method .

Parameters
  • path (str) – The path to data, or path to the directory where all data is stored.

  • data_name (Optional[str]) – The name of data. If data_name is None, all paths will be changed.