Page MenuHomeSoftware Heritage

No OneTemporary

diff --git a/bin/hashtree.py b/bin/hashtree.py
index 6d531c5..afa0a59 100755
--- a/bin/hashtree.py
+++ b/bin/hashtree.py
@@ -1,61 +1,72 @@
#!/usr/bin/env python3
# Use sample:
-# hashtree.py --path . --ignore '.svn' --ignore '.git-svn'
+# hashtree.py --path . --ignore '.svn' --ignore '.git-svn' \
+# --ignore-empty-folders
# 38f8d2c3a951f6b94007896d0981077e48bbd702
import click
import os
from swh.model import git
from swh.core import hashutil
@click.command()
@click.option('--path', default='.',
help='Optional path to hash.')
-@click.option('--ignore-empty-folder', is_flag=True,
+@click.option('--ignore-empty-folder', is_flag=True, default=False,
help='Ignore empty folder.')
@click.option('--ignore', multiple=True,
help='Ignore pattern.')
-def hashtree(path, ignore_empty_folder=False, ignore=None):
+def hashtree(path, ignore_empty_folder, ignore=None):
+ if os.path.exists(path):
+ if not os.path.isdir(path):
+ print('%s should be a directory!' % path)
+ return
+ else:
+ print('%s should exist!' % path)
+ return
+
if isinstance(path, str):
path = path.encode('utf-8')
if ignore:
patterns = []
for exc in ignore:
patterns.append(exc.encode('utf-8'))
def dir_ok_fn_basic(dirpath, patterns=patterns):
dname = os.path.basename(dirpath)
for pattern_to_ignore in patterns:
if pattern_to_ignore == dname:
return False
if (pattern_to_ignore + b'/') in dirpath:
return False
return True
if ignore_empty_folder:
def dir_ok_fn(dirpath, patterns=patterns):
if not dir_ok_fn_basic(dirpath):
return False
- if os.listdir(dirpath) == []:
- return False
- return True
+ return os.listdir(dirpath) != []
else:
dir_ok_fn = dir_ok_fn_basic
-
- objects = git.walk_and_compute_sha1_from_directory(
- path,
- dir_ok_fn=dir_ok_fn)
else:
- objects = git.walk_and_compute_sha1_from_directory(path)
+ if ignore_empty_folder:
+ def dir_ok_fn(dirpath):
+ return os.listdir(dirpath) != []
+ else:
+ dir_ok_fn = git.default_validation_dir
+
+ objects = git.walk_and_compute_sha1_from_directory_2(
+ path,
+ dir_ok_fn=dir_ok_fn)
- h = objects[git.ROOT_TREE_KEY][0]['sha1_git']
+ h = objects[path]['checksums']['sha1_git']
print(hashutil.hash_to_hex(h))
if __name__ == '__main__':
hashtree()

File Metadata

Mime Type
text/x-diff
Expires
Sat, Jun 21, 7:47 PM (3 w, 21 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3262092

Event Timeline