Utilities for loading a particular file from inside a zipped data pack
copy_data_from_existing_pack(pack_path=None)
Copy the "data" folder from an existing pack into the default pack folder, overwriting any existing data directory
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pack_path |
path
|
The pack to copy from. If None is provided, this method will look for a "wandering trades" data pack in the "packs" folder ("hermit edition" packs should be given priority). |
None
|
Raises:
Type | Description |
---|---|
KeyError
|
If the specified pack path does not exist or has no data folder |
Source code in head_hunter/extract.py
file_from_data_pack(pack_name, resource, pack_directory=None)
Extract a specific file from a data pack
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pack_name |
str
|
Which data pack you want (not case-sensitive, and after normalizing for spaces, underscores and dashes) |
required |
resource |
path or list of paths
|
The specific resource you want to extract, specified as a Path relative to the pack root. If there are multiple locations this resource could be, provide them as a list, and this method will check each in order until one is found. |
required |
pack_directory |
path
|
The pack directory to search. If None is given, this method will look for a "packs" folder inside the current working directory. |
None
|
Yields:
Type | Description |
---|---|
file
|
file pointer open to the requested file from the requested pack |
Raises:
Type | Description |
---|---|
KeyError
|
If the pack or pack file cannot be found |
Source code in head_hunter/extract.py
get_data_pack(pack_name, pack_directory=None)
Get a specific data pack
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pack_name |
str
|
Which data pack you want (not case-sensitive, and after normalizing for spaces, underscores and dashes) |
required |
pack_directory |
path
|
The pack directory to search. If None is given, this method will look for a "packs" folder inside the current working directory. |
None
|
Returns:
Type | Description |
---|---|
Path
|
The path to that data pack. If there are multiple paths matching the given description, the one returned should hopefully be the most recent one (it'll be the last one sorted lexically). |
Raises:
Type | Description |
---|---|
KeyError
|
If no matching packs can be found |
RuntimeWarning
|
If there are multiple packs matching the given specification |
Source code in head_hunter/extract.py
list_available_packs(pack_directory=None)
Return a list of all data packs (zipped or not) in the specified pack directory
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pack_directory |
path
|
The pack directory to search. If None is given, this method will look for a "packs" folder inside the current working directory. |
None
|
Returns:
Type | Description |
---|---|
list of paths
|
The available data packs, sorted lexically (alphabetically) |
Notes
If the pack directory doesn't exist, this method will return an empty list rather than raising an error