comparison sworduploader.py @ 10:af2a645f63a2

Support for BagIt packages
author Marco Fabiani <marco.fabiani@eecs.qmul.ac.uk>
date Wed, 11 Apr 2012 17:09:14 +0100
parents 394b4d094767
children 4206512d8ae2
comparison
equal deleted inserted replaced
9:394b4d094767 10:af2a645f63a2
124 myzip = zipfile.ZipFile(data) 124 myzip = zipfile.ZipFile(data)
125 if "mets.xml" in myzip.namelist(): #This is a METS package 125 if "mets.xml" in myzip.namelist(): #This is a METS package
126 packaging = "http://purl.org/net/sword/package/METSDSpaceSIP" 126 packaging = "http://purl.org/net/sword/package/METSDSpaceSIP"
127 type = "METS" 127 type = "METS"
128 in_progress = False 128 in_progress = False
129 else: #THis is a simple zip file 129 elif "bagit.txt" in "".join(myzip.namelist()): #This is a BagIt package
130 packaging = "http://purl.org/net/sword/package/BagIt"
131 type = "BAGIT"
132 else:#THis is a simple zip file
130 packaging = "http://purl.org/net/sword/package/SimpleZip" 133 packaging = "http://purl.org/net/sword/package/SimpleZip"
131 type = "SimpleZip" 134 type = "SimpleZip"
132 myzip.close() 135 myzip.close()
133 elif os.path.isfile(data): # This is a single file 136 elif os.path.isfile(data): # This is a single file
134 fileslist.append(data) 137 fileslist.append(data)
175 except HTTPResponseError: 178 except HTTPResponseError:
176 print "Bad request" 179 print "Bad request"
177 else: 180 else:
178 # Send the zip file and let the ingester do its job 181 # Send the zip file and let the ingester do its job
179 payload = open(fileslist[0], "rb") 182 payload = open(fileslist[0], "rb")
180 if type == "SimpleZip": 183 if (type == "SimpleZip") or (type=="BAGIT"):
181 in_progress = True 184 in_progress = True
182 # FIXME: we don't want to write silly things in dc.description! 185 # FIXME: we don't want to write silly things in dc.description!
183 else: 186 else:
184 in_progress = False 187 in_progress = False
185 try: 188 try: