Commit 043c2e0e authored by VIGNET Pierre's avatar VIGNET Pierre
Browse files

Ability to detect wrong output directory

parent cbf091cd
......@@ -306,7 +306,10 @@ def compute_macs(args):
MODEL_NAME = params['chart_file'].split('/')[-1][:-4]
# FILES
CAM_FILE_PREFIX = params['output'] + MODEL_NAME + \
# Add trailing '/' if not present
output = params['output'] if params['output'][-1] == '/' \
else params['output'] + '/'
CAM_FILE_PREFIX = output + MODEL_NAME + \
'_' + params['final_prop'] + '_cam'
# cam_file
cam_file = CAM_FILE_PREFIX + ".txt"
......@@ -345,6 +348,25 @@ def args_to_param(args):
return {k: v for k, v in vars(args).items() if k != 'func'}
class readable_dir(argparse.Action):
"""
http://stackoverflow.com/questions/11415570/directory-path-types-with-argparse
"""
def __call__(self, parser, namespace, values, option_string=None):
prospective_dir = values
if not os.path.isdir(prospective_dir):
raise argparse.ArgumentTypeError(
"readable_dir:{0} is not a valid path".format(prospective_dir))
if os.access(prospective_dir, os.R_OK):
setattr(namespace, self.dest, prospective_dir)
else:
raise argparse.ArgumentTypeError(
"readable_dir:{0} is not a readable dir".format(prospective_dir))
if __name__ == "__main__":
# parser configuration
......@@ -367,7 +389,8 @@ if __name__ == "__main__":
parser_input_file.add_argument('--steps', type=int, nargs='?', default=10)
parser_input_file.add_argument('--start_prop', nargs='?', default=None)
parser_input_file.add_argument('--inv_prop', nargs='?', default=None)
parser_input_file.add_argument('--output', nargs='?', default='result/')
parser_input_file.add_argument('--output', action=readable_dir, nargs='?',
default='result/')
parser_input_file.set_defaults(func=compute_macs)
......
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