diff --git a/fdict.py b/fdict.py deleted file mode 100644 index 99e520b..0000000 --- a/fdict.py +++ /dev/null @@ -1,25 +0,0 @@ -from collections import UserDict -from typing import Any - -class _NotPresent: - """ - Type for representing non-existent dictionary keys. - - See :class:`_FillableDict` - """ - -class _FillableDict(UserDict): - """Use :method:`fill` to add key if not present.""" - - def __init__(self, data: dict): - self.data = data - - def fill(self, key: str, value: Any) -> None: - if self.data.get(key, _NotPresent) is _NotPresent: - self.data[key] = value - -d = _FillableDict({'a': None, 'b': 'BBBB'}) -d.fill('c', 'CCCCCCCCC') -d.fill('a', 'CCCCCCCCC') -d['a'].fill('gg', 'AAAAAAAA') -print(d) diff --git a/instance.yaml b/instance.yaml deleted file mode 100644 index a6b214b..0000000 --- a/instance.yaml +++ /dev/null @@ -1,10 +0,0 @@ -title: dev-1 -vcpus: 4 -memory: 4096 -volumes: - - is_system: true - type: file - target: vda - capacity: - value: 5 - unit: GiB diff --git a/pars.py b/pars.py deleted file mode 100644 index a33742c..0000000 --- a/pars.py +++ /dev/null @@ -1,34 +0,0 @@ -import re - - -def _split_unit(val: str) -> dict | None: - match = re.match(r'([0-9]+)([a-z]+)', val, re.I) - if match: - return { - 'value': match.groups()[0], - 'unit': match.groups()[1], - } - return None - - -def _parse_complex_arg(arg: str) -> dict: - # key=value --> {'key': 'value'} - if re.match(r'.+=.+', arg): - key, val = arg.split('=') - # system --> {'is_system': True} - # ro --> {'is_readonly': True} - elif re.match(r'^[a-z0-9_\.\-]+$', arg, re.I): - key = 'is_' + arg.replace('ro', 'readonly') - val = True - else: - raise ValueError('Invalid argument pattern') - # key=15GiB --> {'key': {'value': 15, 'unit': 'GiB'}} - if not isinstance(val, bool): - val = _split_unit(val) or val - return {key: val} - - -print(_parse_complex_arg('source=/volumes/50c4410b-2ef0-4ffd-a2e5-04f0212772d4.qcow2')) -print(_parse_complex_arg('capacity=15GiB')) -print(_parse_complex_arg('system')) -print(_parse_complex_arg('cpu.cores=8')) diff --git a/pd.py b/pd.py deleted file mode 100644 index 78d91a9..0000000 --- a/pd.py +++ /dev/null @@ -1,20 +0,0 @@ -from pydantic import BaseModel, Extra - - -class EntityModel(BaseModel): - """Basic entity model.""" - - aaa: int - bbb: int - - class Config: - extra = Extra.forbid - - -class Some(EntityModel): - ooo: str - www: str - -a = Some(ooo='dsda', www='wcd', sds=1) - -print(a)