GenPath Tool Cleanup Pull Request - #23
Conversation
…e were just for my benefit but might be handy for others
…stituted variable values. Command now uses evalin to get variable values from caller environment.
…use errordlg, even though this isn't quite yet a standard and is being discussed in issue #11
…r a number of old scripts that still call the outmoded GeneratePathCommand.m in an eval wrapper
This should fix #22
|
PS if we do accept this pull request, some of the template scripts may need to be rewritten so that they directly call GeneratePath rather than the older, now unsupported eval-ed GeneratePathCommand approach. That will merit opening another issue, but I'll hold off on that until the pull request gets accepted. |
|
@mangstad and @sripada @shijiaguo @dankessler What happened to pizza=1? That was a critical piece of code! Please put that back. Seriously, this is awesome!! Love the new code. I definitely sign off on it. One perhaps small issue: I thought you were going to makedir recursively. Looks like the current one will fail if you try to make a directory inside a directory that itself needs to be made. |
There was a problem hiding this comment.
Actually, @sripada, pizza=1 does still exist :) It just moved :P
|
@sripada More seriously though, in testing, mkdir will work recursively, regardless of whether you specify a path relative to pwd, or an absolute path. The only time it fails, and unfortunately with a kind of ugly message, if is you to try to mkdir into a path that you don't have write rights, to. However, I'll add a commit that puts the mkdir in a try catch block so that if it fails, the user will get a more informative error dialog than seeing "path doesn't exist" or something blah like that. |
|
Yeah, I didn't realize this -- mostly due to the different nature of the default mkdir behavior in bash -- but mkdir in matlab does work recursively so should only fail if the user running the script doesn't have permission to some part of the path being created. Though I agree a more helpful error message would be appropriate. |
…y at fix #22 inspired by @sripada
There was a problem hiding this comment.
I guess I could've put the comment at the bottom of the code I wanted you to check so that you could see it in the discussion panel. Instead, just click on the "view full changes" at the top right of this little element, and you'll zip to the lines in question.
There was a problem hiding this comment.
This exist will only try to create templatepath if it already exists as a file or directory, which doesn't seem to be the desired behavior.
There was a problem hiding this comment.
Another good catch. That should be ==0, not ~=0. Fixing it now.
There was a problem hiding this comment.
Ok, this is fixed now, though in editing it I destroyed our commentary in the diff, but this mini commentary appears to still be live.
There was a problem hiding this comment.
Also, we need to make sure that if there is no file at the end of OutputTemplate, that it ends in a /, otherwise fileparts will give you undesired behavior.
For example, fileparts('/root/directory/') will correctly give you /root/directory/ for templatepath and an empty string for templatename, but fileparts('/root/directory') will give you /root/ for templatepath and directory for templatename.
There was a problem hiding this comment.
Ok, I'll think about that and write a correction that will go through a sequence of checking if OutputTemplate is itself a directory, and only if not, passing templatename to mkdir.
There was also a problem with the check if path exists routine, as the logic was flipped there, too, in that you only want to trigger an error if it doesn't exist, e.g. == 0. That's already fixed, though.
There was a problem hiding this comment.
Ok, so I've been thinking about this, and it's more of a usage issue. These are going to be called by the centralscripts, not the templates, so it's more a matter of enforcement for the developers, not end-users.
If somebody specifies 'make' mode, they presumably are about to make a write operation. The path that GeneratePath returns may be either
- A path to an actual filename that they plan to write out
- A path to a directory that they're then going to write into, presumably using hardcoded or standardized filenames
Presumably if they are running in 'make' mode, in all likelihood, OutputTemplate points to something that doesn't exist. It's pretty hard for GeneratePath to know whether that thing that doesn't exist ought to be a directory or the file itself, in which case it needs to make a parent.
It may be easier to split this up into two modes, so that the call has to directly specify what it wants to happen.
- makedir mode would make a directory with EXACTLY the same name as what genpath returns, so improper usage could result in a directory called rarun_01.nii
- makeparentdir mode, which would always strip off the end of the path with fileparts, and make the parent directory.
It'd then be up to the developer who is calling GeneratePath to specify which mode they want to run in, rather than up to GeneratePath to try to read the mind of whoever is calling it.
…o make a directory if it does not already exist.
There was a problem hiding this comment.
Is there a typo here. Should be OutputTemplate. Same problem in line 97. Or I could be missing something....
There was a problem hiding this comment.
Nice catch @sripada. I tested the function, but not the make and check options, which I'm doing now and just caught those errors. Sorry to have to go through so many iterations with you and @mangstad, but I appreciate the feedback. Another commit in a couple minutes should fix all these open issues.
…will make a parent directory of a file specified by the template, the other will make literally whatever the template says. Also updated help at top of function to reflect this.
There was a problem hiding this comment.
@dankessler , @mangstad
maybe say '... problem writing this file: %s ...'
There was a problem hiding this comment.
Ok, I have updated this to say "problem writing this file/directory" because sometimes you might be trying to make a directory with this. Commits on their way.
|
I love it! I made a few comments on the error messages. If you want to go really gung ho, here is one more suggestion: Of note, the Try needs to be skipped if the template contains a wildcard, i.e., * On second thought, this may be getting overly complicated. I will leave this up to you guys if you think there is merit in this idea. |
|
Actually, the GeneratePath script doesn't need to Try anything. It just needs to check if the expected file type argument is at the end of the OutputTemplate, and if not, then it needs to append it. This may be worth doing as it is a frequent error that is easily correctable. |
|
Hey @dankessler could you give me a quick rundown of how I can pull your copy of this into my local repo so I can just run a few quick tests also? I swear eventually I'll get the hang of the git stuff. |
|
Sure: git remote add dankessler git@github.com:dankessler/MethodsCore #This will add my repository as a remote You could also fetch ALL of my branches (as remote tracking branch) using... |
…e are any complete brackets to expand
|
Alright, I've mapped out the logic and all the switches on a whiteboard, and I think I finally have consistent behavior. Here is the sequence of processing. I've tried to take into account all kinds of bizarre edge cases.
So the logical precedence is as follows: syntax for this list is -option1- disables -option2- type > suffix and I think that's it. |
…bracket expansion), and clear suffix if dircheck is enabled
…sable make mode if otherwise enabled
…er now and this is not necessary
|
Alright, just added a billion tiny commits that @mangstad can use for testing. Unfortunately I have not had time to test yet...but all I did was move stuff around so hopefully nothing got too broken. If I don't hear back, I'll test tomorrow AM and merge the pull if nobody complains. |
|
I'm assuming you're going to merge this pull request tomorrow. I'd like to then merge the master to my local repository, and do a rebase on som_batch so that I can use the GenPath command. Would the following be correct: git merge universe That should then give me access to the Genpath stuff right (assuming I execute it after the pull request has resolved)? |
|
That's a good idea, but the semantics for what you're doing is a little different than how you laid it out. You'd presumably do the follow
commands for this are git fetch universe
git checkout develop
git merge universe/develop
git checkout som_batch
git rebase develop |
|
Also yes, this should get pulled today. Have you had a chance to test the final commit @mangstad ? |
|
Alright, I think it's time to go live with this. I've done a bunch more testing and everything seems fine to me. Unfortunately, I haven't tested every combination of options and wildcard locations (I multiplied out and it's like 800+ possible configurations), but I think it's ready to go so I'm going to merge the pull request. As we roll out additional features we might find bugs or want to change the usage for this, and that's fine, but I think this is good enough to roll onto the develop branch. |
…istent behavior Should fix #22
After long discussion, I'm now rolling out mc_GenPath.m I expect this to be called by many other functions, so if there are any lurking bugs, I guess we'll find them then. Yay team!
This represents some work on the GeneratePath "toolbox".
This should close #22.
It'd be great if @mangstad and @sripada could sign off on this. Once it's integrated, @shijiaguo may want to rebase her dcmbatch work related to #14 to take advantage of the GeneratePath tools.