Docs for seven_zip

SevenZip

class seven_zip.SevenZip(name)

SevenZip class. create a object like this:

>>> zipfile = seven_zip.SevenZip("file.zip")

then you can do fancy stuff like:

>>> zipfile.getnames()

to print all files in the archive. or extract it:

>>> zipfile.extractall("~/")

or more advanced: extract only jpg’s bigger than 1MB to a special folder:

>>> for member in zipfile.searchmember("*.jpg"):
>>>    if member.size > (1024**2):
>>>        member.extract("/tmp/bigpictures")
archive_path = None

Path to the archive

archive_type = None

Type of the archive, e.g. zip

extract(name, path_to_extr)

extract the file name to the path

Parameters:
  • name – The name of the File to be extractet out of the archive
  • path_to_extr – The Path where the File should be written to
Return type:

Path to extracted file as string

extract_all(path)

extract all files to path. this will overwrite files, create directorys etc. you have been warned! returns the paths to the extracted files (as a list)

extract_smart(path)

extracts the archive like someone would excpect

extract_super_smart(path)

extracts files out of pkg’s in dmg’s

getmember(path_in_archive)

return the SevenZipMember for the path_in_archive. If there’s no File like path_in_archive return False

Parameters:path_in_archive – The Name/Path of the new Member
Return type:SevenZipMember
getmembers()

yield SevenZipMember for all Files in the Archive

getnames()

get the names from an archive. returns the names of the files in the archive.

method = None

Method of the Archive (e.g. )

searchmember(path_in_archive)

yield all :py:class:`SevenZipMember`(s) wildcard matching to the specified path

SevenZipMember

class seven_zip.SevenZipMember(path_to_archive, file_dict)
class SevenZipMember

This Class is used for so called “Members”. A Member is a file in an archive You can create Members with SevenZip.getmember("name") or yield all members:

>>> for i in seven_zip_object.getmembers:
>>>    print i.path, i.method

Or you can yield all members matching a specific name:

>>> for i in seven_zip_object.searchmembers("*.c"):
>>>     i.extract("~/code/")
SevenZipMember.extract(extractpath)

Extract the file of the member.

Parameters:extractpath – Extract the files There
Return type:Path to extracted File as string
SevenZipMember.get_info()

return dict with info’s about member. dict is taken from SevenZip

SevenZipMember.has_archive_filename()

is the member extracktable? Based on a stupid guess of the filename...

SevenZipMember.path = None

Path of the Member in the File

SevenZipMember.path_to_archive = None

Path to the whole Archive

SevenZipMember.size = None

Size in bytes