Source code for foundations.pkzip
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
**pkzip.py**
**Platform:**
Windows, Linux, Mac Os X.
**Description:**
This module provides archives files manipulation objects.
**Others:**
"""
#**********************************************************************************************************************
#*** External imports.
#**********************************************************************************************************************
from cStringIO import StringIO
import os
import zipfile
#**********************************************************************************************************************
#*** Internal imports.
#**********************************************************************************************************************
import foundations.io
import foundations.exceptions
import foundations.verbose
#**********************************************************************************************************************
#*** Module attributes.
#**********************************************************************************************************************
__author__ = "Thomas Mansencal"
__copyright__ = "Copyright (C) 2008 - 2012 - Thomas Mansencal"
__license__ = "GPL V3.0 - http://www.gnu.org/licenses/"
__maintainer__ = "Thomas Mansencal"
__email__ = "thomas.mansencal@gmail.com"
__status__ = "Production"
__all__ = ["LOGGER", "Pkzip"]
LOGGER = foundations.verbose.installLogger()
#**********************************************************************************************************************
#*** Module classes and definitions.
#**********************************************************************************************************************
[docs]class Pkzip(object):
"""
This class provides methods to manipulate zip files.
"""
def __init__(self, archive=None):
"""
.. Sphinx: Statements updated for auto-documentation purpose.
Usage::
>>> import tempfile
>>> tempDirectory = tempfile.mkdtemp()
>>> zipFile = Pkzip("zipFile.zip")
>>> zipFile.extract(tempDirectory)
True
:param archive: Archive to manipulate. ( String )
"""
LOGGER.debug("> Initializing '{0}()' class.".format(self.__class__.__name__))
# --- Setting class attributes. ---
self.__archive = None
self.archive = archive
#******************************************************************************************************************
#*** Attributes properties.
#******************************************************************************************************************
@property
def archive(self):
"""
This method is the property for **self.__archive** attribute.
:return: self.__archive. ( String )
"""
return self.__archive
@archive.setter
#*** Sphinx: Decorator commented for auto-documentation purpose. @foundations.exceptions.handleExceptions(AssertionError)
def archive(self, value):
"""
This method is the setter method for **self.__archive** attribute.
:param value: Attribute value. ( String )
"""
if value is not None:
assert type(value) in (str, unicode), "'{0}' attribute: '{1}' type is not 'str' or 'unicode'!".format(
"archive", value)
assert os.path.exists(value), "'{0}' attribute: '{1}' file doesn't exists!".format("archive", value)
self.__archive = value
@archive.deleter
#*** Sphinx: Decorator commented for auto-documentation purpose. @foundations.exceptions.handleExceptions(foundations.exceptions.ProgrammingError)
[docs] def archive(self):
"""
This method is the deleter method for **self.__archive** attribute.
"""
raise foundations.exceptions.ProgrammingError(
"{0} | '{1}' attribute is not deletable!".format(self.__class__.__name__, "archive"))
#******************************************************************************************************************
#*** Class methods.
#******************************************************************************************************************