-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
zoe
committed
Sep 17, 2024
1 parent
8c164d1
commit 494c649
Showing
1 changed file
with
5 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,31 +1,12 @@ | ||
import os | ||
import sys | ||
import time | ||
|
||
directory = os.path.join("target", "bundled") | ||
prefix = sys.argv[1] # assuming prefix is passed as the first argument | ||
max_retries = 5 # Number of retries for a locked file | ||
delay = 2 # Delay in seconds between retries | ||
prefix = sys.argv[1] | ||
|
||
# Iterate over files in the directory | ||
for filename in os.listdir(directory): | ||
old_file = os.path.join(directory, filename) # ensure you access the full file path | ||
new_file = os.path.join(directory, prefix + filename) # add prefix to the filename | ||
|
||
retries = 0 | ||
while retries < max_retries: | ||
try: | ||
os.rename(old_file, new_file) | ||
print(f"Renamed: {old_file} -> {new_file}") | ||
break | ||
except PermissionError: | ||
print(f"PermissionError: File '{old_file}' is being used. Retrying in {delay} seconds...") | ||
retries += 1 | ||
time.sleep(delay) # Wait before retrying | ||
except Exception as e: | ||
print(f"Error: {e}") | ||
break | ||
else: | ||
print(f"Failed to rename '{old_file}' after {max_retries} attempts.") | ||
old_file = os.path.join(directory) | ||
new_file = os.path.join(directory, prefix + filename) | ||
os.rename(old_file, new_file) | ||
|
||
print(f"Prefix '{prefix}' added to release files.") | ||
print(f"Prefix '{prefix}' added to release files") |