sort into folders
This commit is contained in:
C&C++
1st_day_of_month.cppJJbY.cppTp6G.cppalternatice_bracket.c
autoconfig
c.phpc_old_argument_notation.ccnn.ccomp.cconditional_const.cconst.ccpp_regex_error.cppcurrent_year.cppdda2.cppdog.jpgdog2.jpgelse_while.cflex
for_ctags.cppfree_null.cgcc_include_next.cgdb_graph.cgetopt_test.cgnu_decimals.cgnu_history.cgnu_regex.cgnu_regex2.cheader.hindex_in_initializer_list_compiler_extension.cknr.clevenshtein_dist_-_usage.cpplinking
map_initialization.cppncurses_labels.cncurses_mv_win.cppncurses_plus_readline.cppncurses_resize2.cppncurses_resize_hello_world.cppncurses_resize_test.cncurses_scroll.cnf.cnull_printf.cnull_printf.cppportable_namespace.cportable_namespace.hpta.cscoping_showcase.cscreen_size_(without_curses).csdl_render_to_texture.cppsentinel_pack.csetjmp_test.cppstrdup.ctcc_int.ctest.ctypedef.cunctrl.cundefined_reference.cusb.cvasprintf.cvoid_main.cx.cppxtermio.cxtp.cppMisc.
bind_test.sh
cross_compile
example.m4extension_cut.Makefilefizzbuzz.f90gdb_pretty_print
guards.hstest.infotest.texiPython
ascii_injection.pyascii_nn_input_helper.pydpt.pyformat.pygraph.pygroup.pyint_memory.ctype.pyint_memory.py.pyotest.pytkinter_filepicker_test.pytorus.py
Vim
Webdev
100
Python/dpt.py
Executable file
100
Python/dpt.py
Executable file
@ -0,0 +1,100 @@
|
||||
#!/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)
|
Reference in New Issue
Block a user