Index: swh/model/cli.py =================================================================== --- swh/model/cli.py +++ swh/model/cli.py @@ -52,11 +52,16 @@ return swhid(CONTENT, object) -def swhid_of_dir(path): - from swh.model.from_disk import Directory +def swhid_of_dir(path, ignored_directory_names): + 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_directory_names + ] + dir_filter = ignore_named_directories(names) + + object = Directory.from_disk(path=path, dir_filter=dir_filter).get_data() return swhid(DIRECTORY, object) @@ -96,7 +101,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 +130,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 +165,13 @@ type=click.Choice(["auto", "content", "directory", "origin", "snapshot"]), help="type of object to identify (default: auto)", ) +@click.option( + "--ignore-named-directory", + "ignored_directory_names", + multiple=True, + metavar="NAME", + help="directory name to ignore", +) @click.option( "--verify", "-v", @@ -168,7 +180,9 @@ 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_directory_names +): """Compute the Software Heritage persistent identifier (SWHID) for the given source code object(s). @@ -203,7 +217,10 @@ 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_directory_names), + objects, + ) if verify: swhid = next(results)[1]