Index: swh/model/cli.py =================================================================== --- swh/model/cli.py +++ swh/model/cli.py @@ -52,11 +52,14 @@ return swhid(CONTENT, object) -def swhid_of_dir(path): - from swh.model.from_disk import Directory +def swhid_of_dir(path, ignored_dirs): + from swh.model.from_disk import Directory, ignore_named_directories from swh.model.identifiers import DIRECTORY, swhid - object = Directory.from_disk(path=path).get_data() + names = [name.encode(sys.getfilesystemencoding()) for name in ignored_dirs] + dir_filter = ignore_named_directories(names) + + object = Directory.from_disk(path=path, dir_filter=dir_filter).get_data() return swhid(DIRECTORY, object) @@ -96,7 +99,7 @@ return str(SWHID(object_type="snapshot", object_id=snapshot_identifier(snapshot))) -def identify_object(obj_type, follow_symlinks, obj): +def identify_object(obj_type, follow_symlinks, ignored_directory_names, obj): from urllib.parse import urlparse if obj_type == "auto": @@ -125,7 +128,7 @@ if obj_type == "content": swhid = swhid_of_file(path) elif obj_type == "directory": - swhid = swhid_of_dir(path) + swhid = swhid_of_dir(path, ignored_directory_names) elif obj_type == "origin": swhid = swhid_of_origin(obj) elif obj_type == "snapshot": @@ -160,6 +163,13 @@ type=click.Choice(["auto", "content", "directory", "origin", "snapshot"]), help="type of object to identify (default: auto)", ) +@click.option( + "--ignore-dir", + "ignored_dirs", + multiple=True, + metavar="NAME", + help="ignore directories by name (can be repeated, does not support globing)", +) @click.option( "--verify", "-v", @@ -168,7 +178,7 @@ help="reference identifier to be compared with computed one", ) @click.argument("objects", nargs=-1, required=True) -def identify(obj_type, verify, show_filename, follow_symlinks, objects): +def identify(obj_type, verify, show_filename, follow_symlinks, objects, ignored_dirs): """Compute the Software Heritage persistent identifier (SWHID) for the given source code object(s). @@ -203,7 +213,9 @@ if verify and len(objects) != 1: raise click.BadParameter("verification requires a single object") - results = map(partial(identify_object, obj_type, follow_symlinks), objects) + results = map( + partial(identify_object, obj_type, follow_symlinks, ignored_dirs), objects, + ) if verify: swhid = next(results)[1]