Package qm :: Package test :: Package classes :: Module local_host
[hide private]
[frames] | no frames]

Source Code for Module qm.test.classes.local_host

 1  ######################################################################## 
 2  # 
 3  # File:   local_host.py 
 4  # Author: Mark Mitchell 
 5  # Date:   2005-06-03 
 6  # 
 7  # Contents: 
 8  #   LocalHost 
 9  # 
10  # Copyright (c) 2005 by CodeSourcery, LLC.  All rights reserved.  
11  # 
12  ######################################################################## 
13   
14  ######################################################################## 
15  # Imports 
16  ####################################################################### 
17   
18  import os 
19  import os.path 
20  from   qm.host import Host 
21  import shutil 
22   
23  ######################################################################## 
24  # Classes 
25  ####################################################################### 
26   
27 -class LocalHost(Host):
28 """A 'LocalHost' is the machine on which Python is running. 29 30 The default directory for a 'LocalHost' is the current working 31 directory for this Python process.""" 32
33 - def UploadFile(self, local_file, remote_file = None):
34 35 if remote_file is None: 36 remote_file = os.path.basename(local_file) 37 # Do not copy the files if they are the same. 38 if not self._SameFile(local_file, remote_file): 39 shutil.copy(local_file, remote_file)
40 41
42 - def UploadAndRun(self, path, arguments, environment = None, 43 timeout = -1):
44 45 # There is no need to actually upload the file, since it is 46 # running on the local machine. 47 return self.Run(path, arguments, environment, timeout)
48 49
50 - def DownloadFile(self, remote_file, local_file = None):
51 52 return self.UploadFile(remote_file, local_file)
53 54
55 - def _SameFile(self, file1, file2):
56 """Return true iff 'file1' and 'file2' are the same file. 57 58 returns -- True iff 'file1' and 'file2' are the same file, 59 even if they have different names.""" 60 61 if not os.path.exists(file1) or not os.path.exists(file2): 62 return False 63 if hasattr(os.path, "samefile"): 64 return os.path.samefile(file1, file2) 65 return (os.path.normcase(os.path.abspath(file1)) 66 == os.path.normcase(os.path.abspath(file2)))
67 68
69 - def DeleteFile(self, remote_file):
70 71 os.remove(remote_file)
72