Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
FSL
fslpy
Commits
eee2c366
Commit
eee2c366
authored
May 02, 2019
by
Michiel Cottaar
Browse files
BUG: check invalid characters in the FileTree
Also made small fixes to trees that contained invalid characters
parent
e8f0a5ad
Changes
3
Hide whitespace changes
Inline
Side-by-side
fsl/utils/filetree/parse.py
View file @
eee2c366
...
...
@@ -38,6 +38,21 @@ def list_all_trees() -> List[str]:
return
trees
def
check_forbidden_characters
(
text
,
characters
,
text_type
):
"""
Checks the text for forbidden characters
raises ValueError if one is found
:param text: string with the text
:param characters: sequence of forbidden characters
:param text_type: type of the text to raise in error message
"""
bad
=
[
character
for
character
in
characters
if
character
in
text
]
if
len
(
bad
)
>
0
:
raise
ValueError
(
f
'Invalid character(s) "
{
""
.
join
(
bad
)
}
" in
{
text_type
}
:
{
text
}
'
)
def
read_line
(
line
:
str
)
->
Tuple
[
int
,
PurePath
,
str
]:
"""
Parses line from the tree file
...
...
@@ -54,11 +69,14 @@ def read_line(line: str) -> Tuple[int, PurePath, str]:
match
=
re
.
match
(
r
'^(\s*)(\S*)\s*\((\S*)\)\s*$'
,
line
)
if
match
is
not
None
:
gr
=
match
.
groups
()
check_forbidden_characters
(
gr
[
1
],
r
'<>"/\|?*'
,
'file or directory name'
)
check_forbidden_characters
(
gr
[
2
],
r
'(){}/'
,
'short name'
)
return
len
(
gr
[
0
]),
PurePath
(
gr
[
1
]),
gr
[
2
]
match
=
re
.
match
(
r
'^(\s*)(\S*)\s*$'
,
line
)
if
match
is
not
None
:
gr
=
match
.
groups
()
short_name
=
gr
[
1
].
split
(
'.'
)[
0
]
check_forbidden_characters
(
gr
[
1
],
r
'<>"/\|?*'
,
'file or directory name'
)
return
len
(
gr
[
0
]),
PurePath
(
gr
[
1
]),
short_name
raise
ValueError
(
'Unrecognized line %s'
%
line
)
...
...
@@ -79,6 +97,8 @@ def read_subtree_line(line: str, directory: str) -> Tuple[int, "filetree.FileTre
if
match
is
None
:
raise
ValueError
(
"Sub-tree line could not be parsed: {}"
.
format
(
line
.
strip
()))
spaces
,
type_name
,
variables_str
,
short_name
=
match
.
groups
()
check_forbidden_characters
(
type_name
,
r
'<>:"/\|?*'
,
'sub-tree name'
)
check_forbidden_characters
(
short_name
,
r
'(){}/'
,
'sub-tree name'
)
variables
=
{}
if
len
(
variables_str
.
strip
())
!=
0
:
...
...
fsl/utils/filetree/trees/HCP_Surface.tree
View file @
eee2c366
...
...
@@ -27,6 +27,6 @@
{subject}.sulc_MSMAll.{space}.dscalar.nii (sulc_msm_cifti)
{subject}.thickness_MSMAll.{space}.dscalar.nii (thick_msm_cifti)
{subject}.curvature_MSMAll.{space}.dscalar.nii (curv_msm_cifti)
{subject}.BA.32k_fs_LR.dlabel.nii (BA_cifti)
)
{subject}.BA.32k_fs_LR.dlabel.nii (BA_cifti)
{subject}.aparc.32k_fs_LR.dlabel.nii (aparc_cifti)
{subject}.aparc.a2009s.32k_fs_LR.dlabel.nii (aparc2009_cifti)
fsl/utils/filetree/trees/freesurfer.tree
View file @
eee2c366
...
...
@@ -67,10 +67,10 @@
aparc.a2009s+aseg.mgz (aparc_a2009s_aseg)
aseg.mgz
label
/
label
{hemi}h.aparc.annot (aparc.annot)
stats
/
stats
aseg.stats (aseg_stats)
wmparc.stats (wmparc_stats)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment