Skip to content

Commit 20557eb

Browse files
Fix T201 in release_tools and scripts: replace print() with sys.stdout/stderr.write()
Agent-Logs-Url: https://github.com/GitHubSecurityLab/seclab-taskflow-agent/sessions/8acf69e6-94a8-40d4-a66c-2b90b143f143 Co-authored-by: kevinbackhouse <4358136+kevinbackhouse@users.noreply.github.com>
1 parent 4ab7df8 commit 20557eb

3 files changed

Lines changed: 31 additions & 31 deletions

File tree

release_tools/copy_files.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def copy_files(file_list, dest_dir):
2929
abs_dest = os.path.abspath(os.path.join(dest_dir, rel_path))
3030
os.makedirs(os.path.dirname(abs_dest), exist_ok=True)
3131
shutil.copy2(abs_src, abs_dest)
32-
print(f"Copied {abs_src} -> {abs_dest}")
32+
sys.stdout.write(f"Copied {abs_src} -> {abs_dest}\n")
3333

3434

3535
def ensure_git_repo(dest_dir):
@@ -41,22 +41,22 @@ def ensure_git_repo(dest_dir):
4141
if not os.path.isdir(git_dir):
4242
try:
4343
subprocess.run(["git", "init", "-b", "main"], cwd=dest_dir, check=True)
44-
print(f"Initialized new git repository in {dest_dir} with 'main' as the default branch")
44+
sys.stdout.write(f"Initialized new git repository in {dest_dir} with 'main' as the default branch\n")
4545
except subprocess.CalledProcessError as e:
46-
print(f"Failed to initialize git repository in {dest_dir}: {e}")
46+
sys.stderr.write(f"Failed to initialize git repository in {dest_dir}: {e}\n")
4747
sys.exit(1)
4848
else:
4949
# Ensure main branch exists and is checked out
5050
try:
5151
branches = subprocess.check_output(["git", "branch"], cwd=dest_dir, text=True)
5252
if "main" not in branches:
5353
subprocess.run(["git", "checkout", "-b", "main"], cwd=dest_dir, check=True)
54-
print("Created and switched to 'main' branch.")
54+
sys.stdout.write("Created and switched to 'main' branch.\n")
5555
else:
5656
subprocess.run(["git", "checkout", "main"], cwd=dest_dir, check=True)
57-
print("Switched to 'main' branch.")
57+
sys.stdout.write("Switched to 'main' branch.\n")
5858
except subprocess.CalledProcessError as e:
59-
print(f"Failed to ensure 'main' branch in {dest_dir}: {e}")
59+
sys.stderr.write(f"Failed to ensure 'main' branch in {dest_dir}: {e}\n")
6060
sys.exit(1)
6161

6262

@@ -70,16 +70,16 @@ def git_add_files(file_list, dest_dir):
7070
for rel_path in file_list:
7171
try:
7272
subprocess.run(["git", "add", "-f", rel_path], check=True)
73-
print(f"git add {rel_path}")
73+
sys.stdout.write(f"git add {rel_path}\n")
7474
except subprocess.CalledProcessError as e:
75-
print(f"Failed to git add {rel_path}: {e}")
75+
sys.stderr.write(f"Failed to git add {rel_path}: {e}\n")
7676
finally:
7777
os.chdir(cwd)
7878

7979

8080
if __name__ == "__main__":
8181
if len(sys.argv) != 3:
82-
print("Usage: python copy_files.py <file_list.txt> <dest_dir>")
82+
sys.stderr.write("Usage: python copy_files.py <file_list.txt> <dest_dir>\n")
8383
sys.exit(1)
8484
file_list_path = sys.argv[1]
8585
dest_dir = sys.argv[2]

release_tools/publish_docker.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ def build_and_push_image(dest_dir, image_name, tag):
2525
)
2626
# Push
2727
subprocess.run(["docker", "push", f"{image_name}:{tag}"], check=True)
28-
print(f"Pushed {image_name}:{tag}")
28+
sys.stdout.write(f"Pushed {image_name}:{tag}\n")
2929
digest = get_image_digest(image_name, tag)
30-
print(f"Image digest: {digest}")
30+
sys.stdout.write(f"Image digest: {digest}\n")
3131
with open("/tmp/digest.txt", "w") as f:
3232
f.write(digest)
3333

3434

3535
if __name__ == "__main__":
3636
if len(sys.argv) != 3:
37-
print("Usage: python build_and_publish_docker.py <ghcr_username/repo> <tag>")
38-
print("Example: python build_and_publish_docker.py ghcr.io/anticomputer/my-python-app latest")
37+
sys.stderr.write("Usage: python build_and_publish_docker.py <ghcr_username/repo> <tag>\n")
38+
sys.stderr.write("Example: python build_and_publish_docker.py ghcr.io/anticomputer/my-python-app latest\n")
3939
sys.exit(1)
4040

4141
image_name = sys.argv[1]

scripts/migrate_to_jinja2.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def migrate_file(self, file_path: Path) -> bool:
9191
True if file was modified, False otherwise
9292
"""
9393
if file_path.suffix != '.yaml':
94-
print(f"Skipping non-YAML file: {file_path}")
94+
sys.stdout.write(f"Skipping non-YAML file: {file_path}\n")
9595
return False
9696

9797
try:
@@ -101,25 +101,25 @@ def migrate_file(self, file_path: Path) -> bool:
101101
migrated_content = self.migrate_content(original_content)
102102

103103
if migrated_content == original_content:
104-
print(f"No changes needed: {file_path}")
104+
sys.stdout.write(f"No changes needed: {file_path}\n")
105105
return False
106106

107107
if self.dry_run:
108-
print(f"\n{'='*60}")
109-
print(f"Would modify: {file_path}")
110-
print(f"{'='*60}")
108+
sys.stdout.write(f"\n{'='*60}\n")
109+
sys.stdout.write(f"Would modify: {file_path}\n")
110+
sys.stdout.write(f"{'='*60}\n")
111111
self._show_diff(original_content, migrated_content)
112112
return True
113113

114114
# Write migrated content
115115
with open(file_path, 'w') as f:
116116
f.write(migrated_content)
117117

118-
print(f"Migrated: {file_path}")
118+
sys.stdout.write(f"Migrated: {file_path}\n")
119119
return True
120120

121121
except Exception as e:
122-
print(f"Error migrating {file_path}: {e}", file=sys.stderr)
122+
sys.stderr.write(f"Error migrating {file_path}: {e}\n")
123123
return False
124124

125125
def _show_diff(self, original: str, migrated: str):
@@ -129,9 +129,9 @@ def _show_diff(self, original: str, migrated: str):
129129

130130
for i, (orig, mig) in enumerate(zip(orig_lines, mig_lines, strict=False), 1):
131131
if orig != mig:
132-
print(f"Line {i}:")
133-
print(f" - {orig}")
134-
print(f" + {mig}")
132+
sys.stdout.write(f"Line {i}:\n")
133+
sys.stdout.write(f" - {orig}\n")
134+
sys.stdout.write(f" + {mig}\n")
135135

136136
def migrate_directory(self, directory: Path, recursive: bool = True) -> int:
137137
"""Migrate all YAML files in directory.
@@ -143,10 +143,10 @@ def migrate_directory(self, directory: Path, recursive: bool = True) -> int:
143143
yaml_files = list(directory.glob(pattern))
144144

145145
if not yaml_files:
146-
print(f"No YAML files found in {directory}")
146+
sys.stdout.write(f"No YAML files found in {directory}\n")
147147
return 0
148148

149-
print(f"Found {len(yaml_files)} YAML files")
149+
sys.stdout.write(f"Found {len(yaml_files)} YAML files\n")
150150

151151
modified_count = 0
152152
for yaml_file in yaml_files:
@@ -184,7 +184,7 @@ def main():
184184
total_modified = 0
185185
for path in args.paths:
186186
if not path.exists():
187-
print(f"Path not found: {path}", file=sys.stderr)
187+
sys.stderr.write(f"Path not found: {path}\n")
188188
continue
189189

190190
if path.is_file():
@@ -197,14 +197,14 @@ def main():
197197
)
198198
total_modified += modified
199199
else:
200-
print(f"Invalid path: {path}", file=sys.stderr)
200+
sys.stderr.write(f"Invalid path: {path}\n")
201201

202-
print(f"\n{'='*60}")
202+
sys.stdout.write(f"\n{'='*60}\n")
203203
if args.dry_run:
204-
print(f"Dry run complete. {total_modified} files would be modified.")
204+
sys.stdout.write(f"Dry run complete. {total_modified} files would be modified.\n")
205205
else:
206-
print(f"Migration complete. {total_modified} files modified.")
207-
print(f"{'='*60}")
206+
sys.stdout.write(f"Migration complete. {total_modified} files modified.\n")
207+
sys.stdout.write(f"{'='*60}\n")
208208

209209

210210
if __name__ == '__main__':

0 commit comments

Comments
 (0)