1
0
Fork 0
mirror of https://github.com/SinTan1729/random.git synced 2025-04-19 09:10:00 -05:00

fix: A syntax error

This commit is contained in:
Sayantan Santra 2025-04-07 21:30:38 -05:00
parent c0cce90f40
commit 9a0f38c994
Signed by: SinTan1729
GPG key ID: 0538DD402EA50898

View file

@ -10,66 +10,65 @@ import subprocess
import time import time
# Check if the build script exists # Check if the build script exists
if not os.path.isfile('lure.sh'): if not os.path.isfile("lure.sh"):
print("Couldn't find a lure.sh file in the current directory.") print("Couldn't find a lure.sh file in the current directory.")
exit(1) exit(1)
with open('lure.sh', 'r') as script_file: with open("lure.sh", "r") as script_file:
script = script_file.readlines() script = script_file.readlines()
vars = {} vars = {}
for line in script: for line in script:
if '=' not in line or '\t' in line: if "=" not in line or "\t" in line:
continue continue
var, val = line.strip('\n').split('=') var, val = line.strip("\n").split("=")
vars[var] = val.strip('""').strip("''") vars[var] = val.strip('""').strip("''")
for src_type in [k for k in vars.keys() if "sources" in k]: for src_type in [k for k in vars.keys() if "sources" in k]:
suffix = src_type.split('_')[1] suffix = src_type.split("_")[1]
if suffix != "": if suffix != "":
suffix = "_"+suffix suffix = "_" + suffix
# Read all the links # Read all the links
links = [link.strip('""').strip("''") links = [link.strip('""').strip("''") for link in vars[src_type].strip("()").split()]
for link in vars[src_type].strip('()').split()]
# Get the old sums # Get the old sums
old_sums = vars["checksums"+suffix].strip('()').split() old_sums = vars["checksums" + suffix].strip("()").split()
old_sums = [sum.strip('""').strip("''") for sum in old_sums] old_sums = [sum.strip('""').strip("''") for sum in old_sums]
checksums = [] checksums = []
for i, link in enumerate(links): for i, link in enumerate(links):
if old_sums[i] == 'SKIP': if old_sums[i] == "SKIP":
checksums.append('SKIP') checksums.append("SKIP")
continue continue
# Try to do variable expansions (works up to one level, should be enough) # Try to do variable expansions (works up to one level, should be enough)
to_replace = list(set(re.findall('(\${.+?})', link))) to_replace = list(set(re.findall("(${.+?})", link)))
for str in to_replace: for str in to_replace:
str_clean = str.strip('${}') str_clean = str.strip("${}")
link = link.replace(str, vars[str_clean]) link = link.replace(str, vars[str_clean])
filename = subprocess.run( filename = subprocess.run(
['curl', '-sLO', '-w', '%{filename_effective}', link], stdout=subprocess.PIPE) ["curl", "-sLO", "-w", "%{filename_effective}", link], stdout=subprocess.PIPE
filename = filename.stdout.decode('utf-8') )
filename = filename.stdout.decode("utf-8")
checksum = subprocess.run( checksum = subprocess.run(["sha256sum", filename], stdout=subprocess.PIPE)
['sha256sum', filename], stdout=subprocess.PIPE) checksum = checksum.stdout.decode("utf-8").split()[0]
checksum = checksum.stdout.decode('utf-8').split()[0]
checksums.append(checksum) checksums.append(checksum)
# Build the output line # Build the output line
sum_out = "checksums"+suffix+"=('"+"' '".join(checksums)+"')\n" sum_out = "checksums" + suffix + "=('" + "' '".join(checksums) + "')\n"
for i, line in enumerate(script): for i, line in enumerate(script):
if "checksums"+suffix in line: if "checksums" + suffix in line:
script[i] = sum_out script[i] = sum_out
print("Updated checksums for "+suffix[1:]+" sources") print("Updated checksums for " + suffix[1:] + " sources")
timestamp = "{}".format(int(time.time())) timestamp = "{}".format(int(time.time()))
with open(timestamp, 'w') as tempfile: with open(timestamp, "w") as tempfile:
tempfile.writelines(script) tempfile.writelines(script)
os.rename('lure.sh', "lure-"+timestamp+".sh") os.rename("lure.sh", "lure-" + timestamp + ".sh")
os.rename(timestamp, 'lure.sh') os.rename(timestamp, "lure.sh")
print("Done!") print("Done!")