Skip to content

Commit

Permalink
Fix broken docs, moved generate function so it was easier to see in t…
Browse files Browse the repository at this point in the history
…he docs
  • Loading branch information
DoubleF3lix committed Oct 19, 2021
1 parent 9f00944 commit de6549d
Showing 1 changed file with 59 additions and 58 deletions.
117 changes: 59 additions & 58 deletions onyx/pack_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,65 @@ def __init__(

self.gen_time_start = time.time()

def generate(
self,
overwrite: bool = True,
zipped: bool = False,
only_generate_zip_object: bool = False,
print_output_path: bool = True,
print_generation_time: bool = True,
) -> None:
"""
generate - Generates the data pack
Args:
overwrite (bool, optional): Whether to overwrite the data pack if it already exists. Defaults to True.
zipped (bool, optional): Whether to generate a zipped data pack. If ``False``, a folder will be generated instead. Defaults to False.
only_generate_zip_object (bool, optional): If set, only returns a ``ZipFile`` object instead of generating a file/folder. Defaults to False.
print_output_path (bool, optional): Whether to print the output path of the data pack. Defaults to True.
print_generation_time (bool): Whether the generation time should be printed to the console. Defaults to False.
"""
# Generate the initialization function file (make sure it has any commands in it, otherwise don't bother)
if self.init_contents:
self.pack_object[
f"{snakify(self.pack_data['name'])}:_init"
] = beet.Function(self.init_contents, tags=["minecraft:load"])

# Determine the data pack output path
if self.pack_data["path"] is None:
pack_output_path = os.path.join(os.getcwd())
else:
pack_output_path = os.path.join(self.pack_data["path"])

return_values = {
"output_path": pack_output_path,
"generation_time": time.time() - self.gen_time_start,
}

if not only_generate_zip_object:
output_path = self.pack_object.save(
directory=pack_output_path, overwrite=overwrite, zipped=zipped
)
else:
with zipfile.ZipFile(snakify(self.pack_data["name"]) + ".zip", "w") as zip:
self.pack_object.dump(zip)
return_values["zip_object"] = zip

if print_output_path:
if not only_generate_zip_object:
print(
f"Data pack {self.pack_data['name']} generated at '{output_path}{'.zip' if zipped else ''}'"
)
else:
print("Data pack generated as ZipFile object")

if print_generation_time:
print(
f"Data pack generated in {round(return_values['generation_time'], 6)} seconds"
)

return return_values

def advancement(self, path: str, contents: dict) -> "Advancement":
"""
advancement - Creates an advancement
Expand Down Expand Up @@ -356,64 +415,6 @@ def worldgen_template_pool(
"""
return Worldgen_TemplatePool(path, contents, self)

def generate(
self,
overwrite: bool = True,
zipped: bool = False,
only_generate_zip_object: bool = False,
print_output_path: bool = True,
print_generation_time: bool = True,
) -> None:
"""
generate - Generates the data pack
Args:
overwrite (bool, optional): Whether to overwrite the data pack if it already exists. Defaults to True.
zipped (bool, optional): Whether to generate a zipped data pack. If ``False``, a folder will be generated instead. Defaults to False.
only_generate_zip_object (bool, optional): If set, only returns a ``ZipFile`` object instead of generating a file/folder. Defaults to False.
print_output_path (bool, optional): Whether to print the output path of the data pack. Defaults to True.
print_generation_time (bool): Whether the generation time should be printed to the console. Defaults to False.
"""
# Generate the initialization function file (make sure it has any commands in it, otherwise don't bother)
if self.init_contents:
self.pack_object[
f"{snakify(self.pack_data['name'])}:_init"
] = beet.Function(self.init_contents, tags=["minecraft:load"])

# Determine the data pack output path
if self.pack_data["path"] is None:
pack_output_path = os.path.join(os.getcwd())
else:
pack_output_path = os.path.join(self.pack_data["path"])

return_values = {
"output_path": pack_output_path,
"generation_time": time.time() - self.gen_time_start,
}

if not only_generate_zip_object:
output_path = self.pack_object.save(
directory=pack_output_path, overwrite=overwrite, zipped=zipped
)
else:
with zipfile.ZipFile(snakify(self.pack_data["name"]) + ".zip", "w") as zip:
self.pack_object.dump(zip)
return_values["zip_object"] = zip

if print_output_path:
if not only_generate_zip_object:
print(
f"Data pack {self.pack_data['name']} generated at '{output_path}{'.zip' if zipped else ''}'"
)
else:
print("Data pack generated as ZipFile object")

if print_generation_time:
print(
f"Data pack generated in {round(return_values['generation_time'], 6)} seconds"
)

return return_values

def __str__(self) -> str:
"""
__str__ - Returns the name of the data pack
Expand Down

0 comments on commit de6549d

Please sign in to comment.