Created
April 11, 2013 00:36
-
-
Save mcantelon/5359715 to your computer and use it in GitHub Desktop.
Create SIP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# get transfer info | |
transfer = models.Transfer.objects.get(uuid=transfer_uuid) | |
transfer_path = transfer.currentlocation.replace( | |
'%sharedPath%', | |
helpers.get_server_config_value('sharedDirectory') | |
) | |
# extra transfer name | |
transfer_directory_name = os.path.basename(transfer_path[:-1]) | |
transfer_name = transfer_directory_name[:-37] | |
sip_uuid = uuid.uuid4().__str__() | |
sip = models.SIP.objects.create( | |
uuid=sip_uuid, | |
currentpath='%sharedPath%watchedDirectories/system/autoProcessSIP/' + transfer_name + '/' | |
) | |
sip.save() | |
createStructuredDirectory(transfer_path, createManualNormalizedDirectories=False) | |
for directory in createManualNormalizedDirectoriesList: | |
path = os.path.join(transfer_path, directory) | |
if not os.path.isdir(path): | |
os.makedirs(path) | |
#get the database list of files in the objects directory | |
#for each file, confirm it's in the SIP objects directory, and update the current location/ owning SIP' | |
sql = """SELECT fileUUID, currentLocation FROM Files WHERE removedTime = 0 AND currentLocation LIKE '\%transferDirectory\%objects%' AND transferUUID = '""" + transfer_uuid + "'" | |
for row in databaseInterface.queryAllSQL(sql): | |
fileUUID = row[0] | |
currentPath = databaseFunctions.deUnicode(row[1]) | |
currentSIPFilePath = currentPath.replace("%transferDirectory%", transfer_path) | |
if os.path.isfile(currentSIPFilePath): | |
sql = """UPDATE Files SET currentLocation='%s', sipUUID='%s' WHERE fileUUID='%s'""" % (MySQLdb.escape_string(currentPath.replace("%transferDirectory%", "%SIPDirectory%")), sip_uuid, fileUUID) | |
databaseInterface.runSQL(sql) | |
else: | |
print >>sys.stderr, "file not found: ", currentSIPFilePath | |
shutil.move( | |
transfer_path, | |
'/var/archivematica/sharedDirectory/watchedDirectories/system/autoProcessSIP/' + transfer_name | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment