GitXplorerGitXplorer
s

generate-globs

public
3 stars
1 forks
0 issues

Commits

List of commits on branch master.
Verified
785667a9c23662634fad38e40c78c7fe251d6aac

improved syntax highlighing

ssebastian-philipp committed 7 years ago
Unverified
d7d578f402bab1c6ddbe96585298fbbcb2b386ce

readme

ssebastian-philipp committed 7 years ago
Unverified
5e1e0450e851d5f4188128ed2e2debd4328b77b5

Readme

ssebastian-philipp committed 7 years ago
Unverified
0fd10c945aa6af322d6e2e3471e147c26f3c93da

Added tests, readme and license

ssebastian-philipp committed 7 years ago

README

The README file for this repository.

Generate Globs

Generate glob expressions by example.

Usage

Generate a list of globs that match all elements of whitelist and none of blacklist.

>>> import fnmatch
>>> # whitelist, blacklist = [], []
>>> globs = generate_globs(whitelist, blacklist)

generate_globs generates globs that fulfill both assertions:

>>> assert all([any([fnmatch.filter([white], glob) for glob in globs]) for white in whitelist])
>>> assert not any([fnmatch.filter(blacklist, glob) for glob in globs])

For example:

>>> generate_globs(whitelist=['data1', 'data2', 'data3'], blacklist=['admin']) 
{['data*']}

>>> generate_globs(whitelist=['a', 'b', 'c'], blacklist=['d']) 
{['[a-c]']}

Returns an empty list, if whitelist is empty.

Limitation

Generating good globs for arbitrary input is hard, thus only expect decent globs for "friendly" input. Also, don't use it for user input.

Running the tests

py.test -v  test_generate_globs.py