# ingest my custom datastreams for this object

    # create a JPG datastream
    #tifFile = objectData['datastreams']['TIFF']
    #baseName = os.path.splitext(os.path.basename(tifFile))[0]
    #jpgFile = os.path.join(config.tempDir, "%s.jpg" % baseName)
    #converter.tif_to_jpg(tifFile, jpgFile, ['-compress', 'JPEG', '-quality', '90%']) # this will generate jpgFile
    #fedoraLib.update_datastream(obj, u"JPG", jpgFile, label=unicode("%s.jpg" % baseName), mimeType=misc.getMimeType("jpg"))
    #os.remove(jpgFile) # finished with that

    # ingest my custom datastreams for this object
    # create a JP2 datastream
    tifFile = objectData['datastreams']['TIFF']
    baseName = os.path.splitext(os.path.basename(tifFile))[0]
    jp2File = os.path.join(config.tempDir, "%s.jp2" % baseName)
    converter.tif_to_jp2(tifFile, jp2File, 'default', 'default') # this will generate jp2File
    fedoraLib.update_datastream(obj, u"JP2", jp2File, label=os.path.basename(jp2File), mimeType=misc.getMimeType("jp2"))
    os.remove(jp2File) # finished with that

    # extract mix metadata
    #cmd= jhove -h xml $INFILE | xsltproc jhove2mix.xslt - > `basename ${$INFILE%.*}.mix`
    mixFile = os.path.join(config.tempDir, "%s.mix.xml" % baseName)
    """ extract this into tif_to_mix() """
    outfile = open(mixFile, "w")
    jhoveCmd1 = ["jhove", "-h", "xml", tifFile]
    jhoveCmd2 = ["xsltproc", "data/jhove2mix.xslt", "-"] # complete cmd for xsltproc
    #jhoveCmd2 = ["xalan", "-xsl", "data/jhove2mix.xslt"] # complete cmd for xalan
    p1 = subprocess.Popen(jhoveCmd1, stdout=subprocess.PIPE)
    p2 = subprocess.Popen(jhoveCmd2, stdin=p1.stdout, stdout=outfile)
    r = p2.communicate()
    if os.path.getsize(mixFile) == 0:
        if dsid in [ "MODS", "KML" ]:
            controlGroup = "X"
        else:
            controlGroup = "M"
        fedoraLib.update_datastream(obj, dsid, file, label=unicode(os.path.basename(file)), mimeType=misc.getMimeType(os.path.splitext(file)[1]), controlGroup=controlGroup)

    # === STATIC DATASTREAM SECTION ===
    # these DS are defined here - sources are created as required

    # ingest my custom datastreams for this object
    # create a JP2 datastream
    tifFile = objectData['datastreams']['TIFF']
    baseName = os.path.splitext(os.path.basename(tifFile))[0]

    jp2File = os.path.join(config.tempDir, "%s.jp2" % baseName)
    converter.tif_to_jp2(tifFile, jp2File, 'default', 'default') # this will generate jp2File
    fedoraLib.update_datastream(obj, u"JP2", jp2File, label=os.path.basename(jp2File), mimeType=misc.getMimeType("jp2"))
    os.remove(jp2File) # finished with that

    # i'm generating my own thumbnails
    tnFile = os.path.join(config.tempDir, "tmp.jpg")
    converter.tif_to_jpg(tifFile, tnFile, imageMagicOpts='TN')
    #add a TN datastream to the map object
    fedoraLib.update_datastream(obj, u"TN", tnFile, label=unicode(config.myCollectionName+"_TN.jpg"), mimeType=misc.getMimeType("jpg"))
    os.remove(tnFile) # delete it so we can recreate it again for the next thumbnail
    # now tnFile is closed and deleted

    if config.jhoveCmd != None: # config.jhoveCmd will be empty if jhove extraction cannot be completed
        # extract mix metadata
        #cmd= jhove -h xml $INFILE | xsltproc jhove2mix.xslt - > `basename ${$INFILE%.*}.mix`
        mixFile = os.path.join(config.tempDir, "%s.mix.xml" % baseName)
            try:
                #obj = addObjectToFedora(fedora, unicode(pageset[1]), pagePid, objPid, "archiveorg:pageCModel",
                #        extraNamespaces=extraNamespaces, extraRelationships=extraRelationships)
                obj = addObjectToFedora(fedora, u"", pagePid, objPid, "islandora:pageCModel",
                        extraNamespaces=extraNamespaces, extraRelationships=extraRelationships)
            except FedoraConnectionException, fcx:
                print("Connection error while trying to add fedora object (%s) - the connection to fedora may be broken", page)
                continue

            # ingest the tif
            tifFile = os.path.join(bookFolder, page)
            fedoraLib.update_datastream(obj, u"TIFF", tifFile, label=unicode("%s.tif" % basePage), mimeType=misc.getMimeType("tiff"))

            # create a JP2 datastream
            jp2File = os.path.join(config.tempDir, "%s.jp2" % basePage)
            converter.tif_to_jp2(tifFile, jp2File, 'default', 'default')
            fedoraLib.update_datastream(obj, u"JP2", jp2File, label=unicode("%s.jp2" % basePage), mimeType=misc.getMimeType("jp2"))
            os.remove(jp2File) # finished with that

            # create DC, MODS, VRA datastreams
            for dsid in ['DC', 'MODS', 'VRA']:
                dsfile = os.path.join(bookFolder, "%s.%s.xml" % (os.path.splitext(page)[0], dsid.lower()))
                dspage = os.path.basename(dsfile)
                fedoraLib.update_datastream(obj, unicode(dsid), dsfile, label=unicode(dspage), mimeType=misc.getMimeType("xml"), controlGroup='X')

            pdfFile = os.path.join(config.tempDir, "%s.pdf" % basePage)
            converter.tif_to_pdf(tifFile, pdfFile, 'default')
            #fedoraLib.update_datastream(obj, u'PDF', pdfFile, label=unicode("%s.pdf" % basePage), mimeType=misc.getMimeType("pdf"))
            # for the first page, move it to the full when finished with it
            if idx == 0:
                os.rename(pdfFile, fullPDF)