sistema_progs

Programas para customizar o meu entorno de traballo nos meus equipos persoais
Log | Files | Refs

natool (1396B)


      1 #!/usr/bin/env python3
      2 
      3 # #############################################################################
      4 # natool: a wrapper script to patool to list, extract and create archives
      5 #
      6 # usage: natool [-a] [-l] [-x] [archive] [file/dir]
      7 #
      8 # Examples:
      9 # - create archive : natool -a archive.7z archive_dir
     10 # - list archive   : natool -l archive.7z
     11 # - extract archive: natool -x archive.7z
     12 #
     13 # Brief:
     14 # natool is written to integrate patool (instead of the default atool) with nnn
     15 # A copies of this file should be dropped somewhere in $PATH as atool
     16 #
     17 # Author: Arun Prakash Jana
     18 # Email: engineerarun@gmail.com
     19 # Homepage: https://github.com/jarun/nnn
     20 # Copyright © 2019 Arun Prakash Jana
     21 # #############################################################################
     22 
     23 import sys
     24 from subprocess import Popen, PIPE
     25 
     26 if len(sys.argv) < 3:
     27     print('usage: natool [-a] [-l] [-x] [archive] [file/dir]')
     28     sys.exit(0)
     29 
     30 if sys.argv[1] == '-a':
     31     cmd = ['patool', '--non-interactive', 'create', sys.argv[2]]
     32     cmd.extend(sys.argv[3:])
     33 elif sys.argv[1] == '-l':
     34     cmd = ['patool', '--non-interactive', 'list']
     35     cmd.extend(sys.argv[2:])
     36 elif sys.argv[1] == '-x':
     37     cmd = ['patool', '--non-interactive', 'extract']
     38     cmd.extend(sys.argv[2:])
     39 else:
     40     sys.exit(0)
     41 
     42 pipe = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
     43 out, err = pipe.communicate()
     44 print(out.decode())
     45 print(err.decode())