提交 67887a0c 编写于 作者: L Lucas Meneghel Rodrigues

Merge pull request #254 from ldoktor/tar

avocado.utils.archive: Add support for .tar.xz [V3]
......@@ -11,7 +11,7 @@ virtualenv:
before_script:
- sudo apt-get update
- sudo apt-get -y --force-yes install python-libvirt build-essential python-yaml
- sudo apt-get -y --force-yes install python-libvirt build-essential python-yaml python-lzma
install:
- pip install sphinx tox pylint autopep8 flexmock
......
......@@ -8,7 +8,7 @@ URL: http://avocado-framework.readthedocs.org/
Source: avocado-%{version}.tar.gz
BuildRequires: python2-devel, python-docutils, python-yaml
BuildArch: noarch
Requires: python, python-requests, python-yaml, fabric
Requires: python, python-requests, python-yaml, fabric, pyliblzma
%description
Avocado is a set of tools and libraries (what people call
......
......@@ -17,9 +17,10 @@
Module to help extract and create compressed archives.
"""
import lzma
import os
import zipfile
import tarfile
import zipfile
class ArchiveException(Exception):
......@@ -30,6 +31,39 @@ class ArchiveException(Exception):
pass
class _WrapLZMA(object):
""" wraps tar.xz for python 2.7's tarfile """
def __init__(self, filename, mode):
"""
Creates an instance of :class:`ArchiveFile`.
:param filename: the archive file name.
:param mode: file mode, `r` read, `w` write.
"""
self._engine = tarfile.open(fileobj=lzma.LZMAFile(filename, mode),
mode=mode)
methods = dir(self._engine)
for meth in dir(self):
try:
methods.remove(meth)
except ValueError:
pass
for method in methods:
setattr(self, method, getattr(self._engine, method))
@classmethod
def open(cls, filename, mode='r'):
"""
Creates an instance of :class:`_WrapLZMA`.
:param filename: the archive file name.
:param mode: file mode, `r` read, `w` write.
"""
return cls(filename, mode)
class ArchiveFile(object):
"""
......@@ -45,7 +79,8 @@ class ArchiveFile(object):
'.tar.gz': (False, True, tarfile.open, ':gz'),
'.tgz': (False, True, tarfile.open, ':gz'),
'.tar.bz2': (False, True, tarfile.open, ':bz2'),
'.tbz2': (False, True, tarfile.open, ':bz2'), }
'.tbz2': (False, True, tarfile.open, ':bz2'),
'.xz': (False, True, _WrapLZMA.open, '')}
def __init__(self, filename, mode='r'):
"""
......
......@@ -9,5 +9,5 @@ Package: avocado
Architecture: all
Homepage: http://autotest.github.com/
XB-Python-Version: ${python:Versions}
Depends: ${misc:Depends}, ${python:Depends}, python-yaml
Depends: ${misc:Depends}, ${python:Depends}, python-yaml, python-lzma
Description: Avocado is a framework for fully automated testing.
......@@ -6,3 +6,4 @@ virtualenv==1.9.1
mysql-python==1.2.3
requests==1.2.3
fabric==1.7.0
pyliblzma==0.5.3
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册