Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F7450565
swh-objstorage-add-dir
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-objstorage-add-dir
View Options
#!/usr/bin/python3
# Copyright (C) 2015 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
import
logging
import
os
import
sys
from
swh.storage
import
objstorage
if
__name__
==
'__main__'
:
try
:
root_dir
=
sys
.
argv
[
1
]
dirname
=
sys
.
argv
[
2
]
except
IndexError
:
print
(
"Usage: swh-objstorage-add-dir OBJ_STORAGE_DIR DATA_DIR"
)
sys
.
exit
(
1
)
logging
.
basicConfig
(
level
=
logging
.
INFO
)
objs
=
objstorage
.
ObjStorage
(
root_dir
)
dups
=
0
for
root
,
_dirs
,
files
in
os
.
walk
(
dirname
):
for
name
in
files
:
path
=
os
.
path
.
join
(
root
,
name
)
with
open
(
path
,
'rb'
)
as
f
:
try
:
objs
.
add_file
(
f
,
length
=
os
.
path
.
getsize
(
path
))
except
objstorage
.
DuplicateObjError
:
dups
+=
1
if
dups
:
logging
.
info
(
'skipped
%d
duplicate(s) file(s)'
%
dups
)
File Metadata
Details
Attached
Mime Type
text/x-python
Expires
Thu, Apr 17, 7:55 AM (5 d, 5 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3265773
Attached To
rDSTOC swh-storage-cassandra
Event Timeline
Log In to Comment