+
+ @staticmethod
+ def match_ext(archive, *extensions):
+ for ext in extensions:
+ if archive.endswith(ext):
+ return True
+ return False
+
+ def compress(self, server, path, files, archive):
+ if self.match_ext(archive, '.tar.gz', '.tgz'):
+ cmd, args = 'tar', ['cvzf', archive, '-C', path] + files
+ elif self.match_ext(archive, '.tar.bz2', '.tbz'):
+ cmd, args = 'tar', ['cvjf', archive, '-C', path] + files
+ elif self.match_ext(archive, '.zip'):
+ cmd, args = 'jar', (['cvMf', archive] + list(chain.from_iterable(('-C', path, f) for f in files)))
+ else:
+ raise ValueError('Unknown archive type: {}'.format(archive))
+
+ self.op_attr.set_disk_stack('#'.join(["popen:argv=", cmd] + args))
+
+ return self.get(server)
+
+ def extract(self, server, archive, dst):
+ if self.match_ext(archive, '.tar.gz', '.tgz'):
+ cmd, args = 'tar', ('xvzf', archive, '-C', dst)
+ elif self.match_ext(archive, '.tar.bz2', '.tbz'):
+ cmd, args = 'tar', ('xvjf', archive, '-C', dst)
+ elif self.match_ext(archive, '.zip'):
+ cmd, args = 'unzip', (archive, '-d', dst)
+ else:
+ raise ValueError('Unknown archive type: {}'.format(archive))
+
+ self.op_attr.set_disk_stack('#'.join(("popen:argv=", cmd) + args))
+
+ return self.get(server)