autoconfig
cgi
cross_compile
flex
gdb_pretty_print
linking
.gitignore
1st_day_of_month.cpp
JJbY.cpp
Makefile
alternatice_bracket.c
ascii_injection.py
ascii_nn_input_helper.py
bind_test.sh
blumba.html
bootrap.html
brython_hw.html
c.php
c_old_argument_notation.c
cnn.c
comp.c
conditional_const.c
const.c
cpp_regex_error.cpp
current_year.cpp
dda2.cpp
dog.jpg
dog2.jpg
dpt.py
dropdown.html
else_while.c
example.m4
extension_cut.Makefile
fddl.js
fizzbuzz.f90
for_ctags.cpp
format.py
free_null.c
gcc_include_next.c
gdb_graph.c
getopt_test.c
gnu_decimals.c
gnu_history.c
gnu_regex.c
gnu_regex2.c
graph.py
group.py
guards.hs
header.h
index_in_initializer_list_compiler_extension.c
initials_test.html
int_memory.ctype.py
int_memory.py.py
knr.c
levenshtein_dist_-_usage.cpp
map_initialization.cpp
menu.vim
ncurses_labels.c
ncurses_mv_win.cpp
ncurses_plus_readline.cpp
ncurses_resize2.cpp
ncurses_resize_hello_world.cpp
ncurses_resize_test.c
ncurses_scroll.c
nf.c
null_printf.c
null_printf.cpp
otest.py
portable_namespace.c
portable_namespace.h
101 lines
2.1 KiB
Python
Executable File
101 lines
2.1 KiB
Python
Executable File
#!/bin/python3
|
|
|
|
import sys
|
|
import getopt
|
|
import os
|
|
from pathlib import Path
|
|
import subprocess
|
|
|
|
ARCHIVE_TYPES = [
|
|
".zip",
|
|
".rar",
|
|
".7z"
|
|
]
|
|
MAX_OUTPUT_LEN = 150
|
|
|
|
input_path = ""
|
|
do_delete = False
|
|
|
|
def usage(name):
|
|
print('''{script} [options]
|
|
-i <path> : specify input dir
|
|
-d : do delete
|
|
-h : print help and quit'''\
|
|
.format(script=name))
|
|
|
|
def opts(argv):
|
|
global input_path, do_delete
|
|
try:
|
|
opts, args = getopt.getopt(argv[1:], 'i:dh')
|
|
except getopt.GetoptError as e:
|
|
print("Unkown option. Quiting.")
|
|
exit(1)
|
|
for opt, arg in opts:
|
|
if opt == '-i':
|
|
input_path = arg
|
|
elif opt == '-d':
|
|
do_delete = True
|
|
elif opt == '-h':
|
|
usage(argv[0])
|
|
exit(0)
|
|
|
|
def is_password_protected(file):
|
|
command = ['7z', 't', '-p', file]
|
|
process = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
|
|
try:
|
|
process.wait()
|
|
except:
|
|
pass
|
|
return 0 != process.returncode
|
|
|
|
def extract(file):
|
|
if is_password_protected(file):
|
|
#print('Ignoring ', file, '.', sep='')
|
|
return
|
|
global do_delete
|
|
output_dir = str(file.parent) + '/' + str(file.stem)
|
|
try:
|
|
os.mkdir(output_dir)
|
|
except:
|
|
pass
|
|
output_option = '-o' + str(output_dir)
|
|
command = ['7z', 'x', file, output_option]
|
|
try:
|
|
print('Extracting: ', file, '... ', sep='', end='')
|
|
process = subprocess.Popen(command, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, stdin=subprocess.PIPE)
|
|
process.communicate(input='Y\n'.encode())
|
|
process.wait()
|
|
if process.returncode == 0:
|
|
print('Success.')
|
|
if do_delete:
|
|
os.remove(file)
|
|
else:
|
|
print('Fail.')
|
|
except:
|
|
print('\nError while forking 7z. Is it installed correctly?')
|
|
|
|
def scandir(dir_):
|
|
#print('scandir', dir_)
|
|
global MAX_OUTPUT_LEN
|
|
global ARCHIVE_TYPES
|
|
if len(str(dir_)) >= MAX_OUTPUT_LEN:
|
|
return
|
|
for entry in Path(dir_).iterdir():
|
|
if entry.is_dir():
|
|
scandir(entry)
|
|
else:
|
|
for t in ARCHIVE_TYPES:
|
|
if t == entry.suffix:
|
|
extract(entry)
|
|
|
|
def main(argv):
|
|
global input_path, do_delete
|
|
opts(argv)
|
|
if input_path == '':
|
|
print("No input directory specified. Quiting.")
|
|
exit(1)
|
|
scandir(input_path)
|
|
|
|
if __name__ == "__main__":
|
|
main(sys.argv)
|