X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=juju%2Fconstraints.py;h=97529e46ad5accd7dc5d6d45e3d7e01d9347e639;hb=2f274d7544ca51b8a958fa8d9beb48a471a17d39;hp=43c048ae4fb87cc0e1434540b0725a22d31c1da1;hpb=d703653028e7ea25da20f205b9ff341c75694e33;p=osm%2FN2VC.git diff --git a/juju/constraints.py b/juju/constraints.py index 43c048a..97529e4 100644 --- a/juju/constraints.py +++ b/juju/constraints.py @@ -28,6 +28,9 @@ FACTORS = { "P": 1024 * 1024 * 1024 } +SNAKE1 = re.compile(r'(.)([A-Z][a-z]+)') +SNAKE2 = re.compile('([a-z0-9])([A-Z])') + def parse(constraints): """ Constraints must be expressed as a string containing only spaces @@ -37,6 +40,9 @@ def parse(constraints): if constraints is None: return None + if constraints == "": + return None + if type(constraints) is dict: # Fowards compatibilty: already parsed return constraints @@ -52,6 +58,11 @@ def normalize_key(key): key = key.strip() key = key.replace("-", "_") # Our _client lib wants "_" in place of "-" + + # Convert camelCase to snake_case + key = SNAKE1.sub(r'\1_\2', key) + key = SNAKE2.sub(r'\1_\2', key).lower() + return key @@ -68,4 +79,7 @@ def normalize_value(value): values = [normalize_value(v) for v in values] return values + if value.isdigit(): + return int(value) + return value