Module Utilities
[hide private]
[frames] | no frames]

Source Code for Module Utilities

  1  # Copyright (C) 2005, 2006 Joint Institute for VLBI in Europe 
  2  # 
  3  # This program is free software; you can redistribute it and/or modify 
  4  # it under the terms of the GNU General Public License as published by 
  5  # the Free Software Foundation; either version 2 of the License, or 
  6  # (at your option) any later version. 
  7  # 
  8  # This program is distributed in the hope that it will be useful, 
  9  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 10  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 11  # GNU General Public License for more details. 
 12   
 13  # You should have received a copy of the GNU General Public License 
 14  # along with this program; if not, write to the Free Software 
 15  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 16   
 17  from AIPS import * 
 18  from AIPSTask import * 
 19  from AIPSData import * 
 20  import socket 
 21  import sys, re 
 22   
23 -def rdiskappend(proxyname,remotedisk):
24 """Appends proxyname to the global proxy list, and adds the correct 25 (proxyname,remotedisk) pair as an AIPSDisk object in the global disk 26 list. Returns the disk index in the AIPS.disks list.""" 27 28 # Proxyname is only added to the global proxy list if it isn't already 29 # there, of course, and the appropriate entry from AIPS.proxies is used 30 # to create an AIPSDisk object and stick it on the end of the AIPS.disks 31 # list. We assume that the proxy is specified as a URL with the FQDN, 32 # although duplicates won't really cause any huge problems (it's just 33 # unsightly). 34 35 i = 0 36 proxyfound = False 37 for proxy in AIPS.proxies : 38 if proxy == proxyname : 39 proxyid = i 40 proxyfound = True 41 break 42 i = i + 1 43 44 if not proxyfound : 45 AIPS.proxies.append(proxyname) 46 proxyid = len(AIPS.proxies) - 1 47 48 rdisk = AIPSDisk(AIPS.proxies[proxyid],remotedisk) 49 50 j = 1 # First disk entry in AIPS.disks is always None! 51 diskfound = False 52 for disk in AIPS.disks[1:] : 53 if (rdisk.url == disk.url) and (rdisk.disk == disk.disk) : 54 diskid = j 55 diskfound = True 56 break 57 j = j + 1 58 59 if not diskfound : 60 AIPS.disks.append(rdisk) 61 diskid = len(AIPS.disks) - 1 62 63 return diskid
64
65 -def rcopy(AIPSDataSource,AIPSDataTarget):
66 """ 67 Copies data from one AIPS repository to another on a remote host. 68 """ 69 70 # Takes two AIPSData objects as arguments. The first refers to the data 71 # store on the local host. The second is a "fake" object that is filled 72 # in by rcopy. Works by converting first to a FITS file, 73 # transporting via the FileTransport server and the transporter client 74 # method, and then importing the result into the remote AIPS client. 75 # FITS transport implies a substantial conversion overhead, which is 76 # required once on each end, but has the advantage of automatically 77 # adjusting to the correct byte-endianness. 78 79 fitswrite = AIPSTask('FITTP') 80 fitswrite.indata = AIPSDataSource 81 # truncate so that outfile is not longer than 48 total 82 # characters, due to AIPS being a retarded 70's child... 83 inname = fitswrite.inname[0:37] 84 outname = "/tmp/" + inname + ".fits" 85 if os.path.exists(outname) : 86 os.remove(outname) 87 fitswrite.outfile = outname 88 fitswrite.go() 89 90 # extract the target hostname from the proxy url 91 hostpattern = "http://(.*):[0-9]+" 92 match = re.search(hostpattern,AIPS.disks[AIPSDataTarget.disk].url) 93 rhost = match.group(1) 94 95 # beam me over, scotty 96 remotename = transport(outname,rhost) 97 98 # and import the temporary FITS file at the other end 99 fitsimport = AIPSTask('FITLD') 100 fitsimport.infile = remotename 101 fitsimport.outdata = AIPSDataTarget 102 fitsimport.go() 103 104 # clean up /tmp on the localhost 105 # os.remove(outname) 106 return 0
107
108 -def transport(file,server,port=8001) :
109 """ 110 Sends the named file to a tmp directory on server, returning the name of 111 the file on the remote system. 112 """ 113 114 input = open(file,'r') 115 out = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 116 out.connect((server,port)) 117 118 while True: 119 buffer = input.read(65536) 120 if not buffer : break 121 out.sendall(buffer) 122 remote_filename = out.recv(1024) 123 124 out.close() 125 return remote_filename
126