示例#1
0
    def test_files(self):
        #    outfilename = "test_files"
        try:
            clip = FPClip(self.pool)
            clip.open(clipid, FPLibrary.FP_OPEN_ASTREE)

            numfiles = clip.getNumBlobs()
            assert numfiles, "Missing blobs"
            for i in range(numfiles + 1):
                blob_id = clip.fetchNext()
                if not blob_id:
                    break

                blob_tag = FPTag(blob_id)
                print(("tag: %r" % blob_tag))
                if blob_tag.getBlobSize() < 1:
                    print(("Empty blob %s" % i))
                    blob_tag.close()
                    continue

                outfilename = blob_tag.getTagName()
                print(("tag name : %s" % outfilename))
                fh = FPFileOutputStream(
                    "outfile.{name}.{i}".format(name=outfilename, i=i))
                print("reading file from centera...")
                blob_tag.blobRead(fh.stream, 0)
                print("ok")
                fh.close()
                blob_tag.close()

        finally:
            print("closing clip")
            clip.close()

        assert outfilename, "Missing tag: %r" % outfilename
示例#2
0
    def getTags(self):
        """

        :return: an iterable of (tag_name, tag_size)
        """
        numfiles = self.getNumBlobs()
        if not numfiles:
            return

        for blob_id in self.getBlobs():
            blob_tag = FPTag(blob_id)
            tag_name = blob_tag.getTagName()
            blob_size = blob_tag.getBlobSize()
            blob_tag.close()
            yield tag_name, blob_size
示例#3
0
    def download(self, clip_id, tag_name, outfile):
        """

        :param clip_id:
        :param tag_name:
        :param outfile:
        :return: the output file if present. None if not found.
        """
        outfile = normpath(abspath(outfile))
        with closing(FPClip(self.pool, close_retries=3)) as clip:
            self._open_or_not_found(clip, clip_id)

            for blob_id in clip.getBlobs():
                with closing(FPTag(blob_id)) as blob_tag:
                    blob_tag_name = blob_tag.getTagName()
                    if blob_tag_name != tag_name:
                        self.log.debug("Skipping tag: %s when looking for: %s",
                                       blob_tag_name, blob_tag)
                        continue

                    if blob_tag.getBlobSize() < 1:
                        self.log.debug("Empty blob %s" % blob_tag_name)
                        raise ValueError()

                    with closing(FPFileOutputStream(outfile)) as fh:
                        self.log.info("Writing blob %s to %s", blob_tag_name,
                                      outfile)
                        blob_tag.blobRead(fh.stream, 0)

                    return outfile
示例#4
0
 def write_clip(self, clip, filename, retention_sec, top_tag):
     clip.setRetentionPeriod(long(retention_sec))
     top_handle = clip.getTopTag()
     with closing(FPTag(top_handle, top_tag)) as blob_tag:
         with closing(FPFileInputStream(filename, 16 * 1024)) as fh:
             blob_tag.blobWrite(fh.stream, 0)
     clipid = clip.write()
     return clipid
示例#5
0
    def readFiles(self, tag_name=None, out_file=None):
        for blob_id in self.getBlobs():

            with closing(FPTag(blob_id)) as blob_tag:
                if not tag_name or blob_tag.getTagName() == tag_name:
                    fh = FPFileOutputStream(outfile + tag_name + ".%s" % i)
                    log.debug("reading file from centera...")
                    blob_tag.blobRead(fh.stream, 0)
示例#6
0
    def test_store_many(self):
        retention_sec = 100
        files = "1.xml 2.xml 3.xml 4.xml".split()
        clip_name = "myclip_" + "manyfiles"

        with closing(FPClip(self.pool, clip_name, close_retries=3)) as clip:
            clip.setRetentionPeriod(long(retention_sec))
            top_handle = clip.getTopTag()
            for filename in files:
                with closing(FPTag(top_handle,
                                   "mytag_" + filename)) as blob_tag:
                    with closing(FPFileInputStream(filename, 16 * 1024)) as fh:
                        blob_tag.blobWrite(fh.stream, 0)
            clipid = clip.write()
示例#7
0
    def getTags(self):
        """

        :return: an iterable of (tag_name, tag_size)
        """
        numfiles = self.getNumBlobs()
        if not numfiles:
            return

        for blob_id in self.getBlobs():
            blob_tag = FPTag(blob_id)
            tag_name = blob_tag.getTagName()
            blob_size = blob_tag.getBlobSize()
            blob_tag.close()
            yield tag_name, blob_size
示例#8
0
    def put(self, clip_name, files, retention_sec):
        """
        Writes a clip and attached files to worm.

        :param clip_name:
        :param files:
        :param retention_sec:
        :return:
        """
        for f in files:
            self.validate_tag(f)

        with closing(FPClip(self.pool, clip_name, close_retries=3)) as clip:
            clip.setRetentionPeriod(long(retention_sec))
            top_handle = clip.getTopTag()
            for filename in files:
                tag_name = self.clean_tag(filename)
                with closing(FPTag(top_handle, tag_name)) as blob_tag:
                    with closing(FPFileInputStream(filename, 16 * 1024)) as fh:
                        blob_tag.blobWrite(fh.stream, 0)
            clip_id = clip.write()

        return clip_id
示例#9
0
  pool.setGlobalOption( FPLibrary.FP_OPTION_EMBEDDED_DATA_THRESHOLD,
    100 * 1024 )

  pool.getPoolInfo()

  pool.registerApplication( "python wrapper store example", "1.0" )

  clip = FPClip( pool, "python store example" )

  retention = raw_input( "Retention (in seconds): " )

  clip.setRetentionPeriod( long(retention) )

  top_handle  = clip.getTopTag()

  blob_tag = FPTag( top_handle, "file" )

  filename = raw_input( "Filename: " )

  file = FPFileInputStream( filename, 16*1024 )
 
  blob_tag.blobWrite( file.stream, 0 )

  file.close()
  blob_tag.close()

  clipid = clip.write()
  print clipid

  clip.close()
示例#10
0
    pool.setGlobalOption(FPLibrary.FP_OPTION_EMBEDDED_DATA_THRESHOLD,
                         100 * 1024)

    pool.getPoolInfo()

    pool.registerApplication("python wrapper store example", "1.0")

    clip = FPClip(pool, "python store example")

    retention = raw_input("Retention (in seconds): ")

    clip.setRetentionPeriod(long(retention))

    top_handle = clip.getTopTag()

    blob_tag = FPTag(top_handle, "file")

    filename = raw_input("Filename: ")

    file = FPFileInputStream(filename, 16 * 1024)

    blob_tag.blobWrite(file.stream, 0)

    file.close()
    blob_tag.close()

    clipid = clip.write()
    print clipid

    clip.close()
示例#11
0
    clip = FPClip(pool)
    # clipid = raw_input( "Clip id: " )
    clip.open(clipid, FPLibrary.FP_OPEN_ASTREE)

    for a in "name retention.period numfiles".split():
        clip.getDescriptionAttribute(a)

    top = clip.getTopTag()
    print("tag: %r" % top)

    for i in range(clip.getNumBlobs() + 1):
        blob_id = clip.fetchNext()
        if not blob_id:
            break

        blob_tag = FPTag(blob_id)
        if blob_tag.getBlobSize() < 1:
            blob_tag.close()
            continue

        print("tag: %r" % blob_tag)

        file = FPFileOutputStream(outfilename + ".%s" % i)
        print("reading file from centera...")
        blob_tag.blobRead(file.stream, 0)
        print("ok")

        file.close()
        blob_tag.close()

    clip.close()
示例#12
0
    clip = FPClip(pool)
    # clipid = raw_input( "Clip id: " )
    clip.open(clipid, FPLibrary.FP_OPEN_ASTREE)

    for a in "name retention.period numfiles".split():
        clip.getDescriptionAttribute(a)

    top = clip.getTopTag()
    print("tag: %r" % top)

    for i in range(clip.getNumBlobs() + 1):
        blob_id = clip.fetchNext()
        if not blob_id:
            break

        blob_tag = FPTag(blob_id)
        if blob_tag.getBlobSize() < 1:
            blob_tag.close()
            continue

        print("tag: %r" % blob_tag)

        file = FPFileOutputStream(outfilename + ".%s" % i)
        print("reading file from centera...")
        blob_tag.blobRead(file.stream, 0)
        print("ok")

        file.close()
        blob_tag.close()

    clip.close()
示例#13
0
  pool.setGlobalOption( FPLibrary.FP_OPTION_EMBEDDED_DATA_THRESHOLD,
    100 * 1024 )

  pool.getPoolInfo()

  pool.registerApplication( "python wrapper read example", "1.0" )

  clip = FPClip( pool )

  clipid = raw_input( "Clip id: " )

  clip.open( clipid, FPLibrary.FP_OPEN_ASTREE )

  top = clip.getTopTag()

  blob_tag = FPTag( clip.fetchNext() )

  filename = raw_input( "Filename: " )
  
  file = FPFileOutputStream( filename )

  blob_tag.blobRead( file.stream, 0 )

  file.close()
  blob_tag.close()
  clip.close()
  pool.close()

  
except FPClientException, c:
  print c