Repository navigation
Generate nameroot and nameext from basename - #420
Conversation
Additionally only generate it for Files, not Directories (following specification). And also generate nameext.
|
Can one of the admins verify this patch? |
|
I'm unsure on what the behaviour should be when only Should it generate the value from |
|
For clarification, right now the code (over)writes both from the calculated values to ensure that there are no inconsistencies between both. |
|
@undu yes, that's correct, the |
| d["basename"] = os.path.basename(urllib.request.url2pathname(path)) | ||
|
|
||
| if d["class"] == "File": | ||
| if "nameroot" or "nameext" not in d: |
There was a problem hiding this comment.
You can replace this with the line from draft2tool.py:
f["nameroot"], f["nameext"] = os.path.splitext(f["basename"])
There was a problem hiding this comment.
Didn't know there was a function that did it out of the box, it's changed now.
There was a problem hiding this comment.
You can also remove the conditional. As mentioned earlier we can set nameroot and nameext unconditionally.
FYI that construction doesn't do what you want:
if "x" or "y" in "abc":
print "yes"
This will always print "yes" because the expression is actually bool("x") or bool("y" in "abc") and non-empty strings are True.
There was a problem hiding this comment.
Thanks for the tip, I removed the condition.
| "basename": "bar.cwl", | ||
| "nameroot": "bar", | ||
| "class": "File", | ||
| "nameext": "cwl", |
There was a problem hiding this comment.
From the spec:
The basename root such that nameroot + nameext == basename, and nameext is empty or begins with a period and contains at most one period. For the purposess of path splitting leading periods on the basename are ignored; a basename of .cshrc will have a nameroot of .cshrc.
So nameext in this example should be .cwl
There was a problem hiding this comment.
All the tests have been changed to conform to os.path.splitext.
| d["basename"] = os.path.basename(urllib.request.url2pathname(path)) | ||
|
|
||
| if d["class"] == "File": | ||
| if "nameroot" or "nameext" not in d: |
There was a problem hiding this comment.
You can also remove the conditional. As mentioned earlier we can set nameroot and nameext unconditionally.
FYI that construction doesn't do what you want:
if "x" or "y" in "abc":
print "yes"
This will always print "yes" because the expression is actually bool("x") or bool("y" in "abc") and non-empty strings are True.
|
Jenkins, test this please |
Here's the cleaner PR to fix #268
Obsoletes #338