Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F9313008
swh-hashtree
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
swh-hashtree
View Options
#!/usr/bin/env python3
# Use sample:
# swh-hashtree --path . --ignore '.svn' --ignore '.git-svn' \
# --ignore-empty-folders
# 38f8d2c3a951f6b94007896d0981077e48bbd702
import
os
import
click
from
swh.model
import
from_disk
,
hashutil
def
combine_filters
(
*
filters
):
"""Combine several ignore filters"""
if
len
(
filters
)
==
0
:
return
from_disk
.
accept_all_directories
elif
len
(
filters
)
==
1
:
return
filters
[
0
]
def
combined_filter
(
*
args
,
**
kwargs
):
return
all
(
filter
(
*
args
,
**
kwargs
)
for
filter
in
filters
)
return
combined_filter
@click
.
command
()
@click
.
option
(
"--path"
,
default
=
"."
,
help
=
"Optional path to hash."
)
@click
.
option
(
"--ignore-empty-folder"
,
is_flag
=
True
,
default
=
False
,
help
=
"Ignore empty folder."
)
@click
.
option
(
"--ignore"
,
multiple
=
True
,
help
=
"Ignore pattern."
)
def
main
(
path
,
ignore_empty_folder
=
False
,
ignore
=
None
):
filters
=
[]
if
ignore_empty_folder
:
filters
.
append
(
from_disk
.
ignore_empty_directories
)
if
ignore
:
filters
.
append
(
from_disk
.
ignore_named_directories
([
os
.
fsencode
(
name
)
for
name
in
ignore
])
)
try
:
d
=
from_disk
.
Directory
.
from_disk
(
path
=
os
.
fsencode
(
path
),
dir_filter
=
combine_filters
(
*
filters
)
)
hash
=
d
.
hash
except
Exception
as
e
:
print
(
e
)
return
else
:
print
(
hashutil
.
hash_to_hex
(
hash
))
if
__name__
==
"__main__"
:
main
()
File Metadata
Details
Attached
Mime Type
text/x-python
Expires
Thu, Jul 3, 11:19 AM (1 w, 23 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3240398
Attached To
rDMOD Data model
Event Timeline
Log In to Comment