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
|
self._api = api
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def generate(self, config, path):
|
async def generate(self, config, path):
|
||||||
"""
|
"""
|
||||||
Generates static files based on the supplied config to the specified 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]):
|
def __init__(self, api: api.Api = Provide[ApiContainer.api]):
|
||||||
super().__init__("releases", api)
|
super().__init__("releases", api)
|
||||||
|
|
||||||
def generate(self, config, path):
|
async def generate(self, config, path):
|
||||||
path = join(path, "releases")
|
path = join(path, "releases")
|
||||||
|
|
||||||
repositories = config["repositories"]
|
repositories = config["repositories"]
|
||||||
@ -87,7 +87,7 @@ class ContributorsGenerator(Generator):
|
|||||||
def __init__(self, api: api.Api = Provide[ApiContainer.api]):
|
def __init__(self, api: api.Api = Provide[ApiContainer.api]):
|
||||||
super().__init__("contributors", api)
|
super().__init__("contributors", api)
|
||||||
|
|
||||||
def generate(self, config, path):
|
async def generate(self, config, path):
|
||||||
path = join(path, "contributors")
|
path = join(path, "contributors")
|
||||||
|
|
||||||
create_if_not_exists(path)
|
create_if_not_exists(path)
|
||||||
@ -111,7 +111,7 @@ class ConnectionsGenerator(Generator):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__("connections", None)
|
super().__init__("connections", None)
|
||||||
|
|
||||||
def generate(self, config, path):
|
async def generate(self, config, path):
|
||||||
new_connections = config["connections"]
|
new_connections = config["connections"]
|
||||||
|
|
||||||
connections_path = join(path, f"connections.json")
|
connections_path = join(path, f"connections.json")
|
||||||
@ -131,7 +131,7 @@ class TeamGenerator(Generator):
|
|||||||
def __init__(self, api: api.Api = Provide[ApiContainer.api]):
|
def __init__(self, api: api.Api = Provide[ApiContainer.api]):
|
||||||
super().__init__("team", api)
|
super().__init__("team", api)
|
||||||
|
|
||||||
def generate(self, config, path):
|
async def generate(self, config, path):
|
||||||
organization = config["organization"]
|
organization = config["organization"]
|
||||||
|
|
||||||
team = self._api.get_members(organization)
|
team = self._api.get_members(organization)
|
||||||
@ -150,7 +150,7 @@ class DonationsGenerator(Generator):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__("donations")
|
super().__init__("donations")
|
||||||
|
|
||||||
def generate(self, config, path):
|
async def generate(self, config, path):
|
||||||
links = config["links"] if "links" in config else []
|
links = config["links"] if "links" in config else []
|
||||||
wallets = config["wallets"] if "wallets" in config else []
|
wallets = config["wallets"] if "wallets" in config else []
|
||||||
|
|
||||||
@ -178,7 +178,7 @@ class AnnouncementGenerator(Generator):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__("announcements")
|
super().__init__("announcements")
|
||||||
|
|
||||||
def generate(self, config, path):
|
async def generate(self, config, path):
|
||||||
new_announcement = config["announcement"]
|
new_announcement = config["announcement"]
|
||||||
new_announcement_channel = new_announcement["channel"]
|
new_announcement_channel = new_announcement["channel"]
|
||||||
|
|
||||||
@ -220,7 +220,7 @@ class RemoveAnnouncementGenerator(Generator):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__("remove_announcement")
|
super().__init__("remove_announcement")
|
||||||
|
|
||||||
def generate(self, config, path):
|
async def generate(self, config, path):
|
||||||
# TODO: Implement this
|
# TODO: Implement this
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
13
main.py
13
main.py
@ -1,3 +1,4 @@
|
|||||||
|
import asyncio
|
||||||
from genericpath import isdir, isfile
|
from genericpath import isdir, isfile
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
@ -17,12 +18,20 @@ def main():
|
|||||||
output = config["output"]
|
output = config["output"]
|
||||||
generator_provider = DefaultGeneratorProvider()
|
generator_provider = DefaultGeneratorProvider()
|
||||||
|
|
||||||
|
loop = asyncio.get_event_loop()
|
||||||
|
tasks = []
|
||||||
|
|
||||||
for generator_config in config["configs"]:
|
for generator_config in config["configs"]:
|
||||||
for generator_name in generator_config["generators"]:
|
for generator_name in generator_config["generators"]:
|
||||||
generator = generator_provider.get(generator_name)
|
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__":
|
if __name__ == "__main__":
|
||||||
wire_dependencies()
|
wire_dependencies()
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user