ominfra 0.0.0.dev193__py3-none-any.whl → 0.0.0.dev194__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- ominfra/clouds/aws/journald2aws/main.py +5 -2
- ominfra/manage/deploy/conf/manager.py +2 -2
- ominfra/manage/main.py +3 -3
- ominfra/scripts/journald2aws.py +446 -95
- ominfra/scripts/manage.py +467 -168
- ominfra/scripts/supervisor.py +1055 -659
- ominfra/supervisor/configs.py +4 -3
- ominfra/supervisor/main.py +2 -2
- {ominfra-0.0.0.dev193.dist-info → ominfra-0.0.0.dev194.dist-info}/METADATA +4 -4
- {ominfra-0.0.0.dev193.dist-info → ominfra-0.0.0.dev194.dist-info}/RECORD +14 -15
- ominfra/configs.py +0 -102
- {ominfra-0.0.0.dev193.dist-info → ominfra-0.0.0.dev194.dist-info}/LICENSE +0 -0
- {ominfra-0.0.0.dev193.dist-info → ominfra-0.0.0.dev194.dist-info}/WHEEL +0 -0
- {ominfra-0.0.0.dev193.dist-info → ominfra-0.0.0.dev194.dist-info}/entry_points.txt +0 -0
- {ominfra-0.0.0.dev193.dist-info → ominfra-0.0.0.dev194.dist-info}/top_level.txt +0 -0
ominfra/scripts/manage.py
CHANGED
@@ -80,6 +80,9 @@ DeployPathKind = ta.Literal['dir', 'file'] # ta.TypeAlias
|
|
80
80
|
# ../../omlish/asyncs/asyncio/timeouts.py
|
81
81
|
AwaitableT = ta.TypeVar('AwaitableT', bound=ta.Awaitable)
|
82
82
|
|
83
|
+
# ../../omlish/configs/types.py
|
84
|
+
ConfigMap = ta.Mapping[str, ta.Any]
|
85
|
+
|
83
86
|
# ../../omlish/formats/ini/sections.py
|
84
87
|
IniSectionSettingsMap = ta.Mapping[str, ta.Mapping[str, ta.Union[str, ta.Sequence[str]]]] # ta.TypeAlias
|
85
88
|
|
@@ -117,6 +120,9 @@ CommandOutputT = ta.TypeVar('CommandOutputT', bound='Command.Output')
|
|
117
120
|
# ../../omlish/argparse/cli.py
|
118
121
|
ArgparseCmdFn = ta.Callable[[], ta.Optional[int]] # ta.TypeAlias
|
119
122
|
|
123
|
+
# ../../omlish/configs/formats.py
|
124
|
+
ConfigDataT = ta.TypeVar('ConfigDataT', bound='ConfigData')
|
125
|
+
|
120
126
|
# ../../omlish/lite/contextmanagers.py
|
121
127
|
ExitStackedT = ta.TypeVar('ExitStackedT', bound='ExitStacked')
|
122
128
|
|
@@ -131,9 +137,6 @@ InjectorBindingOrBindings = ta.Union['InjectorBinding', 'InjectorBindings']
|
|
131
137
|
AtomicPathSwapKind = ta.Literal['dir', 'file']
|
132
138
|
AtomicPathSwapState = ta.Literal['open', 'committed', 'aborted'] # ta.TypeAlias
|
133
139
|
|
134
|
-
# ../configs.py
|
135
|
-
ConfigMapping = ta.Mapping[str, ta.Any]
|
136
|
-
|
137
140
|
# ../../omlish/subprocesses.py
|
138
141
|
SubprocessChannelOption = ta.Literal['pipe', 'stdout', 'devnull'] # ta.TypeAlias
|
139
142
|
|
@@ -1212,6 +1215,13 @@ def asyncio_maybe_timeout(
|
|
1212
1215
|
return fut
|
1213
1216
|
|
1214
1217
|
|
1218
|
+
########################################
|
1219
|
+
# ../../../omlish/configs/types.py
|
1220
|
+
|
1221
|
+
|
1222
|
+
#
|
1223
|
+
|
1224
|
+
|
1215
1225
|
########################################
|
1216
1226
|
# ../../../omlish/formats/ini/sections.py
|
1217
1227
|
|
@@ -2071,6 +2081,129 @@ def toml_make_safe_parse_float(parse_float: TomlParseFloat) -> TomlParseFloat:
|
|
2071
2081
|
return safe_parse_float
|
2072
2082
|
|
2073
2083
|
|
2084
|
+
########################################
|
2085
|
+
# ../../../omlish/formats/toml/writer.py
|
2086
|
+
|
2087
|
+
|
2088
|
+
class TomlWriter:
|
2089
|
+
@dc.dataclass(frozen=True)
|
2090
|
+
class Literal:
|
2091
|
+
s: str
|
2092
|
+
|
2093
|
+
def __init__(self, out: ta.TextIO) -> None:
|
2094
|
+
super().__init__()
|
2095
|
+
self._out = out
|
2096
|
+
|
2097
|
+
self._indent = 0
|
2098
|
+
self._wrote_indent = False
|
2099
|
+
|
2100
|
+
#
|
2101
|
+
|
2102
|
+
def _w(self, s: str) -> None:
|
2103
|
+
if not self._wrote_indent:
|
2104
|
+
self._out.write(' ' * self._indent)
|
2105
|
+
self._wrote_indent = True
|
2106
|
+
self._out.write(s)
|
2107
|
+
|
2108
|
+
def _nl(self) -> None:
|
2109
|
+
self._out.write('\n')
|
2110
|
+
self._wrote_indent = False
|
2111
|
+
|
2112
|
+
def _needs_quote(self, s: str) -> bool:
|
2113
|
+
return (
|
2114
|
+
not s or
|
2115
|
+
any(c in s for c in '\'"\n') or
|
2116
|
+
s[0] not in string.ascii_letters
|
2117
|
+
)
|
2118
|
+
|
2119
|
+
def _maybe_quote(self, s: str) -> str:
|
2120
|
+
if self._needs_quote(s):
|
2121
|
+
return repr(s)
|
2122
|
+
else:
|
2123
|
+
return s
|
2124
|
+
|
2125
|
+
#
|
2126
|
+
|
2127
|
+
def write_root(self, obj: ta.Mapping) -> None:
|
2128
|
+
for i, (k, v) in enumerate(obj.items()):
|
2129
|
+
if i:
|
2130
|
+
self._nl()
|
2131
|
+
self._w('[')
|
2132
|
+
self._w(self._maybe_quote(k))
|
2133
|
+
self._w(']')
|
2134
|
+
self._nl()
|
2135
|
+
self.write_table_contents(v)
|
2136
|
+
|
2137
|
+
def write_table_contents(self, obj: ta.Mapping) -> None:
|
2138
|
+
for k, v in obj.items():
|
2139
|
+
self.write_key(k)
|
2140
|
+
self._w(' = ')
|
2141
|
+
self.write_value(v)
|
2142
|
+
self._nl()
|
2143
|
+
|
2144
|
+
def write_array(self, obj: ta.Sequence) -> None:
|
2145
|
+
self._w('[')
|
2146
|
+
self._nl()
|
2147
|
+
self._indent += 1
|
2148
|
+
for e in obj:
|
2149
|
+
self.write_value(e)
|
2150
|
+
self._w(',')
|
2151
|
+
self._nl()
|
2152
|
+
self._indent -= 1
|
2153
|
+
self._w(']')
|
2154
|
+
|
2155
|
+
def write_inline_table(self, obj: ta.Mapping) -> None:
|
2156
|
+
self._w('{')
|
2157
|
+
for i, (k, v) in enumerate(obj.items()):
|
2158
|
+
if i:
|
2159
|
+
self._w(', ')
|
2160
|
+
self.write_key(k)
|
2161
|
+
self._w(' = ')
|
2162
|
+
self.write_value(v)
|
2163
|
+
self._w('}')
|
2164
|
+
|
2165
|
+
def write_inline_array(self, obj: ta.Sequence) -> None:
|
2166
|
+
self._w('[')
|
2167
|
+
for i, e in enumerate(obj):
|
2168
|
+
if i:
|
2169
|
+
self._w(', ')
|
2170
|
+
self.write_value(e)
|
2171
|
+
self._w(']')
|
2172
|
+
|
2173
|
+
def write_key(self, obj: ta.Any) -> None:
|
2174
|
+
if isinstance(obj, TomlWriter.Literal):
|
2175
|
+
self._w(obj.s)
|
2176
|
+
elif isinstance(obj, str):
|
2177
|
+
self._w(self._maybe_quote(obj.replace('_', '-')))
|
2178
|
+
elif isinstance(obj, int):
|
2179
|
+
self._w(repr(str(obj)))
|
2180
|
+
else:
|
2181
|
+
raise TypeError(obj)
|
2182
|
+
|
2183
|
+
def write_value(self, obj: ta.Any) -> None:
|
2184
|
+
if isinstance(obj, bool):
|
2185
|
+
self._w(str(obj).lower())
|
2186
|
+
elif isinstance(obj, (str, int, float)):
|
2187
|
+
self._w(repr(obj))
|
2188
|
+
elif isinstance(obj, ta.Mapping):
|
2189
|
+
self.write_inline_table(obj)
|
2190
|
+
elif isinstance(obj, ta.Sequence):
|
2191
|
+
if not obj:
|
2192
|
+
self.write_inline_array(obj)
|
2193
|
+
else:
|
2194
|
+
self.write_array(obj)
|
2195
|
+
else:
|
2196
|
+
raise TypeError(obj)
|
2197
|
+
|
2198
|
+
#
|
2199
|
+
|
2200
|
+
@classmethod
|
2201
|
+
def write_str(cls, obj: ta.Any) -> str:
|
2202
|
+
out = io.StringIO()
|
2203
|
+
cls(out).write_value(obj)
|
2204
|
+
return out.getvalue()
|
2205
|
+
|
2206
|
+
|
2074
2207
|
########################################
|
2075
2208
|
# ../../../omlish/lite/cached.py
|
2076
2209
|
|
@@ -4843,6 +4976,235 @@ class ArgparseCli:
|
|
4843
4976
|
return await fn()
|
4844
4977
|
|
4845
4978
|
|
4979
|
+
########################################
|
4980
|
+
# ../../../omlish/configs/formats.py
|
4981
|
+
"""
|
4982
|
+
Notes:
|
4983
|
+
- necessarily string-oriented
|
4984
|
+
- single file, as this is intended to be amalg'd and thus all included anyway
|
4985
|
+
|
4986
|
+
TODO:
|
4987
|
+
- ConfigDataMapper? to_map -> ConfigMap?
|
4988
|
+
- nginx ?
|
4989
|
+
- raw ?
|
4990
|
+
"""
|
4991
|
+
|
4992
|
+
|
4993
|
+
##
|
4994
|
+
|
4995
|
+
|
4996
|
+
@dc.dataclass(frozen=True)
|
4997
|
+
class ConfigData(abc.ABC): # noqa
|
4998
|
+
@abc.abstractmethod
|
4999
|
+
def as_map(self) -> ConfigMap:
|
5000
|
+
raise NotImplementedError
|
5001
|
+
|
5002
|
+
|
5003
|
+
#
|
5004
|
+
|
5005
|
+
|
5006
|
+
class ConfigLoader(abc.ABC, ta.Generic[ConfigDataT]):
|
5007
|
+
@property
|
5008
|
+
def file_exts(self) -> ta.Sequence[str]:
|
5009
|
+
return ()
|
5010
|
+
|
5011
|
+
def match_file(self, n: str) -> bool:
|
5012
|
+
return '.' in n and n.split('.')[-1] in check.not_isinstance(self.file_exts, str)
|
5013
|
+
|
5014
|
+
#
|
5015
|
+
|
5016
|
+
def load_file(self, p: str) -> ConfigDataT:
|
5017
|
+
with open(p) as f:
|
5018
|
+
return self.load_str(f.read())
|
5019
|
+
|
5020
|
+
@abc.abstractmethod
|
5021
|
+
def load_str(self, s: str) -> ConfigDataT:
|
5022
|
+
raise NotImplementedError
|
5023
|
+
|
5024
|
+
|
5025
|
+
#
|
5026
|
+
|
5027
|
+
|
5028
|
+
class ConfigRenderer(abc.ABC, ta.Generic[ConfigDataT]):
|
5029
|
+
@property
|
5030
|
+
@abc.abstractmethod
|
5031
|
+
def data_cls(self) -> ta.Type[ConfigDataT]:
|
5032
|
+
raise NotImplementedError
|
5033
|
+
|
5034
|
+
def match_data(self, d: ConfigDataT) -> bool:
|
5035
|
+
return isinstance(d, self.data_cls)
|
5036
|
+
|
5037
|
+
#
|
5038
|
+
|
5039
|
+
@abc.abstractmethod
|
5040
|
+
def render(self, d: ConfigDataT) -> str:
|
5041
|
+
raise NotImplementedError
|
5042
|
+
|
5043
|
+
|
5044
|
+
##
|
5045
|
+
|
5046
|
+
|
5047
|
+
@dc.dataclass(frozen=True)
|
5048
|
+
class ObjConfigData(ConfigData, abc.ABC):
|
5049
|
+
obj: ta.Any
|
5050
|
+
|
5051
|
+
def as_map(self) -> ConfigMap:
|
5052
|
+
return check.isinstance(self.obj, collections.abc.Mapping)
|
5053
|
+
|
5054
|
+
|
5055
|
+
##
|
5056
|
+
|
5057
|
+
|
5058
|
+
@dc.dataclass(frozen=True)
|
5059
|
+
class JsonConfigData(ObjConfigData):
|
5060
|
+
pass
|
5061
|
+
|
5062
|
+
|
5063
|
+
class JsonConfigLoader(ConfigLoader[JsonConfigData]):
|
5064
|
+
file_exts = ('json',)
|
5065
|
+
|
5066
|
+
def load_str(self, s: str) -> JsonConfigData:
|
5067
|
+
return JsonConfigData(json.loads(s))
|
5068
|
+
|
5069
|
+
|
5070
|
+
class JsonConfigRenderer(ConfigRenderer[JsonConfigData]):
|
5071
|
+
data_cls = JsonConfigData
|
5072
|
+
|
5073
|
+
def render(self, d: JsonConfigData) -> str:
|
5074
|
+
return json_dumps_pretty(d.obj)
|
5075
|
+
|
5076
|
+
|
5077
|
+
##
|
5078
|
+
|
5079
|
+
|
5080
|
+
@dc.dataclass(frozen=True)
|
5081
|
+
class TomlConfigData(ObjConfigData):
|
5082
|
+
pass
|
5083
|
+
|
5084
|
+
|
5085
|
+
class TomlConfigLoader(ConfigLoader[TomlConfigData]):
|
5086
|
+
file_exts = ('toml',)
|
5087
|
+
|
5088
|
+
def load_str(self, s: str) -> TomlConfigData:
|
5089
|
+
return TomlConfigData(toml_loads(s))
|
5090
|
+
|
5091
|
+
|
5092
|
+
class TomlConfigRenderer(ConfigRenderer[TomlConfigData]):
|
5093
|
+
data_cls = TomlConfigData
|
5094
|
+
|
5095
|
+
def render(self, d: TomlConfigData) -> str:
|
5096
|
+
return TomlWriter.write_str(d.obj)
|
5097
|
+
|
5098
|
+
|
5099
|
+
##
|
5100
|
+
|
5101
|
+
|
5102
|
+
@dc.dataclass(frozen=True)
|
5103
|
+
class YamlConfigData(ObjConfigData):
|
5104
|
+
pass
|
5105
|
+
|
5106
|
+
|
5107
|
+
class YamlConfigLoader(ConfigLoader[YamlConfigData]):
|
5108
|
+
file_exts = ('yaml', 'yml')
|
5109
|
+
|
5110
|
+
def load_str(self, s: str) -> YamlConfigData:
|
5111
|
+
return YamlConfigData(__import__('yaml').safe_load(s))
|
5112
|
+
|
5113
|
+
|
5114
|
+
class YamlConfigRenderer(ConfigRenderer[YamlConfigData]):
|
5115
|
+
data_cls = YamlConfigData
|
5116
|
+
|
5117
|
+
def render(self, d: YamlConfigData) -> str:
|
5118
|
+
return __import__('yaml').safe_dump(d.obj)
|
5119
|
+
|
5120
|
+
|
5121
|
+
##
|
5122
|
+
|
5123
|
+
|
5124
|
+
@dc.dataclass(frozen=True)
|
5125
|
+
class IniConfigData(ConfigData):
|
5126
|
+
sections: IniSectionSettingsMap
|
5127
|
+
|
5128
|
+
def as_map(self) -> ConfigMap:
|
5129
|
+
return self.sections
|
5130
|
+
|
5131
|
+
|
5132
|
+
class IniConfigLoader(ConfigLoader[IniConfigData]):
|
5133
|
+
file_exts = ('ini',)
|
5134
|
+
|
5135
|
+
def load_str(self, s: str) -> IniConfigData:
|
5136
|
+
cp = configparser.ConfigParser()
|
5137
|
+
cp.read_string(s)
|
5138
|
+
return IniConfigData(extract_ini_sections(cp))
|
5139
|
+
|
5140
|
+
|
5141
|
+
class IniConfigRenderer(ConfigRenderer[IniConfigData]):
|
5142
|
+
data_cls = IniConfigData
|
5143
|
+
|
5144
|
+
def render(self, d: IniConfigData) -> str:
|
5145
|
+
return render_ini_sections(d.sections)
|
5146
|
+
|
5147
|
+
|
5148
|
+
##
|
5149
|
+
|
5150
|
+
|
5151
|
+
@dc.dataclass(frozen=True)
|
5152
|
+
class SwitchedConfigFileLoader:
|
5153
|
+
loaders: ta.Sequence[ConfigLoader]
|
5154
|
+
default: ta.Optional[ConfigLoader] = None
|
5155
|
+
|
5156
|
+
def load_file(self, p: str) -> ConfigData:
|
5157
|
+
n = os.path.basename(p)
|
5158
|
+
|
5159
|
+
for l in self.loaders:
|
5160
|
+
if l.match_file(n):
|
5161
|
+
return l.load_file(p)
|
5162
|
+
|
5163
|
+
if (d := self.default) is not None:
|
5164
|
+
return d.load_file(p)
|
5165
|
+
|
5166
|
+
raise NameError(n)
|
5167
|
+
|
5168
|
+
|
5169
|
+
DEFAULT_CONFIG_LOADERS: ta.Sequence[ConfigLoader] = [
|
5170
|
+
JsonConfigLoader(),
|
5171
|
+
TomlConfigLoader(),
|
5172
|
+
YamlConfigLoader(),
|
5173
|
+
IniConfigLoader(),
|
5174
|
+
]
|
5175
|
+
|
5176
|
+
DEFAULT_CONFIG_LOADER: ConfigLoader = JsonConfigLoader()
|
5177
|
+
|
5178
|
+
DEFAULT_CONFIG_FILE_LOADER = SwitchedConfigFileLoader(
|
5179
|
+
loaders=DEFAULT_CONFIG_LOADERS,
|
5180
|
+
default=DEFAULT_CONFIG_LOADER,
|
5181
|
+
)
|
5182
|
+
|
5183
|
+
|
5184
|
+
##
|
5185
|
+
|
5186
|
+
|
5187
|
+
@dc.dataclass(frozen=True)
|
5188
|
+
class SwitchedConfigRenderer:
|
5189
|
+
renderers: ta.Sequence[ConfigRenderer]
|
5190
|
+
|
5191
|
+
def render(self, d: ConfigData) -> str:
|
5192
|
+
for r in self.renderers:
|
5193
|
+
if r.match_data(d):
|
5194
|
+
return r.render(d)
|
5195
|
+
raise TypeError(d)
|
5196
|
+
|
5197
|
+
|
5198
|
+
DEFAULT_CONFIG_RENDERERS: ta.Sequence[ConfigRenderer] = [
|
5199
|
+
JsonConfigRenderer(),
|
5200
|
+
TomlConfigRenderer(),
|
5201
|
+
YamlConfigRenderer(),
|
5202
|
+
IniConfigRenderer(),
|
5203
|
+
]
|
5204
|
+
|
5205
|
+
DEFAULT_CONFIG_RENDERER = SwitchedConfigRenderer(DEFAULT_CONFIG_RENDERERS)
|
5206
|
+
|
5207
|
+
|
4846
5208
|
########################################
|
4847
5209
|
# ../../../omlish/lite/contextmanagers.py
|
4848
5210
|
|
@@ -6939,97 +7301,6 @@ def bind_interp_uv() -> InjectorBindings:
|
|
6939
7301
|
return inj.as_bindings(*lst)
|
6940
7302
|
|
6941
7303
|
|
6942
|
-
########################################
|
6943
|
-
# ../../configs.py
|
6944
|
-
|
6945
|
-
|
6946
|
-
##
|
6947
|
-
|
6948
|
-
|
6949
|
-
def parse_config_file(
|
6950
|
-
name: str,
|
6951
|
-
f: ta.TextIO,
|
6952
|
-
) -> ConfigMapping:
|
6953
|
-
if name.endswith('.toml'):
|
6954
|
-
return toml_loads(f.read())
|
6955
|
-
|
6956
|
-
elif any(name.endswith(e) for e in ('.yml', '.yaml')):
|
6957
|
-
yaml = __import__('yaml')
|
6958
|
-
return yaml.safe_load(f)
|
6959
|
-
|
6960
|
-
elif name.endswith('.ini'):
|
6961
|
-
import configparser
|
6962
|
-
cp = configparser.ConfigParser()
|
6963
|
-
cp.read_file(f)
|
6964
|
-
config_dct: ta.Dict[str, ta.Any] = {}
|
6965
|
-
for sec in cp.sections():
|
6966
|
-
cd = config_dct
|
6967
|
-
for k in sec.split('.'):
|
6968
|
-
cd = cd.setdefault(k, {})
|
6969
|
-
cd.update(cp.items(sec))
|
6970
|
-
return config_dct
|
6971
|
-
|
6972
|
-
else:
|
6973
|
-
return json.loads(f.read())
|
6974
|
-
|
6975
|
-
|
6976
|
-
def read_config_file(
|
6977
|
-
path: str,
|
6978
|
-
cls: ta.Type[T],
|
6979
|
-
*,
|
6980
|
-
prepare: ta.Optional[ta.Callable[[ConfigMapping], ConfigMapping]] = None,
|
6981
|
-
msh: ObjMarshalerManager = OBJ_MARSHALER_MANAGER,
|
6982
|
-
) -> T:
|
6983
|
-
with open(path) as cf:
|
6984
|
-
config_dct = parse_config_file(os.path.basename(path), cf)
|
6985
|
-
|
6986
|
-
if prepare is not None:
|
6987
|
-
config_dct = prepare(config_dct)
|
6988
|
-
|
6989
|
-
return msh.unmarshal_obj(config_dct, cls)
|
6990
|
-
|
6991
|
-
|
6992
|
-
##
|
6993
|
-
|
6994
|
-
|
6995
|
-
def build_config_named_children(
|
6996
|
-
o: ta.Union[
|
6997
|
-
ta.Sequence[ConfigMapping],
|
6998
|
-
ta.Mapping[str, ConfigMapping],
|
6999
|
-
None,
|
7000
|
-
],
|
7001
|
-
*,
|
7002
|
-
name_key: str = 'name',
|
7003
|
-
) -> ta.Optional[ta.Sequence[ConfigMapping]]:
|
7004
|
-
if o is None:
|
7005
|
-
return None
|
7006
|
-
|
7007
|
-
lst: ta.List[ConfigMapping] = []
|
7008
|
-
if isinstance(o, ta.Mapping):
|
7009
|
-
for k, v in o.items():
|
7010
|
-
check.isinstance(v, ta.Mapping)
|
7011
|
-
if name_key in v:
|
7012
|
-
n = v[name_key]
|
7013
|
-
if k != n:
|
7014
|
-
raise KeyError(f'Given names do not match: {n} != {k}')
|
7015
|
-
lst.append(v)
|
7016
|
-
else:
|
7017
|
-
lst.append({name_key: k, **v})
|
7018
|
-
|
7019
|
-
else:
|
7020
|
-
check.not_isinstance(o, str)
|
7021
|
-
lst.extend(o)
|
7022
|
-
|
7023
|
-
seen = set()
|
7024
|
-
for d in lst:
|
7025
|
-
n = d['name']
|
7026
|
-
if n in d:
|
7027
|
-
raise KeyError(f'Duplicate name: {n}')
|
7028
|
-
seen.add(n)
|
7029
|
-
|
7030
|
-
return lst
|
7031
|
-
|
7032
|
-
|
7033
7304
|
########################################
|
7034
7305
|
# ../commands/marshal.py
|
7035
7306
|
|
@@ -7506,6 +7777,106 @@ class SystemConfig:
|
|
7506
7777
|
platform: ta.Optional[Platform] = None
|
7507
7778
|
|
7508
7779
|
|
7780
|
+
########################################
|
7781
|
+
# ../../../omlish/configs/nginx.py
|
7782
|
+
"""
|
7783
|
+
See:
|
7784
|
+
- https://nginx.org/en/docs/dev/development_guide.html
|
7785
|
+
- https://nginx.org/en/docs/dev/development_guide.html#config_directives
|
7786
|
+
- https://nginx.org/en/docs/example.html
|
7787
|
+
"""
|
7788
|
+
|
7789
|
+
|
7790
|
+
@dc.dataclass()
|
7791
|
+
class NginxConfigItems:
|
7792
|
+
lst: ta.List['NginxConfigItem']
|
7793
|
+
|
7794
|
+
@classmethod
|
7795
|
+
def of(cls, obj: ta.Any) -> 'NginxConfigItems':
|
7796
|
+
if isinstance(obj, NginxConfigItems):
|
7797
|
+
return obj
|
7798
|
+
return cls([NginxConfigItem.of(e) for e in check.isinstance(obj, list)])
|
7799
|
+
|
7800
|
+
|
7801
|
+
@dc.dataclass()
|
7802
|
+
class NginxConfigItem:
|
7803
|
+
name: str
|
7804
|
+
args: ta.Optional[ta.List[str]] = None
|
7805
|
+
block: ta.Optional[NginxConfigItems] = None
|
7806
|
+
|
7807
|
+
@classmethod
|
7808
|
+
def of(cls, obj: ta.Any) -> 'NginxConfigItem':
|
7809
|
+
if isinstance(obj, NginxConfigItem):
|
7810
|
+
return obj
|
7811
|
+
args = check.isinstance(check.not_isinstance(obj, str), collections.abc.Sequence)
|
7812
|
+
name, args = check.isinstance(args[0], str), args[1:]
|
7813
|
+
if args and not isinstance(args[-1], str):
|
7814
|
+
block, args = NginxConfigItems.of(args[-1]), args[:-1]
|
7815
|
+
else:
|
7816
|
+
block = None
|
7817
|
+
return NginxConfigItem(name, [check.isinstance(e, str) for e in args], block=block)
|
7818
|
+
|
7819
|
+
|
7820
|
+
def render_nginx_config(wr: IndentWriter, obj: ta.Any) -> None:
|
7821
|
+
if isinstance(obj, NginxConfigItem):
|
7822
|
+
wr.write(obj.name)
|
7823
|
+
for e in obj.args or ():
|
7824
|
+
wr.write(' ')
|
7825
|
+
wr.write(e)
|
7826
|
+
if obj.block:
|
7827
|
+
wr.write(' {\n')
|
7828
|
+
with wr.indent():
|
7829
|
+
render_nginx_config(wr, obj.block)
|
7830
|
+
wr.write('}\n')
|
7831
|
+
else:
|
7832
|
+
wr.write(';\n')
|
7833
|
+
|
7834
|
+
elif isinstance(obj, NginxConfigItems):
|
7835
|
+
for e2 in obj.lst:
|
7836
|
+
render_nginx_config(wr, e2)
|
7837
|
+
|
7838
|
+
else:
|
7839
|
+
raise TypeError(obj)
|
7840
|
+
|
7841
|
+
|
7842
|
+
def render_nginx_config_str(obj: ta.Any) -> str:
|
7843
|
+
iw = IndentWriter()
|
7844
|
+
render_nginx_config(iw, obj)
|
7845
|
+
return iw.getvalue()
|
7846
|
+
|
7847
|
+
|
7848
|
+
########################################
|
7849
|
+
# ../../../omlish/lite/configs.py
|
7850
|
+
|
7851
|
+
|
7852
|
+
##
|
7853
|
+
|
7854
|
+
|
7855
|
+
def load_config_file_obj(
|
7856
|
+
f: str,
|
7857
|
+
cls: ta.Type[T],
|
7858
|
+
*,
|
7859
|
+
prepare: ta.Union[
|
7860
|
+
ta.Callable[[ConfigMap], ConfigMap],
|
7861
|
+
ta.Iterable[ta.Callable[[ConfigMap], ConfigMap]],
|
7862
|
+
] = (),
|
7863
|
+
msh: ObjMarshalerManager = OBJ_MARSHALER_MANAGER,
|
7864
|
+
) -> T:
|
7865
|
+
config_data = DEFAULT_CONFIG_FILE_LOADER.load_file(f)
|
7866
|
+
|
7867
|
+
config_dct = config_data.as_map()
|
7868
|
+
|
7869
|
+
if prepare is not None:
|
7870
|
+
if isinstance(prepare, ta.Iterable):
|
7871
|
+
pfs = list(prepare)
|
7872
|
+
else:
|
7873
|
+
pfs = [prepare]
|
7874
|
+
for pf in pfs:
|
7875
|
+
config_dct = pf(config_dct)
|
7876
|
+
|
7877
|
+
return msh.unmarshal_obj(config_dct, cls)
|
7878
|
+
|
7879
|
+
|
7509
7880
|
########################################
|
7510
7881
|
# ../../../omlish/logs/standard.py
|
7511
7882
|
"""
|
@@ -7956,78 +8327,6 @@ class AbstractAsyncSubprocesses(BaseSubprocesses):
|
|
7956
8327
|
return ret.decode().strip()
|
7957
8328
|
|
7958
8329
|
|
7959
|
-
########################################
|
7960
|
-
# ../../../omserv/nginx/configs.py
|
7961
|
-
"""
|
7962
|
-
TODO:
|
7963
|
-
- omnibus/jmespath
|
7964
|
-
|
7965
|
-
https://nginx.org/en/docs/dev/development_guide.html
|
7966
|
-
https://nginx.org/en/docs/dev/development_guide.html#config_directives
|
7967
|
-
https://nginx.org/en/docs/example.html
|
7968
|
-
|
7969
|
-
https://github.com/yandex/gixy
|
7970
|
-
"""
|
7971
|
-
|
7972
|
-
|
7973
|
-
@dc.dataclass()
|
7974
|
-
class NginxConfigItems:
|
7975
|
-
lst: ta.List['NginxConfigItem']
|
7976
|
-
|
7977
|
-
@classmethod
|
7978
|
-
def of(cls, obj: ta.Any) -> 'NginxConfigItems':
|
7979
|
-
if isinstance(obj, NginxConfigItems):
|
7980
|
-
return obj
|
7981
|
-
return cls([NginxConfigItem.of(e) for e in check.isinstance(obj, list)])
|
7982
|
-
|
7983
|
-
|
7984
|
-
@dc.dataclass()
|
7985
|
-
class NginxConfigItem:
|
7986
|
-
name: str
|
7987
|
-
args: ta.Optional[ta.List[str]] = None
|
7988
|
-
block: ta.Optional[NginxConfigItems] = None
|
7989
|
-
|
7990
|
-
@classmethod
|
7991
|
-
def of(cls, obj: ta.Any) -> 'NginxConfigItem':
|
7992
|
-
if isinstance(obj, NginxConfigItem):
|
7993
|
-
return obj
|
7994
|
-
args = check.isinstance(check.not_isinstance(obj, str), collections.abc.Sequence)
|
7995
|
-
name, args = check.isinstance(args[0], str), args[1:]
|
7996
|
-
if args and not isinstance(args[-1], str):
|
7997
|
-
block, args = NginxConfigItems.of(args[-1]), args[:-1]
|
7998
|
-
else:
|
7999
|
-
block = None
|
8000
|
-
return NginxConfigItem(name, [check.isinstance(e, str) for e in args], block=block)
|
8001
|
-
|
8002
|
-
|
8003
|
-
def render_nginx_config(wr: IndentWriter, obj: ta.Any) -> None:
|
8004
|
-
if isinstance(obj, NginxConfigItem):
|
8005
|
-
wr.write(obj.name)
|
8006
|
-
for e in obj.args or ():
|
8007
|
-
wr.write(' ')
|
8008
|
-
wr.write(e)
|
8009
|
-
if obj.block:
|
8010
|
-
wr.write(' {\n')
|
8011
|
-
with wr.indent():
|
8012
|
-
render_nginx_config(wr, obj.block)
|
8013
|
-
wr.write('}\n')
|
8014
|
-
else:
|
8015
|
-
wr.write(';\n')
|
8016
|
-
|
8017
|
-
elif isinstance(obj, NginxConfigItems):
|
8018
|
-
for e2 in obj.lst:
|
8019
|
-
render_nginx_config(wr, e2)
|
8020
|
-
|
8021
|
-
else:
|
8022
|
-
raise TypeError(obj)
|
8023
|
-
|
8024
|
-
|
8025
|
-
def render_nginx_config_str(obj: ta.Any) -> str:
|
8026
|
-
iw = IndentWriter()
|
8027
|
-
render_nginx_config(iw, obj)
|
8028
|
-
return iw.getvalue()
|
8029
|
-
|
8030
|
-
|
8031
8330
|
########################################
|
8032
8331
|
# ../../../omdev/interp/providers/base.py
|
8033
8332
|
"""
|
@@ -12314,7 +12613,7 @@ class MainCli(ArgparseCli):
|
|
12314
12613
|
if cf is None:
|
12315
12614
|
return ManageConfig()
|
12316
12615
|
else:
|
12317
|
-
return
|
12616
|
+
return load_config_file_obj(cf, ManageConfig)
|
12318
12617
|
|
12319
12618
|
#
|
12320
12619
|
|
@@ -12385,7 +12684,7 @@ class MainCli(ArgparseCli):
|
|
12385
12684
|
cmds.append(cmd)
|
12386
12685
|
|
12387
12686
|
for cf in self.args.command_file or []:
|
12388
|
-
cmd =
|
12687
|
+
cmd = load_config_file_obj(cf, Command, msh=msh)
|
12389
12688
|
cmds.append(cmd)
|
12390
12689
|
|
12391
12690
|
#
|