From 81b1c38dbd530d3be599605d3241089780bd9141 Mon Sep 17 00:00:00 2001 From: Michael Vrable Date: Mon, 15 Dec 2008 15:15:19 -0800 Subject: [PATCH] Detect decompression script needed for segments based on extension. --- python/cumulus/__init__.py | 42 ++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/python/cumulus/__init__.py b/python/cumulus/__init__.py index 424e38c..b120436 100644 --- a/python/cumulus/__init__.py +++ b/python/cumulus/__init__.py @@ -23,6 +23,15 @@ MAX_RECURSION_DEPTH = 3 # All segments which have been accessed this session. accessed_segments = set() +# Table of methods used to filter segments before storage, and corresponding +# filename extensions. These are listed in priority order (methods earlier in +# the list are tried first). +SEGMENT_FILTERS = [ + (".gpg", "lbs-filter-gpg --decrypt"), + (".gz", "gzip -dc"), + (".bz2", "bzip2 -dc"), +] + def uri_decode(s): """Decode a URI-encoded (%xx escapes) string.""" def hex_decode(m): return chr(int(m.group(1), 16)) @@ -186,19 +195,26 @@ class ObjectStore: def get_segment(self, segment): accessed_segments.add(segment) - raw = self.store.lowlevel_open(segment + ".tar.gpg") - - (input, output) = os.popen2("lbs-filter-gpg --decrypt") - def copy_thread(src, dst): - BLOCK_SIZE = 4096 - while True: - block = src.read(BLOCK_SIZE) - if len(block) == 0: break - dst.write(block) - dst.close() - - thread.start_new_thread(copy_thread, (raw, input)) - return output + + for (extension, filter) in SEGMENT_FILTERS: + try: + raw = self.store.lowlevel_open(segment + ".tar" + extension) + + (input, output) = os.popen2(filter) + def copy_thread(src, dst): + BLOCK_SIZE = 4096 + while True: + block = src.read(BLOCK_SIZE) + if len(block) == 0: break + dst.write(block) + dst.close() + + thread.start_new_thread(copy_thread, (raw, input)) + return output + except: + pass + + raise cumulus.store.NotFoundError def load_segment(self, segment): seg = tarfile.open(segment, 'r|', self.get_segment(segment)) -- 2.20.1