diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..830105a --- /dev/null +++ b/.travis.yml @@ -0,0 +1,10 @@ +language: python +python: + - "2.7" +env: + - DJANGO=1.3 + - DJANGO=1.4 +install: + - pip install --timeout=30 -q -e . --use-mirrors +script: + - make test diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0b9ca94 --- /dev/null +++ b/Makefile @@ -0,0 +1,13 @@ +test: + python tests.py + +verify: + pyflakes libarchive + pep8 --exclude=migrations --ignore=E501,E225 libarchive + +install: + python setup.py install + +publish: + python setup.py register + python setup.py sdist upload diff --git a/README.rst b/README.rst index 506a8d6..2fda1b6 100644 --- a/README.rst +++ b/README.rst @@ -1,3 +1,6 @@ +.. image:: https://travis-ci.org/smartfile/python-libarchive.svg + :target: https://travis-ci.org/smartfile/python-libarchive + A `SmartFile`_ Open Source project. `Read more`_ about how SmartFile uses and contributes to Open Source software. diff --git a/libarchive/tar.py b/libarchive/tar.py index b5b19cf..dadd84e 100644 --- a/libarchive/tar.py +++ b/libarchive/tar.py @@ -1,32 +1,8 @@ -# Copyright (c) 2011, SmartFile -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# * Neither the name of the organization nor the -# names of its contributors may be used to endorse or promote products -# derived from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY -# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -import time +import os from libarchive import is_archive, Entry, SeekableArchive -from tarfile import DEFAULT_FORMAT, USTAR_FORMAT, GNU_FORMAT, PAX_FORMAT, ENCODING -from tarfile import REGTYPE, AREGTYPE, LNKTYPE, SYMTYPE, DIRTYPE, FIFOTYPE, CONTTYPE, CHRTYPE, BLKTYPE, GNUTYPE_SPARSE +from tarfile import DEFAULT_FORMAT, USTAR_FORMAT, GNU_FORMAT, PAX_FORMAT, \ + ENCODING +from tarfile import REGTYPE, SYMTYPE, DIRTYPE, FIFOTYPE, CHRTYPE, BLKTYPE FORMAT_CONVERSION = { USTAR_FORMAT: 'tar', @@ -76,7 +52,13 @@ class TarInfo(Entry): class TarFile(SeekableArchive): - def __init__(self, name=None, mode='r', fileobj=None, format=DEFAULT_FORMAT, tarinfo=TarInfo, encoding=ENCODING): + getmember = SeekableArchive.getentry + list = SeekableArchive.printlist + extract = SeekableArchive.readpath + extractfile = SeekableArchive.readstream + + def __init__(self, name=None, mode='r', fileobj=None, + format=DEFAULT_FORMAT, tarinfo=TarInfo, encoding=ENCODING): if name: f = name elif fileobj: @@ -85,12 +67,8 @@ class TarFile(SeekableArchive): format = FORMAT_CONVERSION.get(format) except KeyError: raise Exception('Invalid tar format: %s' % format) - super(TarFile, self).__init__(f, mode=mode, format=format, entry_class=tarinfo, encoding=encoding) - - getmember = SeekableArchive.getentry - list = SeekableArchive.printlist - extract = SeekableArchive.readpath - extractfile = SeekableArchive.readstream + super(TarFile, self).__init__(f, mode=mode, format=format, + entry_class=tarinfo, encoding=encoding) def getmembers(self): return list(self) @@ -99,6 +77,7 @@ class TarFile(SeekableArchive): return list(self.iterpaths) def next(self): + raise NotImplementedError pass # TODO: how to do this? def extract(self, member, path=None): @@ -113,10 +92,10 @@ class TarFile(SeekableArchive): def add(self, name, arcname, recursive=True, exclude=None, filter=None): pass # TODO: implement this. - def addfile(tarinfo, fileobj): + def addfile(self, tarinfo, fileobj): return self.writepath(fileobj, tarinfo) - def gettarinfo(name=None, arcname=None, fileobj=None): + def gettarinfo(self, name=None, arcname=None, fileobj=None): if name: f = name elif fileobj: diff --git a/libarchive/zip.py b/libarchive/zip.py index 539f6db..2fc32c0 100644 --- a/libarchive/zip.py +++ b/libarchive/zip.py @@ -1,28 +1,3 @@ -# Copyright (c) 2011, SmartFile -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# * Neither the name of the organization nor the -# names of its contributors may be used to endorse or promote products -# derived from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY -# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - import os, time from libarchive import is_archive, Entry, SeekableArchive from zipfile import ZIP_STORED, ZIP_DEFLATED @@ -48,7 +23,7 @@ class ZipEntry(Entry): return self.size def set_file_size(self, value): - assert isinstance(size, (int, long)), 'Please provide size as int or long.' + assert isinstance(value, (int, long)), 'Please provide size as int or long.' self.size = value file_size = property(get_file_size, set_file_size)