|
@ -5,11 +5,15 @@ Created on Fri Sep 28 13:32:51 2018 |
|
|
@author: Nzix |
|
|
@author: Nzix |
|
|
""" |
|
|
""" |
|
|
|
|
|
|
|
|
import argparse, os, sys, re |
|
|
import argparse, os, sys, traceback, re |
|
|
import ncmdump |
|
|
from .core import dump |
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser( |
|
|
parser = argparse.ArgumentParser( |
|
|
prog = 'ncmdump' |
|
|
prog = 'ncmdump', add_help = False |
|
|
|
|
|
) |
|
|
|
|
|
parser.add_argument( |
|
|
|
|
|
'-h', action = 'help', |
|
|
|
|
|
help = 'show this help message and exit' |
|
|
) |
|
|
) |
|
|
parser.add_argument( |
|
|
parser.add_argument( |
|
|
'input', metavar = 'input', nargs = '*', default = ['.'], |
|
|
'input', metavar = 'input', nargs = '*', default = ['.'], |
|
@ -33,8 +37,8 @@ group.add_argument( |
|
|
help = 'overwrite file with the same name' |
|
|
help = 'overwrite file with the same name' |
|
|
) |
|
|
) |
|
|
group.add_argument( |
|
|
group.add_argument( |
|
|
'-s', dest = 'skip', action = 'store_true', |
|
|
'-r', dest = 'rename', action = 'store_true', |
|
|
help = 'skip conversion if file exist' |
|
|
help = 'auto rename if file name conflicts' |
|
|
) |
|
|
) |
|
|
args = parser.parse_args() |
|
|
args = parser.parse_args() |
|
|
|
|
|
|
|
@ -72,10 +76,11 @@ def name_format(path, meta): |
|
|
name += '.' + meta['format'] |
|
|
name += '.' + meta['format'] |
|
|
folder = args.output if args.output else os.path.dirname(path) |
|
|
folder = args.output if args.output else os.path.dirname(path) |
|
|
save = os.path.join(folder, name) |
|
|
save = os.path.join(folder, name) |
|
|
if not (args.cover or args.skip): save = validate_collision(save) |
|
|
if args.rename: save = validate_collision(save) |
|
|
return save |
|
|
return save |
|
|
|
|
|
|
|
|
if args.output: |
|
|
def main(): |
|
|
|
|
|
if args.output: |
|
|
args.output = os.path.abspath(args.output) |
|
|
args.output = os.path.abspath(args.output) |
|
|
if not os.path.exists(args.output): |
|
|
if not os.path.exists(args.output): |
|
|
print('output does not exist') |
|
|
print('output does not exist') |
|
@ -84,8 +89,8 @@ if args.output: |
|
|
print('output is not a folder') |
|
|
print('output is not a folder') |
|
|
exit() |
|
|
exit() |
|
|
|
|
|
|
|
|
files = [] |
|
|
files = [] |
|
|
for path in args.input: |
|
|
for path in args.input: |
|
|
path = os.path.abspath(path) |
|
|
path = os.path.abspath(path) |
|
|
if not os.path.exists(path): |
|
|
if not os.path.exists(path): |
|
|
continue |
|
|
continue |
|
@ -94,17 +99,22 @@ for path in args.input: |
|
|
else: |
|
|
else: |
|
|
files += [path] |
|
|
files += [path] |
|
|
|
|
|
|
|
|
if sys.version[0] == '2': |
|
|
if sys.version[0] == '2': |
|
|
files = [path.decode(sys.stdin.encoding) for path in files] |
|
|
files = [path.decode(sys.stdin.encoding) for path in files] |
|
|
|
|
|
|
|
|
if not files: |
|
|
if not files: |
|
|
print('empty input') |
|
|
print('empty input') |
|
|
exit() |
|
|
exit() |
|
|
|
|
|
|
|
|
for path in files: |
|
|
for path in files: |
|
|
try: |
|
|
try: |
|
|
save = ncmdump.dump(path, name_format, args.skip) |
|
|
save = dump(path, name_format, not args.cover) |
|
|
if save: print(os.path.split(save)[-1]) |
|
|
if save: print(os.path.split(save)[-1]) |
|
|
if args.delete: os.remove(path) |
|
|
if args.delete: os.remove(path) |
|
|
except KeyboardInterrupt: |
|
|
except KeyboardInterrupt: |
|
|
exit() |
|
|
exit() |
|
|
|
|
|
except: |
|
|
|
|
|
print(traceback.format_exc()) |
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
|
|
main() |