Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F9344810
utils.py
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
utils.py
View Options
# Copyright (C) 2017 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
os
import
shutil
import
tempfile
from
subprocess
import
call
def
init_git_repo_from_archive
(
project_name
,
archive_path
,
root_temp_dir
=
'/tmp'
):
"""Given a path to an archive containing a git repository.
Uncompress that archive to a temporary location and returns the path.
If any problem whatsoever is raised, clean up the temporary location.
Args:
project_name (str): Project's name
archive_path (str): Full path to the archive
root_temp_dir (str): Optional temporary directory mount point
(default to /tmp)
Returns
A tuple:
- temporary folder: containing the mounted repository
- repo_path, path to the mounted repository inside the temporary folder
Raises
ValueError in case of failure to run the command to uncompress
"""
temp_dir
=
tempfile
.
mkdtemp
(
suffix
=
'.swh.loader.git'
,
prefix
=
'tmp.'
,
dir
=
root_temp_dir
)
try
:
# create the repository that will be loaded with the dump
r
=
call
([
'unzip'
,
'-q'
,
'-o'
,
archive_path
,
'-d'
,
temp_dir
])
if
r
!=
0
:
raise
ValueError
(
'Failed to uncompress archive
%s
'
%
archive_path
)
repo_path
=
os
.
path
.
join
(
temp_dir
,
project_name
)
return
temp_dir
,
repo_path
except
Exception
as
e
:
shutil
.
rmtree
(
temp_dir
)
raise
e
File Metadata
Details
Attached
Mime Type
text/x-python
Expires
Fri, Jul 4, 2:49 PM (4 d, 6 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3292215
Attached To
rDLDG Git loader
Event Timeline
Log In to Comment