Skip to content

Commit

Permalink
Improve pymap-admin file path logic
Browse files Browse the repository at this point in the history
  • Loading branch information
icgood committed Nov 12, 2020
1 parent d0422c4 commit f9c8115
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
15 changes: 8 additions & 7 deletions pymap/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from grpclib.server import Server
from pymap.interfaces.backend import ServiceInterface
from pymapadmin import is_compatible, __version__ as server_version
from pymapadmin.local import get_admin_socket, get_token_file
from pymapadmin.local import socket_file, token_file

from .errors import get_incompatible_version_error
from .handlers import handlers
Expand Down Expand Up @@ -44,12 +44,14 @@ class AdminService(ServiceInterface): # pragma: no cover
@classmethod
def add_arguments(cls, parser: ArgumentParser) -> None:
group = parser.add_argument_group('admin service')
group.add_argument('--admin-path', metavar='FILE', help=SUPPRESS)
group.add_argument('--admin-path', action=socket_file.add_action,
help=SUPPRESS)
group.add_argument('--admin-host', action='append', metavar='IFACE',
help='the network interface to listen on')
group.add_argument('--admin-port', metavar='NUM', type=int,
default=50051, help='the port to listen on')
group.add_argument('--admin-token-file', metavar='FILE', help=SUPPRESS)
group.add_argument('--admin-token-file', action=token_file.add_action,
help=SUPPRESS)
group.add_argument('--admin-token-duration', metavar='SEC', type=int,
help=SUPPRESS)

Expand All @@ -66,10 +68,9 @@ def _init_admin_token(self) -> None:
print(f'PYMAP_ADMIN_TOKEN={token}', file=sys.stderr)

def _write_admin_token(self, admin_token: str) -> None:
args = self.config.args
try:
token_file = get_token_file(args.admin_token_file, mkdir=True)
token_file.write_text(admin_token)
path = token_file.get_temp(mkdir=True)
path.write_text(admin_token)
except OSError:
pass

Expand Down Expand Up @@ -108,7 +109,7 @@ def _new_server(self, server_handlers: Sequence[Handler]) -> Server:
async def _start_local(self, server_handlers: Sequence[Handler],
path: Optional[str]) -> Server:
server = self._new_server(server_handlers)
path = str(get_admin_socket(path, mkdir=True))
path = str(socket_file.get_temp(mkdir=True))
await server.start(path=path)
return server

Expand Down
10 changes: 5 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
license = f.read()

setup(name='pymap',
version='0.22.1',
version='0.22.2',
author='Ian Good',
author_email='ian@icgood.net',
description='Lightweight, asynchronous IMAP serving in Python.',
Expand All @@ -49,12 +49,12 @@
include_package_data=True,
packages=find_packages(),
install_requires=[
'pysasl >= 0.8.0',
'proxy-protocol >= 0.5.5',
'pysasl ~= 0.8.0',
'proxy-protocol ~= 0.5.5',
'typing-extensions'],
extras_require={
'redis': ['aioredis >= 1.3.1', 'msgpack >= 1.0'],
'admin': ['pymap-admin == 0.5.2', 'googleapis-common-protos'],
'redis': ['aioredis ~= 1.3.1', 'msgpack ~= 1.0'],
'admin': ['pymap-admin ~= 0.5.3', 'googleapis-common-protos'],
'macaroon': ['pymacaroons'],
'sieve': ['sievelib'],
'systemd': ['systemd-python'],
Expand Down

0 comments on commit f9c8115

Please sign in to comment.