nnn/misc/natool/natool

46 lines
1.4 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env python3
# #############################################################################
# natool: a wrapper script to patool to list, extract and create archives
#
2019-05-19 16:14:58 +00:00
# usage: natool [-a] [-l] [-x] [archive] [file/dir]
#
# Examples:
2019-05-19 16:14:58 +00:00
# - create archive : natool -a archive.7z archive_dir
# - list archive : natool -l archive.7z
# - extract archive: natool -x archive.7z
#
# Brief:
# natool is written to integrate patool (instead of the default atool) with nnn
2019-05-19 16:14:58 +00:00
# A copies of this file should be dropped somewhere in $PATH as atool
#
# Author: Arun Prakash Jana
# Email: engineerarun@gmail.com
# Homepage: https://github.com/jarun/nnn
2019-01-01 02:31:48 +00:00
# Copyright © 2019 Arun Prakash Jana
# #############################################################################
import sys
from subprocess import Popen, PIPE, DEVNULL
2019-01-30 15:08:13 +00:00
if len(sys.argv) < 3:
2019-05-19 16:14:58 +00:00
print('usage: natool [-a] [-l] [-x] [archive] [file/dir]')
sys.exit(0)
2019-05-19 16:14:58 +00:00
if sys.argv[1] == '-a':
cmd = ['patool', '--non-interactive', 'create', sys.argv[2]]
cmd.extend(sys.argv[3:])
elif sys.argv[1] == '-l':
2019-01-30 15:08:13 +00:00
cmd = ['patool', '--non-interactive', 'list']
2019-05-19 16:14:58 +00:00
cmd.extend(sys.argv[2:])
elif sys.argv[1] == '-x':
cmd = ['patool', '--non-interactive', 'extract']
cmd.extend(sys.argv[2:])
else:
2019-05-19 16:14:58 +00:00
sys.exit(0)
pipe = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
out, err = pipe.communicate()
print(out.decode())
print(err.decode())