-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
migrate video_nodeQuery.sh to python #2851
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
KyriosGN0
wants to merge
6
commits into
SeleniumHQ:trunk
Choose a base branch
from
KyriosGN0:python
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
49a7eba
migrate video_nodeQuery.sh to python
KyriosGN0 53dee06
remove shell script
KyriosGN0 e8dad39
fix handling of booleans in check of record_video
KyriosGN0 115bd12
Merge branch 'trunk' into python
VietND96 00476a7
Improve regex pattern handling
VietND96 3801080
Merge branch 'trunk' into python
VietND96 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,117 @@ | ||||||
#!/usr/bin/env python3 | ||||||
|
||||||
import json | ||||||
import os | ||||||
import re | ||||||
import sys | ||||||
from typing import List, Tuple | ||||||
|
||||||
|
||||||
def main() -> None: | ||||||
""" | ||||||
Process video recording configuration based on session capabilities. | ||||||
|
||||||
Args: | ||||||
sys.argv[1]: SESSION_ID | ||||||
sys.argv[2]: SESSION_CAPABILITIES (JSON string) | ||||||
|
||||||
Outputs: | ||||||
Space-separated values: RECORD_VIDEO TEST_NAME | ||||||
""" | ||||||
# Define parameters | ||||||
session_id = sys.argv[1] if len(sys.argv) > 1 else "" | ||||||
session_capabilities = sys.argv[2] if len(sys.argv) > 2 else "" | ||||||
|
||||||
# Environment variables with defaults | ||||||
video_cap_name = os.environ.get("VIDEO_CAP_NAME", "se:recordVideo") | ||||||
test_name_cap = os.environ.get("TEST_NAME_CAP", "se:name") | ||||||
video_name_cap = os.environ.get("VIDEO_NAME_CAP", "se:videoName") | ||||||
video_file_name_trim = os.environ.get("SE_VIDEO_FILE_NAME_TRIM_REGEX", "[:alnum:]-_") | ||||||
video_file_name_suffix = os.environ.get("SE_VIDEO_FILE_NAME_SUFFIX", "true") | ||||||
|
||||||
# Initialize variables | ||||||
record_video = None | ||||||
test_name = None | ||||||
video_name = None | ||||||
|
||||||
# Extract values from session capabilities if provided | ||||||
if session_capabilities: | ||||||
try: | ||||||
capabilities = json.loads(session_capabilities) | ||||||
record_video = capabilities.get(video_cap_name) | ||||||
test_name = capabilities.get(test_name_cap) | ||||||
video_name = capabilities.get(video_name_cap) | ||||||
except (json.JSONDecodeError, AttributeError): | ||||||
# If JSON parsing fails, continue with None values | ||||||
pass | ||||||
|
||||||
# Check if enabling to record video | ||||||
if (isinstance(record_video, str) and record_video.lower() == "false") or record_video is False: | ||||||
record_video = "false" | ||||||
else: | ||||||
record_video = "true" | ||||||
|
||||||
# Check if video file name is set via capabilities | ||||||
if video_name and video_name != "null": | ||||||
test_name = video_name | ||||||
elif test_name and test_name != "null": | ||||||
test_name = test_name | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This assignment is redundant since
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
else: | ||||||
test_name = "" | ||||||
|
||||||
# Check if append session ID to the video file name suffix | ||||||
if not test_name: | ||||||
test_name = session_id | ||||||
elif video_file_name_suffix.lower() == "true": | ||||||
test_name = f"{test_name}_{session_id}" | ||||||
|
||||||
# Normalize the video file name | ||||||
test_name = normalize_filename(test_name, video_file_name_trim) | ||||||
|
||||||
# Output the values for other scripts consuming | ||||||
print(f"{record_video} {test_name}") | ||||||
|
||||||
|
||||||
def normalize_filename(filename: str, trim_pattern: str) -> str: | ||||||
""" | ||||||
Normalize the filename by replacing spaces with underscores, | ||||||
keeping only allowed characters, and truncating to 251 characters. | ||||||
|
||||||
Args: | ||||||
filename: The original filename | ||||||
trim_pattern: Pattern defining allowed characters (e.g., "[:alnum:]-_") | ||||||
|
||||||
Returns: | ||||||
Normalized filename | ||||||
""" | ||||||
if not filename: | ||||||
return "" | ||||||
|
||||||
# Replace spaces with underscores | ||||||
normalized = filename.replace(" ", "_") | ||||||
|
||||||
# Convert trim pattern to regex | ||||||
# Handle character classes like [:alnum:] | ||||||
posix_classes = { | ||||||
"[:alnum:]": "a-zA-Z0-9", | ||||||
"[:alpha:]": "a-zA-Z", | ||||||
"[:digit:]": "0-9", | ||||||
"[:space:]": " \t\n\r\f\v" | ||||||
} | ||||||
|
||||||
allowed_chars = trim_pattern | ||||||
for posix_class, replacement in posix_classes.items(): | ||||||
if posix_class in allowed_chars: | ||||||
allowed_chars = allowed_chars.replace(posix_class, replacement) | ||||||
|
||||||
pattern = f"[^{re.escape(allowed_chars)}]" | ||||||
|
||||||
# Remove disallowed characters | ||||||
normalized = re.sub(pattern, "", normalized) | ||||||
|
||||||
# Truncate to 251 characters | ||||||
return normalized[:251] | ||||||
|
||||||
|
||||||
if __name__ == "__main__": | ||||||
main() |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.