check locality more appropriately
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Mon, 3 Mar 2008 07:50:54 +0000 (07:50 +0000)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Mon, 3 Mar 2008 07:50:54 +0000 (07:50 +0000)
system/TestBox.py
system/utils.py

index 63300ed..e5c3e48 100644 (file)
@@ -9,8 +9,11 @@ class TestBox:
         self.hostname=hostname
         self.key=key
 
+    def is_local(self):
+        return utils.is_local (self.hostname)
+
     def run (self,command):
-        if self.hostname == "localhost":
+        if self.is_local():
             return utils.system(command)
         else:
             if self.key:
@@ -22,7 +25,7 @@ class TestBox:
             return utils.system(to_run)
         
     def copy (self,local_file):
-        if self.hostname == "localhost":
+        if self.is_local():
             return 0
         else:
             if self.key:
index a30b004..b246b18 100644 (file)
@@ -125,3 +125,11 @@ def backslash_shell_specials (command):
             result +=char
     return result
 
+# check main IP address against the provided hostname
+def is_local (hostname):
+    if hostname == "localhost":
+        return True
+    import socket
+    local_ip = socket.gethostbyname(socket.gethostname())
+    remote_ip = socket.gethostbyname(hostname)
+    return local_ip==remote_ip