summaryrefslogtreecommitdiffstats
path: root/cns-libs/cnslibs/common/naming.py
diff options
context:
space:
mode:
authorValerii Ponomarov <vponomar@redhat.com>2019-03-07 20:30:44 +0530
committervponomar <vponomar@redhat.com>2019-03-18 11:34:37 +0000
commit32b611b2a6498b1de307142e335e09d1e0ec082c (patch)
treeaaf600ab6e6adabab7c3facbf30ae6f056731969 /cns-libs/cnslibs/common/naming.py
parent0fcdb081517c5904969b89b20326d21b361e448e (diff)
Reorder lib files removing redundant dir layer
Move all the files of 'cns-libs/cnslibs/common' dir to the 'openshift-storage-libs/openshiftstoragelibs', because 'common' is the only dir there, which doesn't really makes sense. And "cns" is old project name, so, replace it with "openshift-storage-libs". Also, fix all the imports of these libs. Change-Id: Ife00a73554e73b21b214b15016b0c8dbbf423446
Diffstat (limited to 'cns-libs/cnslibs/common/naming.py')
-rw-r--r--cns-libs/cnslibs/common/naming.py56
1 files changed, 0 insertions, 56 deletions
diff --git a/cns-libs/cnslibs/common/naming.py b/cns-libs/cnslibs/common/naming.py
deleted file mode 100644
index b44559ad..00000000
--- a/cns-libs/cnslibs/common/naming.py
+++ /dev/null
@@ -1,56 +0,0 @@
-"""Helper functions for working with names for volumes, resources, etc.
-"""
-
-import string
-import random
-import re
-
-# we only use lowercase here because kubernetes requires
-# names to be lowercase or digits, so that is our default
-UNIQUE_CHARS = (string.lowercase + string.digits)
-
-
-def make_unique_label(prefix=None, suffix=None, sep='-',
- clean=r'[^a-zA-Z0-9]+', unique_len=8,
- unique_chars=UNIQUE_CHARS):
- """Generate a unique name string based on an optional prefix,
- suffix, and pseudo-random set of alphanumeric characters.
-
- Args:
- prefix (str): Start of the unique string.
- suffix (str): End of the unique string.
- sep (str): Separator string (between sections/invalid chars).
- clean (str): Reqular expression matching invalid chars.
- that will be replaced by `sep` if found in the prefix or suffix
- unique_len (int): Length of the unique part.
- unique_chars (str): String representing the set of characters
- the unique part will draw from.
- Returns:
- str: The uniqueish string.
- """
- cre = re.compile(clean)
- parts = []
- if prefix:
- parts.append(cre.sub(sep, prefix))
- parts.append(''.join(random.choice(unique_chars)
- for _ in range(unique_len)))
- if suffix:
- parts.append(cre.sub(sep, suffix))
- return sep.join(parts)
-
-
-def extract_method_name(full_name, keep_class=False):
- """Given a full test name as returned from TestCase.id() return
- just the method part or class.method.
-
- Args:
- full_name (str): Dot separated name of test.
- keep_class (str): Retain the class name, if false only the
- method name will be returned.
- Returns:
- str: Method name or class.method_name.
- """
- offset = -1
- if keep_class:
- offset = -2
- return '.'.join(full_name.split('.')[offset:])