Skip to content
GitLab
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
buildgrid
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Privacy statement
Keyboard shortcuts
?
What's new
6
Snippets
Groups
Projects
Show more breadcrumbs
BuildGrid
buildgrid
Commits
725db807
Commit
725db807
authored
6 years ago
by
Martin Blanchard
Browse files
Options
Downloads
Patches
Plain Diff
utils.py: Remove CAS download helpers
#79
parent
9b787728
No related branches found
No related tags found
Loading
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
buildgrid/utils.py
+0
-81
0 additions, 81 deletions
buildgrid/utils.py
with
0 additions
and
81 deletions
buildgrid/utils.py
+
0
−
81
View file @
725db807
...
...
@@ -18,87 +18,6 @@ import os
from
buildgrid.settings
import
HASH
from
buildgrid._protos.build.bazel.remote.execution.v2
import
remote_execution_pb2
from
buildgrid._protos.google.bytestream
import
bytestream_pb2
def
gen_fetch_blob
(
stub
,
digest
,
instance_name
=
""
):
"""
Generates byte stream from a fetch blob request
"""
resource_name
=
os
.
path
.
join
(
instance_name
,
'
blobs
'
,
digest
.
hash
,
str
(
digest
.
size_bytes
))
request
=
bytestream_pb2
.
ReadRequest
(
resource_name
=
resource_name
,
read_offset
=
0
)
for
response
in
stub
.
Read
(
request
):
yield
response
.
data
def
write_fetch_directory
(
root_directory
,
stub
,
digest
,
instance_name
=
None
):
"""
Locally replicates a directory from CAS.
Args:
root_directory (str): local directory to populate.
stub (): gRPC stub for CAS communication.
digest (Digest): digest for the directory to fetch from CAS.
instance_name (str, optional): farm instance name to query data from.
"""
if
not
os
.
path
.
isabs
(
root_directory
):
root_directory
=
os
.
path
.
abspath
(
root_directory
)
if
not
os
.
path
.
exists
(
root_directory
):
os
.
makedirs
(
root_directory
,
exist_ok
=
True
)
directory
=
parse_to_pb2_from_fetch
(
remote_execution_pb2
.
Directory
(),
stub
,
digest
,
instance_name
)
for
directory_node
in
directory
.
directories
:
child_path
=
os
.
path
.
join
(
root_directory
,
directory_node
.
name
)
write_fetch_directory
(
child_path
,
stub
,
directory_node
.
digest
,
instance_name
)
for
file_node
in
directory
.
files
:
child_path
=
os
.
path
.
join
(
root_directory
,
file_node
.
name
)
with
open
(
child_path
,
'
wb
'
)
as
child_file
:
write_fetch_blob
(
child_file
,
stub
,
file_node
.
digest
,
instance_name
)
for
symlink_node
in
directory
.
symlinks
:
child_path
=
os
.
path
.
join
(
root_directory
,
symlink_node
.
name
)
if
os
.
path
.
isabs
(
symlink_node
.
target
):
continue
# No out of temp-directory links for now.
target_path
=
os
.
path
.
join
(
root_directory
,
symlink_node
.
target
)
os
.
symlink
(
child_path
,
target_path
)
def
write_fetch_blob
(
target_file
,
stub
,
digest
,
instance_name
=
None
):
"""
Extracts a blob from CAS into a local file.
Args:
target_file (str): local file to write.
stub (): gRPC stub for CAS communication.
digest (Digest): digest for the blob to fetch from CAS.
instance_name (str, optional): farm instance name to query data from.
"""
for
stream
in
gen_fetch_blob
(
stub
,
digest
,
instance_name
):
target_file
.
write
(
stream
)
target_file
.
flush
()
assert
digest
.
size_bytes
==
os
.
fstat
(
target_file
.
fileno
()).
st_size
def
parse_to_pb2_from_fetch
(
pb2
,
stub
,
digest
,
instance_name
=
""
):
"""
Fetches stream and parses it into given pb2
"""
stream_bytes
=
b
''
for
stream
in
gen_fetch_blob
(
stub
,
digest
,
instance_name
):
stream_bytes
+=
stream
pb2
.
ParseFromString
(
stream_bytes
)
return
pb2
def
create_digest
(
bytes_to_digest
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment