2018-02-06 08:04:31 +01:00
|
|
|
from argparse import Namespace
|
2018-08-22 22:00:08 +02:00
|
|
|
from typing import Any, Optional
|
2018-02-06 08:04:31 +01:00
|
|
|
|
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
class OpenSlidesArguments:
|
2018-08-22 22:00:08 +02:00
|
|
|
args: Optional[Namespace] = None
|
2018-02-06 08:04:31 +01:00
|
|
|
|
|
|
|
def __getitem__(self, key: str) -> Any:
|
|
|
|
if not self.args:
|
|
|
|
raise KeyError("Arguments are not set.")
|
|
|
|
if not hasattr(self.args, key):
|
|
|
|
raise KeyError("Key '{}' is not in the OpenSlides arguments.".format(key))
|
|
|
|
return getattr(self.args, key)
|
|
|
|
|
|
|
|
def get(self, key: str, default: Any) -> Any:
|
|
|
|
if not self.args or not hasattr(self.args, key):
|
|
|
|
return default
|
|
|
|
else:
|
|
|
|
return getattr(self.args, key)
|
|
|
|
|
|
|
|
def set_arguments(self, args: Namespace) -> None:
|
|
|
|
self.args = args
|
|
|
|
|
|
|
|
|
|
|
|
arguments = OpenSlidesArguments()
|