Exemplo n.º 1
0
def prep_directory(client, mrepo):
    """
    Create an empty FS directory by performing an import and
    then deleting the created fileset.
    """

    from omero.cmd import Delete2, DoAll
    from omero.grid import ImportSettings

    from omero.model import ChecksumAlgorithmI
    from omero.model import FilesetI
    from omero.model import FilesetEntryI
    from omero.model import UploadJobI

    fs = FilesetI()
    fs.linkJob(UploadJobI())
    entry = FilesetEntryI()
    entry.clientPath = rstring("README.txt")
    fs.addFilesetEntry(entry)
    settings = ImportSettings()
    settings.checksumAlgorithm = ChecksumAlgorithmI()
    settings.checksumAlgorithm.value = rstring("SHA1-160")
    proc = mrepo.importFileset(fs, settings)
    try:

        tmp = create_path()
        prx = proc.getUploader(0)
        try:
            tmp.write_text("THIS IS A PLACEHOLDER")
            hash = client.sha1(tmp)
            with open(tmp, "r") as source:
                client.write_stream(source, prx)
        finally:
            prx.close()
        tmp.remove()

        handle = proc.verifyUpload([hash])
        try:
            req = handle.getRequest()
            fs = req.activity.parent
        finally:
            handle.close()

        dir = unwrap(mrepo.treeList(fs.templatePrefix.val))
        oid = dir.items()[0][1].get("id")
        ofile = client.sf.getQueryService().get("OriginalFile", oid)

        delete1 = Delete2(targetObjects={"Fileset": [fs.id.val]})
        delete2 = Delete2(targetObjects={"OriginalFile": [ofile.id.val]})
        doall = DoAll()
        doall.requests = [delete1, delete2]
        cb = client.submit(doall)
        cb.close(True)

    finally:
        proc.close()

    return fs.templatePrefix.val
Exemplo n.º 2
0
 def startUpload(self, files):
     mrepo = self.client.getManagedRepository()
     fs = FilesetI()
     fs.linkJob(UploadJobI())
     for file in files:
         entry = FilesetEntryI()
         entry.clientPath = rstring("%s/%s" % (
             file.path.val, file.name.val
         ))
         fs.addFilesetEntry(entry)
     settings = ImportSettings()
     settings.checksumAlgorithm = ChecksumAlgorithmI()
     settings.checksumAlgorithm.value = rstring("SHA1-160")
     return mrepo.importFileset(fs, settings)
Exemplo n.º 3
0
def prep_directory(client, mrepo):
    """
    Create an empty FS directory by performing an import and
    then deleting the created fileset.
    """

    from omero.cmd import Delete2, DoAll
    from omero.grid import ImportSettings

    from omero.model import ChecksumAlgorithmI
    from omero.model import FilesetI
    from omero.model import FilesetEntryI
    from omero.model import UploadJobI

    fs = FilesetI()
    fs.linkJob(UploadJobI())
    entry = FilesetEntryI()
    entry.clientPath = rstring("README.txt")
    fs.addFilesetEntry(entry)
    settings = ImportSettings()
    settings.checksumAlgorithm = ChecksumAlgorithmI()
    settings.checksumAlgorithm.value = rstring("SHA1-160")
    proc = mrepo.importFileset(fs, settings)
    try:

        tmp = create_path()
        prx = proc.getUploader(0)
        try:
            tmp.write_text("THIS IS A PLACEHOLDER")
            hash = client.sha1(tmp)
            with open(tmp, "r") as source:
                client.write_stream(source, prx)
        finally:
            prx.close()
        tmp.remove()

        handle = proc.verifyUpload([hash])
        try:
            req = handle.getRequest()
            fs = req.activity.parent
        finally:
            handle.close()

        dir = unwrap(mrepo.treeList(fs.templatePrefix.val))
        oid = dir.items()[0][1].get("id")
        ofile = client.sf.getQueryService().get("OriginalFile", oid)

        delete1 = Delete2(targetObjects={'Fileset': [fs.id.val]})
        delete2 = Delete2(targetObjects={'OriginalFile': [ofile.id.val]})
        doall = DoAll()
        doall.requests = [delete1, delete2]
        cb = client.submit(doall)
        cb.close(True)

    finally:
        proc.close()

    return fs.templatePrefix.val
Exemplo n.º 4
0
 def startUpload(self, files):
     mrepo = self.client.getManagedRepository()
     fs = FilesetI()
     fs.linkJob(UploadJobI())
     for file in files:
         entry = FilesetEntryI()
         entry.clientPath = rstring("%s/%s" %
                                    (file.path.val, file.name.val))
         fs.addFilesetEntry(entry)
     settings = ImportSettings()
     settings.checksumAlgorithm = ChecksumAlgorithmI()
     settings.checksumAlgorithm.value = rstring("SHA1-160")
     return mrepo.importFileset(fs, settings)
Exemplo n.º 5
0
def create_fileset():
    """Creates and returns a Fileset with associated Images."""
    fileset = FilesetI()
    fileset.templatePrefix = rstring('')
    for image_index in range(2):
        image = create_image(image_index)
        for fileset_index in range(2):
            fileset_entry = FilesetEntryI()
            fileset_entry.clientPath = rstring('/client/path/filename_%d.ext' %
                                               fileset_index)
            original_file = OriginalFileI()
            original_file.name = rstring('filename_%d.ext' % fileset_index)
            original_file.path = rstring('/server/path/')
            original_file.size = rlong(50L)
            fileset_entry.originalFile = original_file
            fileset.addFilesetEntry(fileset_entry)
        fileset.addImage(image)
    return fileset
Exemplo n.º 6
0
def create_fileset():
    """Creates and returns a Fileset with associated Images."""
    fileset = FilesetI()
    fileset.templatePrefix = rstring("")
    for image_index in range(2):
        image = create_image(image_index)
        for fileset_index in range(2):
            fileset_entry = FilesetEntryI()
            fileset_entry.clientPath = rstring("/client/path/filename_%d.ext" % fileset_index)
            original_file = OriginalFileI()
            original_file.name = rstring("filename_%d.ext" % fileset_index)
            original_file.path = rstring("/server/path/")
            original_file.size = rlong(50L)
            fileset_entry.originalFile = original_file
            fileset.addFilesetEntry(fileset_entry)
        fileset.addImage(image)
    return fileset