Ejemplo n.º 1
0
except (File.DoesNotExist, File.MultipleObjectsReturned) as e:
    # Original file was not found, or there is more than one original file with
    # the same filename (differing extensions)
    # Look for a CSV that will specify the mapping
    csv_path = os.path.join(opts.sipDirectory, "objects",
                            "manualNormalization", "normalization.csv")
    if os.path.isfile(csv_path):
        try:
            access_file = opts.filePath[opts.filePath.
                                        index('manualNormalization/access/'):]
        except ValueError:
            print("{0} not in manualNormalization directory".format(
                opts.filePath),
                  file=sys.stderr)
            exit(4)
        original = fileOperations.findFileInNormalizatonCSV(
            csv_path, "access", access_file, unitIdentifier)
        if original is None:
            if isinstance(e, File.DoesNotExist):
                print("No matching file for: {0}".format(
                    opts.filePath.replace(opts.sipDirectory,
                                          "%SIPDirectory%")),
                      file=sys.stderr)
                exit(3)
            else:
                print("Could not find {access_file} in {filename}".format(
                    access_file=access_file, filename=csv_path),
                      file=sys.stderr)
                exit(2)
        # If we found the original file, retrieve it from the DB
        kwargs = {
            "removedtime__isnull": True,
                                     sip_id=SIPUUID)
except (File.DoesNotExist, File.MultipleObjectsReturned) as e:
    # Original file was not found, or there is more than one original file with
    # the same filename (differing extensions)
    # Look for a CSV that will specify the mapping
    csv_path = os.path.join(SIPDirectory, "objects", "manualNormalization",
                            "normalization.csv")
    if os.path.isfile(csv_path):
        try:
            preservation_file = filePath[
                filePath.index('manualNormalization/preservation/'):]
        except ValueError:
            print("{0} not in manualNormalization directory".format(filePath),
                  file=sys.stderr)
            exit(4)
        original = fileOperations.findFileInNormalizatonCSV(
            csv_path, "preservation", preservation_file, SIPUUID)
        if original is None:
            if isinstance(e, File.DoesNotExist):
                print("No matching file for: {0}".format(
                    filePath.replace(SIPDirectory, "%SIPDirectory%")),
                      file=sys.stderr)
                exit(3)
            else:
                print(
                    "Could not find {preservation_file} in {filename}".format(
                        preservation_file=preservation_file,
                        filename=csv_path),
                    file=sys.stderr)
                exit(2)
        # If we found the original file, retrieve it from the DB
        original_file = File.objects.get(removedtime__isnull=True,
    #If not found try without extension
    sql = "SELECT Files.fileUUID, Files.currentLocation FROM Files WHERE removedTime = 0 AND fileGrpUse='original' AND Files.currentLocation = '" + filePathLike2 + "' AND " + unitIdentifierType + " = '" + unitIdentifier + "';"
rows = databaseInterface.queryAllSQL(sql)
if len(rows) != 1:
    # Original file was not found, or there is more than one original file with
    # the same filename (differing extensions)
    # Look for a CSV that will specify the mapping
    csv_path = os.path.join(opts.sipDirectory, "objects", "manualNormalization", 
        "normalization.csv")
    if os.path.isfile(csv_path):
        try:
            access_file = opts.filePath[opts.filePath.index('manualNormalization/access/'):]
        except ValueError:
            print >>sys.stderr, "{0} not in manualNormalization directory".format(opts.filePath)
            exit(4)
        original = fileOperations.findFileInNormalizatonCSV(csv_path,
            "access", access_file)
        if original == None:
            if len(rows) < 1:
                print >>sys.stderr, "No matching file for: {0}".format(
                    opts.filePath.replace(opts.sipDirectory, "%SIPDirectory%"))
                exit(3)
            else:
                print >>sys.stderr, "Could not find {access_file} in {filename}".format(
                        access_file=access_file, filename=csv_path)
                exit(2)
        # If we found the original file, retrieve it from the DB
        sql = """SELECT Files.fileUUID, Files.currentLocation 
                 FROM Files 
                 WHERE removedTime = 0 AND 
                    fileGrpUse='original' AND 
                    Files.currentLocation LIKE '%{filename}' AND 
if not len(rows):
    sql = "SELECT Files.fileUUID, Files.currentLocation FROM Files WHERE removedTime = 0 AND fileGrpUse='original' AND Files.currentLocation LIKE '" + filePathLike2 + "' AND " + unitIdentifierType + " = '" + unitIdentifier + "';"
    rows = databaseInterface.queryAllSQL(sql)
if len(rows) != 1:
    # Original file was not found, or there is more than one original file with
    # the same filename (differing extensions)
    # Look for a CSV that will specify the mapping
    csv_path = os.path.join(SIPDirectory, "objects", "manualNormalization",
        "normalization.csv")
    if os.path.isfile(csv_path):
        try:
            preservation_file = filePath[filePath.index('manualNormalization/preservation/'):]
        except ValueError:
            print >>sys.stderr, "{0} not in manualNormalization directory".format(filePath)
            exit(4)
        original = fileOperations.findFileInNormalizatonCSV(csv_path,
            "preservation", preservation_file)
        if original is None:
            if len(rows) < 1:
                print >>sys.stderr, "No matching file for: {0}".format(
                    filePath.replace(SIPDirectory, "%SIPDirectory%"))
                exit(3)
            else:
                print >>sys.stderr, "Could not find {preservation_file} in {filename}".format(
                        preservation_file=preservation_file, filename=csv_path)
                exit(2)
        # If we found the original file, retrieve it from the DB
        sql = """SELECT Files.fileUUID, Files.currentLocation 
                 FROM Files 
                 WHERE removedTime = 0 AND 
                    fileGrpUse='original' AND 
                    Files.currentLocation LIKE '%{filename}' AND