Hi,
I have a python script enclosed here for uploading batch item & bitstream
in dspace. But though it I can only upload a single pdf whereas I required
to upload multiple pdf in the single item. Can anyone guide how to do the
same?
--
All messages to this mailing list should adhere to the Code of Conduct:
https://www.lyrasis.org/about/Pages/Code-of-Conduct.aspx
---
You received this message because you are subscribed to the Google Groups
"DSpace Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/dspace-community/bee14f00-c318-4d8e-9217-720ff4e6c540n%40googlegroups.com.
import argparse
import csv
import os
import re
import shutil
def pair(x,y):
return (x,y)
def listlength(x):
def count(x,y): return x+1
return reduce(count,x,0)
#def createDublinXML(folder,id,pdfDir,metaStr,templateStr):
def createDublinXML(folder,id,metaStr,templateStr):
print folder,id,metaStr,templateStr
cList = []
os.mkdir(folder+"/"+id)
ofile1 = open(folder+"/"+id+"/dublin_core.xml","w")
ofile2 = open(folder+"/"+id+"/contents","w")
ofile1Str = "<?xml version=\"1.0\"
encoding=\"UTF-8\"?>\n<dublin_core>\n"
ofile2Str = ''
#ofile1.write()
#ofile1.write(("<dublin_core>\n")
complist = map(pair, templateStr, metaStr)
for descString,metaData in complist:
p = re.compile(r'\W+')
#type(descString)
#descString
descs = p.split(str(descString))
#descs
type(descs)
if metaData == "" :
continue;
if descString != None :
if listlength(descs) == 3 :
ofile1Str += '<dcvalue element=\"' + descs[1] +
'\" qualifier=\"' + descs[2] + '\">' + metaData + "</dcvalue>\n"
else:
ofile1Str += '<dcvalue element=\"' + descs[1] +
'\" qualifier=\"\">' + metaData + "</dcvalue>\n"
else:
(head,tail) = os.path.split(metaData)
ofile2Str += tail + "\tbundle:ORIGINAL"
#copy the pdf file into newly created directory
shutil.copy(metaData,folder+"/"+id)
ofile1Str += "</dublin_core>\n"
ofile1.write(ofile1Str)
ofile2.write(ofile2Str)
ofile1.close()
ofile2.close()
parser = argparse.ArgumentParser()
parser.add_argument("-i","--input",help="input metadata file(csv
format)",action="store",type=argparse.FileType('r'),required=True)
parser.add_argument("-c","--collection",help="collection to add these
items",action="store",required=True)
parser.add_argument("-p","--collectionid",help="collection to add these
items",action="store",required=True)
parser.add_argument("-u","--uploaddir",help="directory from where the items
will be uploaded, need to empty else contents
deleted",action="store",required=True)
parser.add_argument("-t","--templatecsv",help="csv for metadata format in input
csv file",action="store",required=True,type=argparse.FileType('r'))
#parser.add_argument("-s","--pdfdir",help="directory containing PDF Files to be
uploaded",action="store",required=True)
parser.add_argument("-d","--dspacebindir",help="dspace install directory, on
windows C:\\Dspace\\bin",action="store",required=True)
parser.add_argument("-e","--eperson",help="dspace eperson eg.
[email protected]",action="store",required=True)
parser.add_argument("-o","--outputfile",help="output log
file",action="store",default="map.txt")
args = parser.parse_args()
if args.input :
print args.input
if args.collection:
print args.collection
if args.uploaddir:
print args.uploaddir
if args.templatecsv :
print args.templatecsv
#if args.pdfdir :
#print args.pdfdir
if args.dspacebindir :
print args.dspacebindir
if args.eperson :
print args.eperson
if args.outputfile :
print args.outputfile
if args.input:
reader = csv.reader((line.replace('\0','') for line in
args.input),delimiter=',', quotechar='"')
if args.uploaddir:
os.mkdir(args.uploaddir)
if args.collection:
os.mkdir(args.uploaddir+"/"+args.collection)
if args.collectionid:
os.mkdir(args.uploaddir+"/"+args.collection+"/"+args.collectionid )
collbase = args.uploaddir+"/"+args.collection+"/"+args.collectionid
print "Created directory: ", collbase
rowNum = 1
templateStr = ''
if args.templatecsv:
reader1 = csv.reader((line.replace('\0','') for line in
args.templatecsv),delimiter=',', quotechar='"')
for tempStr in reader1:
templateStr = tempStr
args.templatecsv.close()
for row in reader:
#createDublinXML(collbase,str(rowNum),args.pdfdir,row,templateStr)
createDublinXML(collbase,str(rowNum),row,templateStr)
for col in row:
print '%s' % col
rowNum += 1
args.input.close()
os.chdir(args.dspacebindir)
command = args.dspacebindir + "/" + "dspace import ItemImport -a -e " +
args.eperson + " -c " + args.collection + "/"\
+ args.collectionid + " -s " + args.uploaddir + "//" +
args.collection + "//" + args.collectionid + " -m " + args.uploaddir + "/" +
args.outputfile
os.system(command)
#changedir to DspaceBinDir
os.chdir(args.dspacebindir)
command1 = args.dspacebindir + "/" + "dspace index-init"
os.system(command1)
command2 = args.dspacebindir + "/" + "dspace index-update"
os.system(command2)
command3 = args.dspacebindir + "/" + "dspace update-discovery-index -o"
os.system(command3)