Project

General

Profile

1
#!/usr/bin/python
2
#
3
#  '$RCSfile$'
4
#  Copyright: 2000 Regents of the University of California
5
#
6
#   '$Author: leinfelder $'
7
#     '$Date: 2013-09-23 15:54:55 -0700 (Mon, 23 Sep 2013) $'
8
# '$Revision: 8265 $'
9
#
10
# This program is free software; you can redistribute it and/or modify
11
# it under the terms of the GNU General Public License as published by
12
# the Free Software Foundation; either version 2 of the License, or
13
# (at your option) any later version.
14
#
15
# This program is distributed in the hope that it will be useful,
16
# but WITHOUT ANY WARRANTY; without even the implied warranty of
17
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
# GNU General Public License for more details.
19
#
20
# You should have received a copy of the GNU General Public License
21
# along with this program; if not, write to the Free Software
22
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
#
24
"""
25
 Transfers list of documents from one metacat server to another
26
"""
27

    
28
import metacat
29
import sys
30

    
31
try:
32
    docidlist = sys.argv[1]
33
except:
34
    print
35
    print " usage: python transferEml.py docidlist.txt "
36
    print "        where docidlist.txt is a line-delimited list of docids "
37
    print
38
    sys.exit(1)
39

    
40
print "Logging into destination server"
41
dest = metacat.MetacatClient('yourserver:8180','/metacat/metacat')
42
dest.login('user','password','NCEAS')
43

    
44
print "Logging into source server"
45
src = metacat.MetacatClient('knb.ecoinformatics.org', '/knb/metacat')
46
src.login('user','password','NCEAS')
47

    
48
print "Open docid list and loop"
49
for docid in open(docidlist,'r').readlines():
50
    docid = docid.strip().replace('\n','')
51
    if docid != '' and docid is not None:
52
       print " reading docid " + docid
53
       eml = src.read(docid) 
54
       if eml:
55
           print " inserting docid " + docid
56
           response = dest.insert(docid + ".1" ,eml)
57
           if not response:
58
              print "   insert failed"
59
       else:
60
           print "   docid " + docid + " not found"
61

    
62
print "Logging out"
63
dest.logout()
64
src.logout()
65
       
66
        
67

    
68

    
(4-4/4)