patool/patool

59 lines
1.7 KiB
Python
Executable File

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2010 Bastian Kleineidam
#
# 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/>.
"""
patool [extract|list] [sub-command-options] <archive-file>
"""
import sys
if not hasattr(sys, "version_info") or sys.version_info < (2, 5, 0, "final", 0):
raise SystemExit("Error, this script needs Python >= 2.5 installed")
from patoolib import handle_archive, list_formats, baker
@baker.command
def extract (archive, verbose=False, force=False):
"""Extract files from an archive."""
return handle_archive(archive, 'extract')
@baker.command
def list (archive, verbose=False):
"""List files in an archive."""
return handle_archive(archive, 'list')
@baker.command
def create (archive, *args):
"""Create an archive from given files."""
return handle_archive(archive, 'create', *args)
@baker.command
def test (archive, verbose=False):
"""Test files in an archive."""
return handle_archive(archive, 'test', verbose=verbose)
@baker.command
def formats ():
return list_formats()
try:
sys.exit(baker.run())
except baker.CommandError, msg:
print >>sys.stderr, "patool error:", msg
sys.exit(1)