ominfra 0.0.0.dev148__py3-none-any.whl → 0.0.0.dev149__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
ominfra/clouds/aws/cli.py CHANGED
@@ -1,4 +1,4 @@
1
- from omlish import argparse as ap
1
+ from omlish.argparse import all as ap
2
2
  from omlish.formats import json
3
3
 
4
4
  from . import metadata
@@ -4,8 +4,8 @@ import dataclasses as dc
4
4
  import json
5
5
  import typing as ta
6
6
 
7
+ from omlish.io.buffers import DelimitingBuffer
7
8
  from omlish.lite.check import check_isinstance
8
- from omlish.lite.io import DelimitingBuffer
9
9
  from omlish.lite.logs import log
10
10
 
11
11
 
@@ -37,8 +37,8 @@ import os.path
37
37
  import typing as ta
38
38
 
39
39
  from omlish.lite.check import check_equal
40
- from omlish.lite.check import check_non_empty
41
40
  from omlish.lite.check import check_non_empty_str
41
+ from omlish.lite.check import check_not_empty
42
42
  from omlish.lite.check import check_not_in
43
43
 
44
44
 
@@ -151,7 +151,7 @@ class DeployPath:
151
151
  parts: ta.Sequence[DeployPathPart]
152
152
 
153
153
  def __post_init__(self) -> None:
154
- check_non_empty(self.parts)
154
+ check_not_empty(self.parts)
155
155
  for p in self.parts[:-1]:
156
156
  check_equal(p.kind, 'dir')
157
157
 
@@ -989,6 +989,11 @@ def check_non_empty_str(v: ta.Optional[str]) -> str:
989
989
  return v
990
990
 
991
991
 
992
+ def check_arg(v: bool, msg: str = 'Illegal argument') -> None:
993
+ if not v:
994
+ raise ValueError(msg)
995
+
996
+
992
997
  def check_state(v: bool, msg: str = 'Illegal state') -> None:
993
998
  if not v:
994
999
  raise ValueError(msg)
@@ -1041,7 +1046,7 @@ def check_empty(v: SizedT) -> SizedT:
1041
1046
  return v
1042
1047
 
1043
1048
 
1044
- def check_non_empty(v: SizedT) -> SizedT:
1049
+ def check_not_empty(v: SizedT) -> SizedT:
1045
1050
  if not len(v):
1046
1051
  raise ValueError(v)
1047
1052
  return v
@@ -1630,65 +1635,7 @@ class AwsDataclassMeta:
1630
1635
 
1631
1636
 
1632
1637
  ########################################
1633
- # ../../../../../omlish/lite/contextmanagers.py
1634
-
1635
-
1636
- ##
1637
-
1638
-
1639
- class ExitStacked:
1640
- _exit_stack: ta.Optional[contextlib.ExitStack] = None
1641
-
1642
- def __enter__(self: ExitStackedT) -> ExitStackedT:
1643
- check_state(self._exit_stack is None)
1644
- es = self._exit_stack = contextlib.ExitStack()
1645
- es.__enter__()
1646
- return self
1647
-
1648
- def __exit__(self, exc_type, exc_val, exc_tb):
1649
- if (es := self._exit_stack) is None:
1650
- return None
1651
- self._exit_contexts()
1652
- return es.__exit__(exc_type, exc_val, exc_tb)
1653
-
1654
- def _exit_contexts(self) -> None:
1655
- pass
1656
-
1657
- def _enter_context(self, cm: ta.ContextManager[T]) -> T:
1658
- es = check_not_none(self._exit_stack)
1659
- return es.enter_context(cm)
1660
-
1661
-
1662
- ##
1663
-
1664
-
1665
- @contextlib.contextmanager
1666
- def defer(fn: ta.Callable) -> ta.Generator[ta.Callable, None, None]:
1667
- try:
1668
- yield fn
1669
- finally:
1670
- fn()
1671
-
1672
-
1673
- @contextlib.contextmanager
1674
- def attr_setting(obj, attr, val, *, default=None): # noqa
1675
- not_set = object()
1676
- orig = getattr(obj, attr, not_set)
1677
- try:
1678
- setattr(obj, attr, val)
1679
- if orig is not not_set:
1680
- yield orig
1681
- else:
1682
- yield default
1683
- finally:
1684
- if orig is not_set:
1685
- delattr(obj, attr)
1686
- else:
1687
- setattr(obj, attr, orig)
1688
-
1689
-
1690
- ########################################
1691
- # ../../../../../omlish/lite/io.py
1638
+ # ../../../../../omlish/io/buffers.py
1692
1639
 
1693
1640
 
1694
1641
  class DelimitingBuffer:
@@ -1875,7 +1822,7 @@ class IncrementalWriteBuffer:
1875
1822
  ) -> None:
1876
1823
  super().__init__()
1877
1824
 
1878
- check_non_empty(data)
1825
+ check_not_empty(data)
1879
1826
  self._len = len(data)
1880
1827
  self._write_size = write_size
1881
1828
 
@@ -1890,11 +1837,11 @@ class IncrementalWriteBuffer:
1890
1837
  return self._len - self._pos
1891
1838
 
1892
1839
  def write(self, fn: ta.Callable[[bytes], int]) -> int:
1893
- lst = check_non_empty(self._lst)
1840
+ lst = check_not_empty(self._lst)
1894
1841
 
1895
1842
  t = 0
1896
1843
  for i, d in enumerate(lst): # noqa
1897
- n = fn(check_non_empty(d))
1844
+ n = fn(check_not_empty(d))
1898
1845
  if not n:
1899
1846
  break
1900
1847
  t += n
@@ -1909,6 +1856,64 @@ class IncrementalWriteBuffer:
1909
1856
  return t
1910
1857
 
1911
1858
 
1859
+ ########################################
1860
+ # ../../../../../omlish/lite/contextmanagers.py
1861
+
1862
+
1863
+ ##
1864
+
1865
+
1866
+ class ExitStacked:
1867
+ _exit_stack: ta.Optional[contextlib.ExitStack] = None
1868
+
1869
+ def __enter__(self: ExitStackedT) -> ExitStackedT:
1870
+ check_state(self._exit_stack is None)
1871
+ es = self._exit_stack = contextlib.ExitStack()
1872
+ es.__enter__()
1873
+ return self
1874
+
1875
+ def __exit__(self, exc_type, exc_val, exc_tb):
1876
+ if (es := self._exit_stack) is None:
1877
+ return None
1878
+ self._exit_contexts()
1879
+ return es.__exit__(exc_type, exc_val, exc_tb)
1880
+
1881
+ def _exit_contexts(self) -> None:
1882
+ pass
1883
+
1884
+ def _enter_context(self, cm: ta.ContextManager[T]) -> T:
1885
+ es = check_not_none(self._exit_stack)
1886
+ return es.enter_context(cm)
1887
+
1888
+
1889
+ ##
1890
+
1891
+
1892
+ @contextlib.contextmanager
1893
+ def defer(fn: ta.Callable) -> ta.Generator[ta.Callable, None, None]:
1894
+ try:
1895
+ yield fn
1896
+ finally:
1897
+ fn()
1898
+
1899
+
1900
+ @contextlib.contextmanager
1901
+ def attr_setting(obj, attr, val, *, default=None): # noqa
1902
+ not_set = object()
1903
+ orig = getattr(obj, attr, not_set)
1904
+ try:
1905
+ setattr(obj, attr, val)
1906
+ if orig is not not_set:
1907
+ yield orig
1908
+ else:
1909
+ yield default
1910
+ finally:
1911
+ if orig is not_set:
1912
+ delattr(obj, attr)
1913
+ else:
1914
+ setattr(obj, attr, orig)
1915
+
1916
+
1912
1917
  ########################################
1913
1918
  # ../../../../../omlish/lite/logs.py
1914
1919
  """
ominfra/scripts/manage.py CHANGED
@@ -1189,6 +1189,11 @@ def check_non_empty_str(v: ta.Optional[str]) -> str:
1189
1189
  return v
1190
1190
 
1191
1191
 
1192
+ def check_arg(v: bool, msg: str = 'Illegal argument') -> None:
1193
+ if not v:
1194
+ raise ValueError(msg)
1195
+
1196
+
1192
1197
  def check_state(v: bool, msg: str = 'Illegal state') -> None:
1193
1198
  if not v:
1194
1199
  raise ValueError(msg)
@@ -1241,7 +1246,7 @@ def check_empty(v: SizedT) -> SizedT:
1241
1246
  return v
1242
1247
 
1243
1248
 
1244
- def check_non_empty(v: SizedT) -> SizedT:
1249
+ def check_not_empty(v: SizedT) -> SizedT:
1245
1250
  if not len(v):
1246
1251
  raise ValueError(v)
1247
1252
  return v