Skip to content

Commit

Permalink
Now skips symlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
tsileo committed Dec 2, 2013
1 parent 75e4930 commit df1bf18
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
- 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

0.1.0 (2013-07-01)
==================
Expand Down
9 changes: 5 additions & 4 deletions dirtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,12 @@ def walk(self):
for d in list(dirs):
if self.is_excluded(os.path.join(root, d)):
dirs.remove(d)
else:
elif not os.path.islink(os.path.join(root, d)):
ndirs.append(d)

nfiles = []
for fpath in (os.path.join(root, f) for f in files):
if not self.is_excluded(fpath):
if not self.is_excluded(fpath) and not os.path.islink(fpath):
nfiles.append(os.path.relpath(fpath, root))

yield root, ndirs, nfiles
Expand Down Expand Up @@ -354,11 +354,12 @@ def to_json(self, base_path='.', dt=None, fmt=None):
dt = datetime.utcnow()
path = fmt.format(self._dir.path.strip('/').split('/')[-1],
dt.isoformat())
path = os.path.join(base_path, path)

with open(os.path.join(base_path, path), 'wb') as f:
with open(path, 'wb') as f:
f.write(json.dumps(self.state))

return os.path.abspath(path)
return path

@classmethod
def from_json(cls, path):
Expand Down

0 comments on commit df1bf18

Please sign in to comment.