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

make fnmatch.translate also support globstar and make * non-greedy. #6

Merged
merged 1 commit into from May 9, 2015

Conversation

joolswills
Copy link
Contributor

eg

before:

pattern="/home/*/cache"

would match

/home/user/cache
/home/user/something/cache
/home/suer/something/something/cache

now:

pattern="/home/*/cache"

would match

/home/user/cache
/home/user2/cache

but would not match /home/user/something/cache

pattern="/home/**/cache"

would match

/home/user/cache
/home/user/something/cache
/home/suer/something/something/cache

this brings it in line with the other functions in glob2, and although changes the functionality of a single * - makes it match the behaviour of most shells, and is more intuitive.

before:

pattern="/home/*/cache"

would match

/home/user/cache
/home/user/something/cache
/home/suer/something/something/cache

now:

pattern="/home/*/cache"

would match

/home/user/cache

pattern="/home/**/cache"

would match

/home/user/cache
/home/user/something/cache
/home/suer/something/something/cache

this brings it in line with the other functions in glob2, and although changes the functionality of a single * - makes it
match the behaviour of most shells, and is more intuitive.
@miracle2k miracle2k merged commit 0ee1841 into miracle2k:master May 9, 2015
miracle2k added a commit that referenced this pull request May 9, 2015
…atch.translate also support globstar and make * non-greedy. "
@miracle2k
Copy link
Owner

Seems good, thanks.

@miracle2k
Copy link
Owner

I had to revert this, unfortunately. It causes tests failures, as pointed out by @musically-ut.

I looked at it and it turns out that adding this behaviour to fnmatch like this breaks the glob functionality itself.

The way the glob module is written (probably since the original Python code), it expects fnmatch to allow "*" across / boundaries.

@joolswills
Copy link
Contributor Author

I shame as it would make sense that this function would include the extended glob feature - what about changing the other code to work with it ?

My change was initially so attic backup could use extended globbing as it uses this function, but I guess it could be included as a custom function within the backup software.

@miracle2k
Copy link
Owner

I'm open to it in principle, but rather wary about deviating to far from the standard behaviour.

Indeed, a custom copy of fnmatch might be a perfectly feasable solution.

Another possible idea: Glob2 can actually be subclassed to glob not over the actual filesystem, but over a virtual one. See for example:

https://github.com/miracle2k/django-assets/blob/21ddc81feefcabe73e88cedc2fb91b237abbeb0e/django_assets/env.py#L77

It's possible you could use this somehow to get the full matching functionality.

I'm actually interested in attic (borg?) as a backup tool and so I'd be happy if you can make this work.

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

2 participants