Project

General

Profile

1
#!/usr/bin/python
2
#
3
#  '$RCSfile$'
4
#  Copyright: 2000 Regents of the University of California
5
#
6
#   '$Author: $'
7
#     '$Date: $'
8
# '$Revision: $'
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
 Inserts a list of documents into a Metacat server
26
"""
27

    
28
import metacat
29
import sys
30

    
31
try:
32
    docidlist = sys.argv[1]
33
    docdir = sys.argv[2]
34
except:
35
    print
36
    print " usage: python insertDocs.py docidlist.txt docdir"
37
    print "        where docidlist.txt is a line-delimited list of docids "
38
    print "        and docdir is the path to the directory of documents"
39
    print
40
    sys.exit(1)
41

    
42
print "Logging into destination server"
43
dest = metacat.MetacatClient('localhost:8080','/metacat/metacat')
44
dest.login('username','password','NCEAS')
45

    
46
print "Open docid list and loop"
47
for docid in open(docidlist,'r').readlines():
48
    docid = docid.strip().replace('\n','')
49
    if docid != '' and docid is not None:
50
       print " reading docid " + docid
51

    
52
       with open(docdir + "/" + docid) as f:
53
           eml = f.read()
54
           f.close()
55

    
56
       if eml:
57
           print " inserting docid " + docid
58
           response = dest.insert(docid, eml)
59
           if not response:
60
              print "   insert failed"
61
       else:
62
           print "   docid " + docid + " not found"
63

    
64
print "Logging out"
65
dest.logout()
(2-2/4)