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
def assert_clip_name(self, clipid, filename): with closing(FPClip(self.pool, close_retries=3)) as ch: ch.open(clipid, FPLibrary.FP_OPEN_ASTREE) clip_attrs = ch.getDescriptionAttributes() assert filename in clip_attrs[ 'name'], "Missing data in %r" % clip_attrs print(clip_attrs)
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
def test_description(self): expected_attributes = ['refid', 'name', 'modification.date', 'totalsize', 'clusterid', 'modification.profile', 'creation.date', 'retention.period', 'numfiles', 'prev.clip', 'creation.poolid', 'modification.poolid', 'numtags', 'creation.profile', 'type', 'sdk.version', 'clip.naming.scheme'] clip = FPClip(self.pool) clip.open(clipid, FPLibrary.FP_OPEN_ASTREE) try: attributes = clip.getNumDescriptionAttributes() assert all(x in attributes for x in expected_attributes) finally: print("closing clip") clip.close()
def test_store_large(self): retention_sec = 100 filename = "textfile.out" top_tag = "file" clip_name = "myclip_" + filename with closing(FPClip(self.pool, clip_name, close_retries=3)) as clip: clipid = self.write_clip(clip, filename, retention_sec, top_tag) print(clipid)
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()
def get(self, clip_id, tag=None): """ Get a (closed) clip from worm. While storing or retrieving tags from worm, you may need to set a close_retry. :param clip: :return: """ with closing(FPClip(self.pool, close_retries=3 if tag else 0)) as clip: self._open_or_not_found(clip, clip_id) clip.attributes = clip.getDescriptionAttributes() if tag: clip.tags = [x for x in clip.getTags()] return clip
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
def test_store_small(self): try: retention_sec = 100 filename = "myfile.xml" top_tag = "file" clip_name = "myclip_" + filename with closing(FPClip(self.pool, clip_name, close_retries=3)) as clip: clipid = self.write_clip(clip, filename, retention_sec, top_tag) print(clipid) self.assert_clip_name(clipid, filename) except FPClientException as c: print(c) traceback.print_exc(file=sys.stdout) except FPServerException as s: print(s) except FPNetException as n: print(n) except FPException as e: print(e)
try: ip = raw_input( "Pool address: " ) pool = FPPool( ip ) pool.registerApplication( "python wrapper delete example", "1.0" ) d = pool.getCapability( FPLibrary.FP_DELETE, FPLibrary.FP_ALLOWED ) print d if(d): clip = FPClip( pool ) ca = raw_input( "Content address: " ) audited = raw_input( "(a)udited/(n)ormal: " ) if audited in ['a','A']: reason = raw_input( "Reason string: " ) priv = raw_input( "(p)rivileged/(n)ormal: " ) if( priv in ['p','P'] ): clip.auditedDelete( ca, reason, FPLibrary.FP_OPTION_DELETE_PRIVILEGED ) elif( priv in ['n','N']): clip.auditedDelete( ca, reason, FPLibrary.FP_OPTION_DEFAULT_OPTIONS )
from Filepool.FPRetention import FPRetention try: ip = raw_input( "Pool address: " ) pool = FPPool( ip ) 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 )
from Filepool.FPTag import FPTag try: ip = raw_input("Pool address: ") pool = FPPool(ip) 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)
from Filepool.FPTag import FPTag from Filepool.FPFileOutputStream import FPFileOutputStream from Filepool.FPRetention import FPRetention from Filepool.util import parse_config config = parse_config("test/test.ini") ip = raw_input("Pool address: ") or config['test']['POOL_ADDRESS'] clipid = clipid or config['test']['read_clipid'] pool = FPPool(ip) pool.setGlobalOption(FPLibrary.FP_OPTION_EMBEDDED_DATA_THRESHOLD, 100 * 1024) pool.getPoolInfo() # the application will be attached to the clip id pool.registerApplication("python wrapper read example", "1.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)
try: ip = raw_input("Pool address: ") pool = FPPool(ip) pool.registerApplication("python wrapper delete example", "1.0") d = pool.getCapability(FPLibrary.FP_DELETE, FPLibrary.FP_ALLOWED) print d if (d): clip = FPClip(pool) ca = raw_input("Content address: ") audited = raw_input("(a)udited/(n)ormal: ") if audited in ['a', 'A']: reason = raw_input("Reason string: ") priv = raw_input("(p)rivileged/(n)ormal: ") if (priv in ['p', 'P']): clip.auditedDelete(ca, reason, FPLibrary.FP_OPTION_DELETE_PRIVILEGED) elif (priv in ['n', 'N']): clip.auditedDelete(ca, reason,
from Filepool.FPRetention import FPRetention try: ip = raw_input( "Pool address: " ) pool = FPPool( ip ) 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 )