@@ -0,0 +1,2767 @@
+#!/usr/bin/env python3%0A%0A%22%22%22%0AWIP%0APythonic declaration of mDNS .local domains.%0AHeavily based off https://github.com/jstasiak/python-zeroconf/blob/master/tests/test_asyncio.py%0A%22%22%22%0A%0Aimport os%0Aimport sys%0Aimport argparse%0A%0Aimport asyncio%0Aimport logging%0Aimport socket%0Aimport time%0Afrom typing import List%0A%0Asys.path.insert(0, %22/usr/lib/moulinette/%22)%0Afrom yunohost.domain import domain_list%0A%0Afrom zeroconf import IPVersion%0Afrom zeroconf.asyncio import AsyncServiceInfo, AsyncZeroconf%0A%0A# TODO: Remove traceback beautification%0Afrom rich.traceback import install%0Ainstall(show_locals=True)%0A%0Aasync def register_services(infos: List%5BAsyncServiceInfo%5D) -%3E None:%0A    tasks = %5Baiozc.async_register_service(info) for info in infos%5D%0A    background_tasks = await asyncio.gather(*tasks)%0A    await asyncio.gather(*background_tasks)%0A%0A%0Aasync def unregister_services(infos: List%5BAsyncServiceInfo%5D) -%3E None:%0A    tasks = %5Baiozc.async_unregister_service(info) for info in infos%5D%0A    background_tasks = await asyncio.gather(*tasks)%0A    await asyncio.gather(*background_tasks)%0A%0A%0Aasync def close_aiozc(aiozc: AsyncZeroconf) -%3E None:%0A    await aiozc.async_close()%0A%0A%0Aif __name__ == '__main__':%0A    logging.basicConfig(level=logging.DEBUG)%0A%0A    local_domains = %5B d for d in domain_list()%5B'domains'%5D if d.endswith('.local') %5D%0A%0A    parser = argparse.ArgumentParser()%0A    parser.add_argument('--debug', action='store_true')%0A    version_group = parser.add_mutually_exclusive_group()%0A    version_group.add_argument('--v6', action='store_true')%0A    version_group.add_argument('--v6-only', action='store_true')%0A    args = parser.parse_args()%0A%0A    if args.debug:%0A        logging.getLogger('zeroconf').setLevel(logging.DEBUG)%0A    if args.v6:%0A        ip_version = IPVersion.All%0A    elif args.v6_only:%0A        ip_version = IPVersion.V6Only%0A    else:%0A        ip_version = IPVersion.V4Only%0A%0A    infos = %5B%5D%0A    for d in local_domains:%0A        d_domain=d.replace('.local','')%0A        infos.append(%0A            AsyncServiceInfo(%0A                type_=%22_device-info._tcp.local.%22,%0A                name=d_domain+f%22._device-info._tcp.local.%22,%0A                addresses=%5Bsocket.inet_aton(%22127.0.0.1%22)%5D,%0A                port=80,%0A                server=d,%0A            )%0A        )%0A%0A    print(%22Registration of .local domains, press Ctrl-C to exit...%22)%0A    aiozc = AsyncZeroconf(ip_version=ip_version)%0A    loop = asyncio.get_event_loop()%0A    loop.run_until_complete(register_services(infos))%0A    print(%22Registration complete.%22)%0A    try:%0A        while True:%0A            time.sleep(0.1)%0A    except KeyboardInterrupt:%0A        pass%0A    finally:%0A        print(%22Unregistering...%22)%0A        loop.run_until_complete(unregister_services(infos))%0A        print(%22Unregistration complete.%22)%0A        loop.run_until_complete(close_aiozc(aiozc))%0A%0A

Add mdns.py for mDNS broadcast