diff mbox

[KVM-AUTOTEST,3/6] KVM test: add a function that translates user specified paths to real ones

Message ID 1872f2f7ac12ca9fa788f5f14ae2f8afc9f26db7.1249835043.git.mgoldish@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Michael Goldish Aug. 9, 2009, 4:33 p.m. UTC
If a user specified path is an absolute one, it is returned as is.
If it's relative, it's appended to a certain base path.

This function is meant to allow framework and test code to treat all user
specified paths equally.

Signed-off-by: Michael Goldish <mgoldish@redhat.com>
---
 client/tests/kvm/kvm_utils.py |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)
diff mbox

Patch

diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py
index 4c4753b..5e9e90d 100644
--- a/client/tests/kvm/kvm_utils.py
+++ b/client/tests/kvm/kvm_utils.py
@@ -677,6 +677,21 @@  def find_free_ports(start_port, end_port, count):
 
 # The following are miscellaneous utility functions.
 
+def get_path(base_path, user_path):
+    """
+    Translate a user specified path to a real path.
+    If user_path is relative, append it to base_path.
+    If user_path is absolute, return it as is.
+
+    @param base_path: The base path of relative user specified paths.
+    @param user_path: The user specified path.
+    """
+    if os.path.isabs(user_path):
+        return user_path
+    else:
+        return os.path.join(base_path, user_path)
+
+
 def generate_random_string(length):
     """
     Return a random string using alphanumeric characters.