Commit b2e33b9c authored by Marco Kurzynski's avatar Marco Kurzynski
Browse files

fixed dmv

parent e8a139db
#!/usr/bin/env python3.8
from os.path import basename, join, dirname, isdir
from os.path import basename, join, dirname, isdir, realpath
from os import mkdir, getenv
import subprocess
import argparse
import shutil
from utils import file_finder
def process(input_file, args):
def process(input_file, output_dir, args):
exe = '/usr/bin/dmv-ncdf'
output_file = join(dirname(input_file), f'{basename(input_file)[:-4]}_{str.lower(basename(input_file)[-3:])}.nc')
logfile = join(dirname(input_file), f'{basename(input_file)[:-4]}_{str.lower(basename(input_file)[-3:])}.log')
......@@ -20,11 +20,13 @@ def process(input_file, args):
p = subprocess.Popen( [exe], stdout=subprocess.PIPE, stdin=subprocess.PIPE )
p.communicate(dmv_input.encode())
if not isdir(args.output_dir):
mkdir(args.output_dir)
if not output_dir:
output_dir = dirname(input_file)
if not isdir(output_dir):
mkdir(output_dir)
shutil.move(logfile, join(args.output_dir,basename(logfile)))
shutil.move(output_file, join(args.output_dir,basename(output_file)))
shutil.move(logfile, join(output_dir,basename(logfile)))
shutil.move(output_file, join(output_dir,basename(output_file)))
if __name__=='__main__':
......@@ -35,7 +37,6 @@ if __name__=='__main__':
action="count", default=0,
help='show output to terminal')
parser.add_argument('-o','--output-dir',
default=getenv("PWD"),
help='output directory name')
parser.add_argument('-e','--extensions',
nargs="+",
......@@ -47,7 +48,6 @@ if __name__=='__main__':
ae_dirs = file_finder.getFiles(args.input_file, extensions=args.extensions)
for d, files in ae_dirs.items():
for f in files:
process(join(d,f), args)
process(join(d,f), args.output_dir, args)
else:
process(args.input_file, args)
process(realpath(args.input_file), args.output_dir, args)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment