Skip to content

ENH nipype_display_crash defaults to last created pkl file #1619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion bin/nipype_display_crash
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,17 @@ nipype_display_crash crashfile.pklz -r -i

"""

import re
import glob
import os.path as op

def display_crash_files(crashfile, rerun, debug, directory):
"""display crash file content and rerun if required"""

from nipype.utils.filemanip import loadcrash

crashfile = crashfile if crashfile else get_latest_crashfile(directory)

crash_data = loadcrash(crashfile)
node = None
if 'node' in crash_data:
Expand Down Expand Up @@ -52,13 +59,24 @@ def display_crash_files(crashfile, rerun, debug, directory):
raise
print("\n")

def get_latest_crashfile(directory):
directory = directory if directory else "."
print("No crashfile specified. Defaulting to latest crashfile in %s" % directory)

crash_files = glob.glob(op.join(directory, '*.pkl*'))
crash_files.sort(key=lambda file_: op.getctime(op.join(directory, file_)))
latest_file = crash_files[-1]

print("Found latest file %s" % latest_file)
return latest_file

if __name__ == "__main__":
from argparse import ArgumentParser, RawTextHelpFormatter
defstr = ' (default %(default)s)'
parser = ArgumentParser(prog='nipype_display_crash',
description=__doc__,
formatter_class=RawTextHelpFormatter)
parser.add_argument('crashfile', metavar='f', type=str,
parser.add_argument('crashfile', metavar='f', type=str, nargs='?',
help='crash file to display')
parser.add_argument('-r','--rerun', dest='rerun',
default=False, action="store_true",
Expand Down