bug 537 SDN-assist does not connect new instances over an existing vim network
[osm/RO.git] / osm_ro / utils.py
index 00f6f2d..2ae062f 100644 (file)
@@ -30,6 +30,7 @@ __author__="Alfonso Tierno, Gerardo Garcia"
 __date__ ="$08-sep-2014 12:21:22$"
 
 import datetime
+import warnings
 from jsonschema import validate as js_v, exceptions as js_e
 #from bs4 import BeautifulSoup
 
@@ -178,4 +179,32 @@ def check_valid_uuid(uuid):
         except js_e.ValidationError:
             return False
     return False
-    
+
+
+def expand_brackets(text):
+    """
+    Change a text with TEXT[ABC..] into a list with [TEXTA, TEXTB, TEXC, ...
+    if no bracket is used it just return the a list with the single text
+    It uses recursivity to allow several [] in the text
+    :param text:
+    :return:
+    """
+    start = text.find("[")
+    end = text.find("]")
+    if start < 0 or end < 0:
+        return [text]
+    text_list = []
+    for char in text[start+1:end]:
+        text_list += expand_brackets(text[:start] + char + text[end+1:])
+    return text_list
+
+def deprecated(message):
+  def deprecated_decorator(func):
+      def deprecated_func(*args, **kwargs):
+          warnings.warn("{} is a deprecated function. {}".format(func.__name__, message),
+                        category=DeprecationWarning,
+                        stacklevel=2)
+          warnings.simplefilter('default', DeprecationWarning)
+          return func(*args, **kwargs)
+      return deprecated_func
+  return deprecated_decorator
\ No newline at end of file