You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by no...@apache.org on 2020/12/29 12:25:16 UTC
[buildstream] 06/13: Add element_ref_name method
This is an automated email from the ASF dual-hosted git repository.
not-in-ldap pushed a commit to branch tpollard/prototemp
in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit 7570f90a68010d2909aacf54778c53ced4e0d34c
Author: Raoul Hidalgo Charman <ra...@codethink.co.uk>
AuthorDate: Wed Apr 10 11:39:59 2019 +0100
Add element_ref_name method
This takes a bst path and converts it to what is used in the ref
directory.
---
tests/testutils/artifactshare.py | 11 +++--------
tests/testutils/element_name.py | 14 ++++++++++++++
2 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/tests/testutils/artifactshare.py b/tests/testutils/artifactshare.py
index 6c484ce..80959e9 100644
--- a/tests/testutils/artifactshare.py
+++ b/tests/testutils/artifactshare.py
@@ -1,4 +1,3 @@
-import string
import os
import shutil
import signal
@@ -12,6 +11,8 @@ from buildstream._cas.casserver import create_server
from buildstream._exceptions import CASError
from buildstream._protos.build.bazel.remote.execution.v2 import remote_execution_pb2
+from tests.testutils.element_name import element_ref_name
+
# ArtifactShare()
#
@@ -136,13 +137,7 @@ class ArtifactShare():
#
# Replace path separator and chop off the .bst suffix
- element_name = os.path.splitext(element_name.replace(os.sep, '-'))[0]
-
- valid_chars = string.digits + string.ascii_letters + '-._'
- element_name = ''.join([
- x if x in valid_chars else '_'
- for x in element_name
- ])
+ element_name = element_ref_name(element_name)
artifact_key = '{0}/{1}/{2}'.format(project_name, element_name, cache_key)
try:
diff --git a/tests/testutils/element_name.py b/tests/testutils/element_name.py
new file mode 100644
index 0000000..762354e
--- /dev/null
+++ b/tests/testutils/element_name.py
@@ -0,0 +1,14 @@
+import os
+import string
+
+
+def element_ref_name(element_name):
+ # Replace path separator and chop off the .bst suffix
+ element_name = os.path.splitext(element_name.replace(os.sep, '-'))[0]
+
+ # replace other sybols with '_'
+ valid_chars = string.digits + string.ascii_letters + '-._'
+ return ''.join([
+ x if x in valid_chars else '_'
+ for x in element_name
+ ])