Skip to content

Commit

Permalink
Cleanup DirIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
tsileo committed Dec 12, 2013
1 parent df1bf18 commit b6333cc
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*.pyc
*.egg
build/
dist/
*.egg-info/
Expand Down
8 changes: 5 additions & 3 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@
Dirtools Changelog
====================

0.1.1 (not released yet)
========================
0.1.1 (2013-12-12)
==================

- New ``compress_to`` methods for easy gzip compression with tarfile.
- Added patterns support to ``Dir.files`` and ``Dir.subdirs`` methods.
- Now ``Dir.files`` and ``Dir.subdirs`` methods return sorted list.
allowing custom sort options and abspath args that allow to choose between relative/absolute path.
- Added Dir.size method to recursively compute directory size.
- New ``DirState`` and ``compute_diff`` method.
- Now skipping symlinks
- Now skipping symlinks.


0.1.0 (2013-07-01)
==================

- v0.1.0 on pypi.


0.0.0 (2013-06-17)
==================

Expand Down
24 changes: 24 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Dirtools is a little Python package aimed to provide the following features:
* Exclude/ignore files in a directory, using .gitignore like syntax (unix filename pattern matching).
* Generate a hash for a directory tree in order to check if a directory has been modified.
* Search recursively for all subidirs containing a given filename (all projects directory inside a dir).
* Track changes in a directory over time (without duplicating it or without having direct access to it).


.. image:: https://pypip.in/v/dirtools/badge.png
:target: https://crate.io/packages/dirtools
Expand Down Expand Up @@ -101,6 +103,28 @@ Or if you want to do it manually:
tar.add(filename, arcname=arcname, exclude=d.is_excluded)
Track changes in directories
----------------------------

Dirtools provides an helper ``DirIndex`` to help tracking changes in a directory over time, without duplicating it or without having direct access to it.

.. code-block:: python
from dirtools import Dir, DirIndex
d = Dir(path)
dir_index = DirIndex(d)
index_file = dir_index.to_json()
# Later... after some changes
dir_index = DirIndex.from_json(index_file)
dir_index2 = DirIndex(d)
changes = dir_index2 - dir_index
Helpers
-------

Expand Down
3 changes: 2 additions & 1 deletion dirtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ def compress_to(self, archive_path=None):


class DirState(object):
""" Hold a directory state / snapshot meta-data for later comparison. """
def __init__(self, _dir=None, state=None, index_cmp=os.path.getmtime):
self._dir = _dir
self.index_cmp = index_cmp
Expand All @@ -336,7 +337,7 @@ def index(self):
def __sub__(self, other):
""" Compute diff with operator overloading.
>>> path =DirState(Dir('/path'))
>>> path = DirState(Dir('/path'))
>>> path_copy = DirState(Dir('/path_copy'))
>>> diff = path_copy - path
>>> # Equals to
Expand Down

0 comments on commit b6333cc

Please sign in to comment.