Source code for foundations.pkzip
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
**pkzip.py**
**Platform:**
Windows, Linux, Mac Os X.
**Description:**
Provides archives files manipulation objects.
**Others:**
"""
#**********************************************************************************************************************
#*** Future imports.
#**********************************************************************************************************************
from __future__ import unicode_literals
#**********************************************************************************************************************
#*** 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 - 2014 - Thomas Mansencal"
__license__ = "GPL V3.0 - http://www.gnu.org/licenses/"
__maintainer__ = "Thomas Mansencal"
__email__ = "[email protected]"
__status__ = "Production"
__all__ = ["LOGGER", "Pkzip"]
LOGGER = foundations.verbose.installLogger()
#**********************************************************************************************************************
#*** Module classes and definitions.
#**********************************************************************************************************************
[docs]class Pkzip(object):
"""
Defines methods to manipulate zip files.
"""
def __init__(self, archive=None):
"""
Initializes the class.
Usage::
>>> import tempfile
>>> tempDirectory = tempfile.mkdtemp()
>>> zipFile = Pkzip("zipFile.zip")
>>> zipFile.extract(tempDirectory)
True
:param archive: Archive to manipulate.
:type archive: unicode
"""
LOGGER.debug("> Initializing '{0}()' class.".format(self.__class__.__name__))
# --- Setting class attributes. ---
self.__archive = None
self.archive = archive
#******************************************************************************************************************
#*** Attributes properties.
#******************************************************************************************************************
@property
def archive(self):
"""
Property for **self.__archive** attribute.
:return: self.__archive.
:rtype: unicode
"""
return self.__archive
@archive.setter
# Oncilla: Statement commented by auto-documentation process: @foundations.exceptions.handleExceptions(AssertionError)
def archive(self, value):
"""
Setter for **self.__archive** attribute.
:param value: Attribute value.
:type value: unicode
"""
if value is not None:
assert type(value) is unicode, "'{0}' attribute: '{1}' type is not 'unicode'!".format(
"archive", value)
assert os.path.exists(value), "'{0}' attribute: '{1}' file doesn't exists!".format("archive", value)
self.__archive = value
@archive.deleter
# Oncilla: Statement commented by auto-documentation process: @foundations.exceptions.handleExceptions(foundations.exceptions.ProgrammingError)
[docs] def archive(self):
"""
Deleter for **self.__archive** attribute.
"""
raise foundations.exceptions.ProgrammingError(
"{0} | '{1}' attribute is not deletable!".format(self.__class__.__name__, "archive"))
#******************************************************************************************************************
#*** Class methods.
#******************************************************************************************************************
# Oncilla: Statement commented by auto-documentation process: @foundations.exceptions.handleExceptions(foundations.exceptions.DirectoryExistsError,
# Oncilla: Statement commented by auto-documentation process: foundations.exceptions.FileExistsError,
# Oncilla: Statement commented by auto-documentation process: zipfile.BadZipfile)