Skip to content
GitLab
Next
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
4e96eb89
Commit
4e96eb89
authored
6 years ago
by
Martin Blanchard
Browse files
Options
Downloads
Patches
Plain Diff
utils.py: Introduce a CAS browser URL helper
#157
parent
f07c8895
No related branches found
No related tags found
1 merge request
!153
Generate browser URLs for build action
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
buildgrid/settings.py
+8
-0
8 additions, 0 deletions
buildgrid/settings.py
buildgrid/utils.py
+48
-1
48 additions, 1 deletion
buildgrid/utils.py
with
56 additions
and
1 deletion
buildgrid/settings.py
+
8
−
0
View file @
4e96eb89
...
...
@@ -35,3 +35,11 @@ MAX_REQUEST_COUNT = 500
LOG_RECORD_FORMAT
=
'
%(asctime)s:[%(name)36.36s][%(levelname)5.5s]: %(message)s
'
# The different log record attributes are documented here:
# https://docs.python.org/3/library/logging.html#logrecord-attributes
# URL scheme for the CAS content browser:
BROWSER_URL_FORMAT
=
'
%(type)s/%(instance)s/%(hash)s/%(sizebytes)s/
'
# The string markers that are substituted are:
# instance - CAS instance's name.
# type - Type of CAS object, eg. 'action_result', 'command'...
# hash - Object's digest hash.
# sizebytes - Object's digest size in bytes.
This diff is collapsed.
Click to expand it.
buildgrid/utils.py
+
48
−
1
View file @
4e96eb89
...
...
@@ -13,14 +13,61 @@
# limitations under the License.
from
urllib.parse
import
urljoin
from
operator
import
attrgetter
import
os
import
socket
from
buildgrid.settings
import
HASH
,
HASH_LENGTH
from
buildgrid.settings
import
HASH
,
HASH_LENGTH
,
BROWSER_URL_FORMAT
from
buildgrid._protos.build.bazel.remote.execution.v2
import
remote_execution_pb2
class
BrowserURL
:
__url_markers
=
(
'
%(instance)s
'
,
'
%(type)s
'
,
'
%(hash)s
'
,
'
%(sizebytes)s
'
,
)
def
__init__
(
self
,
base_url
,
instance_name
=
None
):
"""
Begins browser URL helper initialization.
"""
self
.
__base_url
=
base_url
self
.
__initialized
=
False
self
.
__url_spec
=
{
'
%(instance)s
'
:
instance_name
or
''
,
}
def
for_message
(
self
,
message_type
,
message_digest
):
"""
Completes browser URL initialization for a protobuf message.
"""
if
self
.
__initialized
:
return
False
self
.
__url_spec
[
'
%(type)s
'
]
=
message_type
self
.
__url_spec
[
'
%(hash)s
'
]
=
message_digest
.
hash
self
.
__url_spec
[
'
%(sizebytes)s
'
]
=
str
(
message_digest
.
size_bytes
)
self
.
__initialized
=
True
return
True
def
generate
(
self
):
"""
Generates a browser URL string.
"""
if
not
self
.
__base_url
or
not
self
.
__initialized
:
return
None
url_tail
=
BROWSER_URL_FORMAT
for
url_marker
in
self
.
__url_markers
:
if
url_marker
not
in
self
.
__url_spec
:
return
None
if
url_marker
not
in
url_tail
:
continue
url_tail
=
url_tail
.
replace
(
url_marker
,
self
.
__url_spec
[
url_marker
])
return
urljoin
(
self
.
__base_url
,
url_tail
)
def
get_hostname
():
"""
Returns the hostname of the machine executing that function.
...
...
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