From 42e18b8fdab74cd5d5a19fb27fb5353296112805 Mon Sep 17 00:00:00 2001 From: Bruno Thomas Date: Sat, 11 Jan 2025 18:42:00 +0100 Subject: [PATCH] feat: add imapserver script and argparse for host:port --- aioimaplib/tests/imapserver.py | 20 +++++++++++++++++--- pyproject.toml | 5 ++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/aioimaplib/tests/imapserver.py b/aioimaplib/tests/imapserver.py index 0cfe121..9ab5c5e 100644 --- a/aioimaplib/tests/imapserver.py +++ b/aioimaplib/tests/imapserver.py @@ -13,6 +13,7 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import argparse import asyncio from base64 import b64decode import email @@ -795,11 +796,24 @@ def create(to, mail_from='', subject='', content='', return Mail(msg, date=date) -async def main(): - srv = await MockImapServer(loop=asyncio.get_running_loop()).run_server() +async def async_main(**kwargs): + log.info(f"Running IMAP server on {kwargs['host']}:{kwargs['port']}") + srv = await MockImapServer(loop=asyncio.get_running_loop()).run_server(host=kwargs['host'], port=kwargs['port']) async with srv: await srv.serve_forever() +def main(): + parser = argparse.ArgumentParser( + formatter_class=argparse.ArgumentDefaultsHelpFormatter, + prog='imapserver', + description='Small python asyncio IMAP testing server.', + epilog='') + parser.add_argument('--port', help='tcp port of the server', default=1143) + parser.add_argument('--host', help='host of the server', default='127.0.0.1') + args = parser.parse_args() + asyncio.run(async_main(**args.__dict__)) + + if __name__ == '__main__': - asyncio.run(main()) + main() diff --git a/pyproject.toml b/pyproject.toml index 2845a08..031ac6e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,4 +40,7 @@ pytest-cov = "^6.0.0" [build-system] requires = ["poetry-core"] -build-backend = "poetry.core.masonry.api" \ No newline at end of file +build-backend = "poetry.core.masonry.api" + +[tool.poetry.scripts] +imapserver = "aioimaplib.tests.imapserver:main" \ No newline at end of file