mirror of
https://github.com/revanced/revanced-static-api.git
synced 2025-04-30 06:34:30 +02:00
feat: Call generators asynchronously
This commit is contained in:
parent
227fbd3f90
commit
38e93bc2f2
@ -18,7 +18,7 @@ class Generator(ABC):
|
||||
self._api = api
|
||||
|
||||
@abstractmethod
|
||||
def generate(self, config, path):
|
||||
async def generate(self, config, path):
|
||||
"""
|
||||
Generates static files based on the supplied config to the specified path.
|
||||
|
||||
@ -43,7 +43,7 @@ class ReleasesGenerator(Generator):
|
||||
def __init__(self, api: api.Api = Provide[ApiContainer.api]):
|
||||
super().__init__("releases", api)
|
||||
|
||||
def generate(self, config, path):
|
||||
async def generate(self, config, path):
|
||||
path = join(path, "releases")
|
||||
|
||||
repositories = config["repositories"]
|
||||
@ -87,7 +87,7 @@ class ContributorsGenerator(Generator):
|
||||
def __init__(self, api: api.Api = Provide[ApiContainer.api]):
|
||||
super().__init__("contributors", api)
|
||||
|
||||
def generate(self, config, path):
|
||||
async def generate(self, config, path):
|
||||
path = join(path, "contributors")
|
||||
|
||||
create_if_not_exists(path)
|
||||
@ -111,7 +111,7 @@ class ConnectionsGenerator(Generator):
|
||||
def __init__(self):
|
||||
super().__init__("connections", None)
|
||||
|
||||
def generate(self, config, path):
|
||||
async def generate(self, config, path):
|
||||
new_connections = config["connections"]
|
||||
|
||||
connections_path = join(path, f"connections.json")
|
||||
@ -131,7 +131,7 @@ class TeamGenerator(Generator):
|
||||
def __init__(self, api: api.Api = Provide[ApiContainer.api]):
|
||||
super().__init__("team", api)
|
||||
|
||||
def generate(self, config, path):
|
||||
async def generate(self, config, path):
|
||||
organization = config["organization"]
|
||||
|
||||
team = self._api.get_members(organization)
|
||||
@ -150,7 +150,7 @@ class DonationsGenerator(Generator):
|
||||
def __init__(self):
|
||||
super().__init__("donations")
|
||||
|
||||
def generate(self, config, path):
|
||||
async def generate(self, config, path):
|
||||
links = config["links"] if "links" in config else []
|
||||
wallets = config["wallets"] if "wallets" in config else []
|
||||
|
||||
@ -178,7 +178,7 @@ class AnnouncementGenerator(Generator):
|
||||
def __init__(self):
|
||||
super().__init__("announcements")
|
||||
|
||||
def generate(self, config, path):
|
||||
async def generate(self, config, path):
|
||||
new_announcement = config["announcement"]
|
||||
new_announcement_channel = new_announcement["channel"]
|
||||
|
||||
@ -220,7 +220,7 @@ class RemoveAnnouncementGenerator(Generator):
|
||||
def __init__(self):
|
||||
super().__init__("remove_announcement")
|
||||
|
||||
def generate(self, config, path):
|
||||
async def generate(self, config, path):
|
||||
# TODO: Implement this
|
||||
pass
|
||||
|
||||
|
13
main.py
13
main.py
@ -1,3 +1,4 @@
|
||||
import asyncio
|
||||
from genericpath import isdir, isfile
|
||||
import os
|
||||
import shutil
|
||||
@ -17,12 +18,20 @@ def main():
|
||||
output = config["output"]
|
||||
generator_provider = DefaultGeneratorProvider()
|
||||
|
||||
loop = asyncio.get_event_loop()
|
||||
tasks = []
|
||||
|
||||
for generator_config in config["configs"]:
|
||||
for generator_name in generator_config["generators"]:
|
||||
generator = generator_provider.get(generator_name)
|
||||
|
||||
generator.generate(generator_config, output) if generator is not None else print(f"Generator {generator_name} not found.")
|
||||
tasks.append(
|
||||
loop.create_task(generator.generate(generator_config, output))
|
||||
) if generator is not None else print(f"Generator {generator_name} not found.")
|
||||
|
||||
loop.run_until_complete(asyncio.wait(tasks))
|
||||
loop.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
wire_dependencies()
|
||||
main()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user