Project

General

Profile

1 3107 perry
#!/usr/bin/python
2
"""
3
 Transfers documents from one metacat server to another
4
 Author: matt perry
5
 Date: 09/28/06
6
"""
7
8
import metacat
9
import sys
10
11
try:
12
    docidlist = sys.argv[1]
13
except:
14
    print
15
    print " usage: python transferEml.py docidlist.txt "
16
    print "        where docidlist.txt is a line-delimited list of docids "
17
    print
18
    sys.exit(1)
19
20
print "Logging into destination server"
21
dest = metacat.MetacatClient('yourserver:8180','/knb/metacat')
22
dest.login('user','password','NCEAS')
23
24
print "Logging into source server"
25
src = metacat.MetacatClient('knb.ecoinformatics.org', '/knb/metacat')
26
src.login('user','password','NCEAS')
27
28
print "Open docid list and loop"
29
for docid in open(docidlist,'r').readlines():
30
    docid = docid.strip().replace('\n','')
31
    if docid != '' and docid is not None:
32
       print " reading docid " + docid
33
       eml = src.read(docid)
34
       if eml:
35
           print " inserting docid " + docid
36
           response = dest.insert(docid + ".1" ,eml)
37
           if not response:
38
              print "   insert failed"
39
       else:
40
           print "   docid " + docid + " not found"
41
42
print "Logging out"
43
dest.logout()
44
src.logout()
45
46
47