summaryrefslogtreecommitdiffstats
path: root/port_for/store.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 05:38:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 05:38:43 +0000
commitc0e738bc25ae76cf5092d6e0f86938fa5684dd27 (patch)
tree0f6250f19003fc920775fead71e48bf918c27a35 /port_for/store.py
parentReleasing progress-linux version 0.7.1-1~progress7.99u1. (diff)
downloadport-for-c0e738bc25ae76cf5092d6e0f86938fa5684dd27.tar.xz
port-for-c0e738bc25ae76cf5092d6e0f86938fa5684dd27.zip
Merging upstream version 0.7.2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'port_for/store.py')
-rw-r--r--port_for/store.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/port_for/store.py b/port_for/store.py
index a07b737..685753c 100644
--- a/port_for/store.py
+++ b/port_for/store.py
@@ -1,22 +1,25 @@
-# -*- coding: utf-8 -*-
+"""PortStore implementation."""
import os
-from configparser import ConfigParser, DEFAULTSECT
-from typing import Optional, List, Tuple, Union
+from configparser import DEFAULTSECT, ConfigParser
+from typing import List, Optional, Tuple, Union
from .api import select_random
from .exceptions import PortForException
-
DEFAULT_CONFIG_PATH = "/etc/port-for.conf"
class PortStore(object):
+ """PortStore binds, reads and stores bound ports in config."""
+
def __init__(self, config_filename: str = DEFAULT_CONFIG_PATH):
+ """Initialize PortStore."""
self._config = config_filename
def bind_port(
self, app: str, port: Optional[Union[int, str]] = None
) -> int:
+ """Binds port to app in the config."""
if "=" in app or ":" in app:
raise Exception('invalid app name: "%s"' % app)
@@ -61,11 +64,13 @@ class PortStore(object):
return int(requested_port)
def unbind_port(self, app: str) -> None:
+ """Remove port assignement to application."""
parser = self._get_parser()
parser.remove_option(DEFAULTSECT, app)
self._save(parser)
def bound_ports(self) -> List[Tuple[str, int]]:
+ """List all bound ports."""
return [
(app, int(port))
for app, port in self._get_parser().items(DEFAULTSECT)