patool/patoolib/programs/p7zip.py

149 lines
4.0 KiB
Python
Raw Normal View History

2010-02-21 11:14:57 +00:00
# -*- coding: utf-8 -*-
2015-07-19 13:43:21 +00:00
# Copyright (C) 2010-2015 Bastian Kleineidam
2010-02-21 11:14:57 +00:00
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Archive commands for the 7z program."""
2015-12-06 19:09:16 +00:00
def extract_7z(archive, compression, cmd, verbosity, interactive, outdir):
2010-02-21 11:14:57 +00:00
"""Extract a 7z archive."""
2015-12-06 19:09:16 +00:00
cmdlist = [cmd, 'x']
if not interactive:
cmdlist.append('-y')
cmdlist.extend(['-o%s' % outdir, '--', archive])
return cmdlist
2010-02-21 11:14:57 +00:00
2015-12-06 19:09:16 +00:00
def extract_7z_singlefile(archive, compression, cmd, verbosity, interactive, outdir):
2013-04-05 16:46:30 +00:00
"""Extract a singlefile archive (eg. gzip or bzip2) with '7z e'.
This makes sure a single file and no subdirectories are created,
which would cause errors with patool repack."""
2015-12-06 19:09:16 +00:00
cmdlist = [cmd, 'e']
if not interactive:
cmdlist.append('-y')
cmdlist.extend(['-o%s' % outdir, '--', archive])
return cmdlist
2013-04-05 16:46:30 +00:00
2010-02-21 11:14:57 +00:00
extract_bzip2 = \
extract_gzip = \
extract_compress = \
2013-04-05 16:46:30 +00:00
extract_xz = \
extract_lzma = \
extract_7z_singlefile
extract_zip = \
2010-02-21 11:14:57 +00:00
extract_rar = \
extract_cab = \
extract_arj = \
extract_cpio = \
extract_rpm = \
extract_deb = \
2013-02-27 18:38:07 +00:00
extract_iso = \
2010-02-21 11:14:57 +00:00
extract_7z
2015-12-06 19:09:16 +00:00
def list_7z (archive, compression, cmd, verbosity, interactive):
2010-02-21 11:14:57 +00:00
"""List a 7z archive."""
2015-12-06 19:09:16 +00:00
cmdlist = [cmd, 'l']
if not interactive:
cmdlist.append('-y')
cmdlist.extend(['--', archive])
return cmdlist
2010-02-21 11:14:57 +00:00
list_bzip2 = \
list_gzip = \
list_zip = \
list_compress = \
list_rar = \
list_cab = \
list_arj = \
list_cpio = \
list_rpm = \
list_deb = \
2013-02-27 18:38:07 +00:00
list_iso = \
2013-02-27 19:05:54 +00:00
list_xz = \
2013-02-27 19:20:02 +00:00
list_lzma = \
2010-02-21 11:14:57 +00:00
list_7z
2010-02-21 12:40:42 +00:00
2015-12-06 19:09:16 +00:00
def test_7z (archive, compression, cmd, verbosity, interactive):
2010-02-21 12:40:42 +00:00
"""Test a 7z archive."""
2015-12-06 19:09:16 +00:00
cmdlist = [cmd, 't']
if not interactive:
cmdlist.append('-y')
cmdlist.extend(['--', archive])
return cmdlist
2010-02-21 12:40:42 +00:00
test_bzip2 = \
test_gzip = \
test_zip = \
test_compress = \
test_rar = \
test_cab = \
test_arj = \
test_cpio = \
test_rpm = \
test_deb = \
2013-02-27 18:38:07 +00:00
test_iso = \
2013-02-27 19:05:54 +00:00
test_xz = \
2013-02-27 19:20:02 +00:00
test_lzma = \
2010-02-21 12:40:42 +00:00
test_7z
2010-02-21 14:48:52 +00:00
2015-12-06 19:09:16 +00:00
def create_7z(archive, compression, cmd, verbosity, interactive, filenames):
2010-02-21 14:48:52 +00:00
"""Create a 7z archive."""
2015-12-06 19:09:16 +00:00
cmdlist = [cmd, 'a']
if not interactive:
cmdlist.append('-y')
cmdlist.extend(['-t7z', '-mx=9', '--', archive])
cmdlist.extend(filenames)
2010-02-21 14:48:52 +00:00
return cmdlist
2015-07-19 15:29:33 +00:00
2015-12-06 19:09:16 +00:00
def create_zip(archive, compression, cmd, verbosity, interactive, filenames):
2015-07-19 15:29:33 +00:00
"""Create a ZIP archive."""
2015-12-06 19:09:16 +00:00
cmdlist = [cmd, 'a']
if not interactive:
cmdlist.append('-y')
cmdlist.extend(['-tzip', '-mx=9', '--', archive])
2015-07-19 15:29:33 +00:00
cmdlist.extend(filenames)
return cmdlist
2015-12-06 19:09:16 +00:00
def create_xz(archive, compression, cmd, verbosity, interactive, filenames):
2015-07-19 15:29:33 +00:00
"""Create an XZ archive."""
2015-12-06 19:09:16 +00:00
cmdlist = [cmd, 'a']
if not interactive:
cmdlist.append('-y')
cmdlist.extend(['-txz', '-mx=9', '--', archive])
2015-07-19 15:29:33 +00:00
cmdlist.extend(filenames)
return cmdlist
2015-12-06 19:09:16 +00:00
def create_gzip(archive, compression, cmd, verbosity, interactive, filenames):
2015-07-19 15:29:33 +00:00
"""Create a GZIP archive."""
2015-12-06 19:09:16 +00:00
cmdlist = [cmd, 'a']
if not interactive:
cmdlist.append('-y')
cmdlist.extend(['-tgzip', '-mx=9', '--', archive])
2015-07-19 15:29:33 +00:00
cmdlist.extend(filenames)
return cmdlist
2015-12-06 19:09:16 +00:00
def create_bzip2(archive, compression, cmd, verbosity, interactive, filenames):
2015-07-19 15:29:33 +00:00
"""Create a BZIP2 archive."""
2015-12-06 19:09:16 +00:00
cmdlist = [cmd, 'a']
if not interactive:
cmdlist.append('-y')
cmdlist.extend(['-tbzip2', '-mx=9', '--', archive])
2015-07-19 15:29:33 +00:00
cmdlist.extend(filenames)
return cmdlist