Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Evan Edmond
fslpy
Commits
3a689377
Commit
3a689377
authored
7 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
New settings function to list all files
parent
7577eb0c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
fsl/utils/settings.py
+29
-2
29 additions, 2 deletions
fsl/utils/settings.py
with
29 additions
and
2 deletions
fsl/utils/settings.py
+
29
−
2
View file @
3a689377
...
...
@@ -19,6 +19,7 @@ the following functions can be called at the module-level:
Settings.readFile
Settings.writeFile
Settings.deleteFile
Settings.listFiles
Settings.readAll
Settings.clear
...
...
@@ -81,6 +82,7 @@ def initialise(*args, **kwargs):
mod
.
writeFile
=
settings
.
writeFile
mod
.
deleteFile
=
settings
.
deleteFile
mod
.
readAll
=
settings
.
readAll
mod
.
listFiles
=
settings
.
listFiles
mod
.
clear
=
settings
.
clear
...
...
@@ -100,6 +102,8 @@ def deleteFile(*args, **kwargs):
pass
def
readAll
(
*
args
,
**
kwarg
):
return
{}
def
listFiles
(
*
args
,
**
kwarg
):
return
[]
def
clear
(
*
args
,
**
kwarg
):
pass
...
...
@@ -224,6 +228,28 @@ class Settings(object):
return
dict
(
zip
(
keys
,
vals
))
def
listFiles
(
self
,
pattern
=
None
):
"""
Returns a list of all stored settings files which match the given
glob-style pattern. If a pattern is not given, all files are returned.
"""
allFiles
=
[]
if
pattern
is
not
None
:
pattern
=
self
.
__fixPath
(
pattern
)
for
dirpath
,
dirnames
,
filenames
in
os
.
walk
(
self
.
__configDir
):
dirpath
=
op
.
relpath
(
dirpath
,
self
.
__configDir
)
filenames
=
[
op
.
join
(
dirpath
,
fn
)
for
fn
in
filenames
]
if
pattern
is
None
:
allFiles
.
extend
(
filenames
)
else
:
allFiles
.
extend
(
fnmatch
.
filter
(
filenames
,
pattern
))
return
allFiles
def
clear
(
self
):
"""
Delete all configuration settings and files.
"""
...
...
@@ -241,8 +267,9 @@ class Settings(object):
def
__fixPath
(
self
,
path
):
"""
Ensures that the given path (passed into :meth:`readFile`,
:meth:`writeFile`, or :meth:`deleteFile`) is cross-platform
compatible.
:meth:`writeFile`, or :meth:`deleteFile`) is cross-platform
compatible. Only works for paths which use ``
'
/
'
`` as the path
separator.
"""
return
op
.
join
(
*
path
.
split
(
'
/
'
))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment