juergbi commented on code in PR #1950:
URL: https://github.com/apache/buildstream/pull/1950#discussion_r1738413224


##########
src/buildstream/utils.py:
##########
@@ -832,6 +832,35 @@ def _parse_size(size, volume):
     return int(num) * 1024 ** units.index(unit)
 
 
+# _parse_percentage():
+#
+# Convert a string representing a percentage between 0% and 100% to a float.
+# E.g. "80%" -> 0.8.
+#
+# Arguments:
+#     percentage (str) The string to parse
+#
+# Returns:
+#     (float) The percentage as a float
+#
+# Raises:
+#     UtilError if the string is not a valid percentage.
+#
+def _parse_percentage(percentage):
+    if not percentage.endswith("%"):
+        raise UtilError("{} is not a valid percentage.".format(percentage))
+
+    try:
+        num = int(percentage[:-1])

Review Comment:
   Fair enough. Updated.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to