Skip to content

Commit

Permalink
Removing find and pathfind methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
jkeyes committed Dec 7, 2019
1 parent 0661b05 commit b33780f
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 235 deletions.
71 changes: 31 additions & 40 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,73 +1,64 @@
.. :changelog:
Changelog
=========

History
-------
0.6.0
+++++
* removed deprecated find and pathfind functions

0.5.4
+++++

- Silly error in MANIFEST.in resolved.
* resolving security alert regarding the version of jinja2

0.5.3
+++++

- do not `chdir` in `walk_and_filter_generator`. `#3 <https://github.com/jkeyes/pathfinder/pull/3>`_. (https://github.com/rubik)
* do not `chdir` in `walk_and_filter_generator`. `#3 <https://github.com/jkeyes/pathfinder/pull/3>`_. (https://github.com/rubik)

0.5.2
+++++

- Silly error in MANIFEST.in resolved.
* Silly error in MANIFEST.in resolved.

0.5.1
+++++

- Added README.rst to MANIFEST.in to prevent install error from pip.
* Added README.rst to MANIFEST.in to prevent install error from pip.

0.5
+++

- find_paths function added which returns a generator
- use all in AndFilter and any in OrFilter
* new find_paths function returns a generator
* using any and all in OrFiter and AndFilter

0.4.1
+++++

- Fixed install error in setup.py
* Fixed install error in setup.py

0.4
+++

- File size filter
- Image filter
- Image dimensions filter
- Color image filter
- Greyscale image filter
- moved code to pathfinder package
- use nose for testing
- changed license from BSD to MIT
- override __or__ and __and__ for easy compound filter creation
- new Filter.find method
- ignore now works for filepaths

* File size filter
* Image filter
* Image dimensions filter
* Color image filter
* Greyscale image filter
* moved code to pathfinder package
* use nose for testing
* changed license from BSD to MIT
* override __or__ and __and__ for easy compound filter creation
* new Filter.find method
* ignore now works for filepaths

0.3.1
+++++

- Removed hard-coded file separators
- Added docstrings and comments

* Removed hard-coded file separators
* Added docstrings and comments

0.3
+++

- Added depth parameter to walk_and_filter
* Added depth parameter to walk_and_filter

0.2
+++
- Added setup.py
- Fixed bug in NotFilter
- Tided pathfind function.
* Added setup.py
* Fixed bug in NotFilter
* Tided pathfind function.

0.1
0.1
+++
- First Cut
* First Cut
9 changes: 1 addition & 8 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
The MIT License (MIT)
Copyright © 2013 John Keyes <john@keyes.ie>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
MIT License: https://jkeyes.mit-license.org/
62 changes: 1 addition & 61 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,61 +1 @@
=========
Changelog
=========

0.5.4
+++++
* resolving security alert regarding the version of jinja2

0.5.3
+++++
* do not `chdir` in `walk_and_filter_generator`. `#3 <https://github.com/jkeyes/pathfinder/pull/3>`_. (https://github.com/rubik)

0.5.2
+++++
* Silly error in MANIFEST.in resolved.

0.5.1
+++++
* Added README.rst to MANIFEST.in to prevent install error from pip.

0.5
+++
* new find_paths function returns a generator
* using any and all in OrFiter and AndFilter

0.4.1
+++++
* Fixed install error in setup.py

0.4
+++
* File size filter
* Image filter
* Image dimensions filter
* Color image filter
* Greyscale image filter
* moved code to pathfinder package
* use nose for testing
* changed license from BSD to MIT
* override __or__ and __and__ for easy compound filter creation
* new Filter.find method
* ignore now works for filepaths

0.3.1
+++++
* Removed hard-coded file separators
* Added docstrings and comments

0.3
+++
* Added depth parameter to walk_and_filter

0.2
+++
* Added setup.py
* Fixed bug in NotFilter
* Tided pathfind function.

0.1
+++
* First Cut
.. include:: ../HISTORY.rst
43 changes: 21 additions & 22 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
api
changelog

==========
pathfinder
==========

pathfinder is `os.walk` for humans.
pathfinder – a simpler `os.walk`

Installation
============
Expand All @@ -34,23 +33,23 @@ Basic find

::

from pathfinder import find
from pathfinder import find_paths

# all files and directories
paths = find(".")
paths = find_paths(".")

# all files
paths = find(".", just_files=True)
paths = find_paths(".", just_files=True)

# all directories
paths = find(".", just_dirs=True)
paths = find_paths(".", just_dirs=True)

By default `find` prepends the path you search for to the results.
By default `find_paths` prepends the path you search for to the results.
If you want you can ensure the results only contain absolute paths:

::

paths = find(".", abspath=True)
paths = find_paths(".", abspath=True)

Filtering the results
---------------------
Expand All @@ -64,18 +63,18 @@ the `Unix shell-style pattern <http://docs.python.org/library/fnmatch.html>`_ ap
::

# all PDF files
paths = find(".", fnmatch="*.pdf")
paths = find_paths(".", fnmatch="*.pdf")

fnmatching provides some power, but for more flexibility lets
have a look at the regular expression support:

::

# all PDF files
paths = find(".", regex=".*\.pdf")
paths = find_paths(".", regex=".*\.pdf")

# all PDF files with four letter base names
paths = find(pwd, regex=".*/.{4}\.pdf")
paths = find_paths(pwd, regex=".*/.{4}\.pdf")

pathfinder provides the ability to ignore certain paths too:

Expand All @@ -85,11 +84,11 @@ pathfinder provides the ability to ignore certain paths too:
# from the files with three character extensions
from pathfinder import FnmatchFilter
ignore = FnmatchFilter("*.pdf")
find(".", regex=".*/.*\..{3}$", ignore=ignore)
find_paths(".", regex=".*/.*\..{3}$", ignore=ignore)

# ignore all files and directories that begin with .
ignore = RegexFilter("\..*")
find(".", ignore=ignore)
find_paths(".", ignore=ignore)

Controlling the depth of the search
-----------------------------------
Expand All @@ -99,7 +98,7 @@ You may want to limit how to deep to search into a directory tree:
::

# only search down two levels
find(".", depth=2)
find_paths(".", depth=2)

Extra support for images
------------------------
Expand All @@ -110,7 +109,7 @@ Let's find some images in the directory:

# all of the images
from pathfinder import ImageFilter
find(".", filter=ImageFilter())
find_paths(".", filter=ImageFilter())

That is just a shortcut for matching multiple file extensions,
but we can also filter the results based on the dimensions of the
Expand All @@ -120,23 +119,23 @@ image:

# only images less than 20 pixels tall
from pathfinder import ImageDimensionFilter
find(".", filter=ImageDimensionFilter(max_height=20))
find_paths(".", filter=ImageDimensionFilter(max_height=20))

# only images less than 10 pixels tall and wide
from pathfinder import ImageDimensionFilter
find(".", filter=ImageDimensionFilter(max_height=10, min_height=10))
find_paths(".", filter=ImageDimensionFilter(max_height=10, min_height=10))

And we can also search for images based on their color paletter:

::

# only color images
from pathfinder import ColorImageFilter
find(".", filter=ColorImageFilter())
find_paths(".", filter=ColorImageFilter())

# only greyscale images
from pathfinder import GreyscaleImageFilter
find(".", filter=GreyscaleImageFilter())
find_paths(".", filter=GreyscaleImageFilter())

Combining filters
-----------------
Expand All @@ -152,21 +151,21 @@ functions.
from pathfinder import SizeFilter
color = ColorImageFilter()
size = SizeFilter(max_bytes=400)
find(".", filter=color & size)
find_paths(".", filter=color & size)

# pdf OR txt files
from pathfinder import FnmatchFilter
txt = FnmatchFilter("*.txt")
pdf = FnmatchFilter("*.pdf")
find(".", filter=txt | pdf)
find_paths(".", filter=txt | pdf)

# txt files, but NOT ones begining with a
from pathfinder import NotFilter
from pathfinder import SizeFilter
from pathfinder import FnmatchFilter
txt = FnmatchFilter("*.txt")
afiles = NotFilter(FnmatchFilter("*/a*"))
find(".", filter=txt & afiles)
find_paths(".", filter=txt & afiles)

find shortcut
-------------
Expand Down
18 changes: 9 additions & 9 deletions example.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from pathfinder import find
from pathfinder import find_paths

# get all directories and sub-directories in current directory
paths = find(".", just_dirs=True)
paths = find_paths(".", just_dirs=True)

# get all files in the current directory and all sub-directories
paths = find(".", just_files=True)
paths = find_paths(".", just_files=True)

# get all jpg files using a regex
paths = find(".", regex=r".*\.jpg$")
paths = find_paths(".", regex=r".*\.jpg$")

# get all jpg files using posix wildcards
paths = find(".", fnmatch="*.jpg")
paths = find_paths(".", fnmatch="*.jpg")

# get all jpg files and png files
from pathfinder import FnmatchFilter
Expand All @@ -20,15 +20,15 @@
png_filter = FnmatchFilter("*.png")
gif_filter = FnmatchFilter("*.gif")
image_filter = OrFilter(jpg_filter, png_filter, gif_filter)
paths = find(".", filter=image_filter)
paths = find_paths(".", filter=image_filter)

# shortcut using bitwise or
paths = find(".", filter=jpg_filter | png_filter | gif_filter)
paths = find_paths(".", filter=jpg_filter | png_filter | gif_filter)

# even shorter using ImageFilter to find all images
from pathfinder import ImageFilter

paths = find(".", filter=ImageFilter())
paths = find_paths(".", filter=ImageFilter())

# and an even shorter way
paths = ImageFilter().find(".")
paths = ImageFilter().find_paths(".")

0 comments on commit b33780f

Please sign in to comment.