-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_release_prefix.py
35 lines (31 loc) · 1.26 KB
/
add_release_prefix.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import os
import time
import sys
import shutil
directory = os.path.join("target", "bundled")
prefix = sys.argv[1] # assuming prefix is passed as the first argument
max_retries = 100 # Number of retries for a locked file
delay = 2 # Delay in seconds between retries
# 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}")
if os.path.isdir(new_file):
shutil.make_archive(f"{new_file}", 'zip', new_file)
os.rmdir(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.")
print(f"Prefix '{prefix}' added to release files.")