Skip to content
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

Exclude hidden folders when walking through script definitions #697

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

underscoredje
Copy link

Ignore hidden folders when through script definition folders.

Resolved issue: #696

I'm not sure if script definition form page permit to put definitions in a subfolders. My tests seem to show no.
If this is still the case, maybe we should add a path validation in the form to avoir hidden folders.

files = []
# Read config file from within directories too
for _root, _dirs, _files in os.walk(configs_dir, topdown=True):
# In place exlustion of _dirs with exlusion prefixes
_dirs[:] = [_dirs
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work, I'm afraid, since _files are not dependent on _dirs and python will iterate over all nested files anyway.

Basically, you need to use os.path.dirname(name) below to get a file's relative path (it will be ..data in your case) and check, that it doesnt start with '.'

@@ -262,9 +262,17 @@ def load_config_model(self, name, user, parameter_values=None, skip_invalid_para
def _visit_script_configs(self, visitor):
configs_dir = self._script_configs_folder

# We will ignore folders with this prefixes (ie: hidden folders)
exclude_prefixes=('.')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to have a list or tuple of prefixes, you have to use ('.',) (note comma) or ['.'].
But then in the check below, you will have to iterate over prefixes, rather than doing startswith(exclude_prefixes) immediately
I'm fine, if you define just a single string, but please rename the variable then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants