1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 from AIPS import *
18 from AIPSTask import *
19 from AIPSData import *
20 import socket
21 import sys, re
22
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
29
30
31
32
33
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
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
71
72
73
74
75
76
77
78
79 fitswrite = AIPSTask('FITTP')
80 fitswrite.indata = AIPSDataSource
81
82
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
91 hostpattern = "http://(.*):[0-9]+"
92 match = re.search(hostpattern,AIPS.disks[AIPSDataTarget.disk].url)
93 rhost = match.group(1)
94
95
96 remotename = transport(outname,rhost)
97
98
99 fitsimport = AIPSTask('FITLD')
100 fitsimport.infile = remotename
101 fitsimport.outdata = AIPSDataTarget
102 fitsimport.go()
103
104
105
106 return 0
107
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