From a468bfb83c12148a48606eda23df25e42f29ba11 Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Mon, 16 Jan 2023 16:16:22 -0500 Subject: [PATCH] Bypass IndexError when running without having a file in each slot for all categories --- randomize.py | 112 +++++++++++++++++++++++++++------------------------ 1 file changed, 60 insertions(+), 52 deletions(-) diff --git a/randomize.py b/randomize.py index 6e2f275..45d8c2d 100755 --- a/randomize.py +++ b/randomize.py @@ -19,59 +19,67 @@ sorted_dir = args.sorted_dir[0].rstrip('/') + '/' for i in range(1, 9): # national options = [f.path for f in scandir(sorted_dir + 'National/' + str(i)) if f.is_dir()] - track = choice(options) - if islink(f"{database_dir}Beta_Nat_Track_Slot_{str(i)}.dx9.database"): - remove(f"{database_dir}Beta_Nat_Track_Slot_{str(i)}.dx9.database") - if islink(f"{database_dir}Beta_Nat_Track_Slot_{str(i)}.dx9.level"): - remove(f"{database_dir}Beta_Nat_Track_Slot_{str(i)}.dx9.level") - if islink(f"{database_dir}Beta_Nat_Track_Slot_{str(i)}.dx9.package"): - remove(f"{database_dir}Beta_Nat_Track_Slot_{str(i)}.dx9.package") - if islink(f"{database_dir}Beta_Nat_Track_Slot_{str(i)}.dx9.scene"): - remove(f"{database_dir}Beta_Nat_Track_Slot_{str(i)}.dx9.scene") - symlink(f"{track}/Beta_Nat_Track_Slot_{str(i)}.dx9.database", - f"{database_dir}Beta_Nat_Track_Slot_{str(i)}.dx9.database") - symlink(f"{track}/Beta_Nat_Track_Slot_{str(i)}.dx9.level", - f"{database_dir}Beta_Nat_Track_Slot_{str(i)}.dx9.level") - symlink(f"{track}/Beta_Nat_Track_Slot_{str(i)}.dx9.package", - f"{database_dir}Beta_Nat_Track_Slot_{str(i)}.dx9.package") - symlink(f"{track}/Beta_Nat_Track_Slot_{str(i)}.dx9.scene", - f"{database_dir}Beta_Nat_Track_Slot_{str(i)}.dx9.scene") + try: + track = choice(options) + if islink(f"{database_dir}Beta_Nat_Track_Slot_{str(i)}.dx9.database"): + remove(f"{database_dir}Beta_Nat_Track_Slot_{str(i)}.dx9.database") + if islink(f"{database_dir}Beta_Nat_Track_Slot_{str(i)}.dx9.level"): + remove(f"{database_dir}Beta_Nat_Track_Slot_{str(i)}.dx9.level") + if islink(f"{database_dir}Beta_Nat_Track_Slot_{str(i)}.dx9.package"): + remove(f"{database_dir}Beta_Nat_Track_Slot_{str(i)}.dx9.package") + if islink(f"{database_dir}Beta_Nat_Track_Slot_{str(i)}.dx9.scene"): + remove(f"{database_dir}Beta_Nat_Track_Slot_{str(i)}.dx9.scene") + symlink(f"{track}/Beta_Nat_Track_Slot_{str(i)}.dx9.database", + f"{database_dir}Beta_Nat_Track_Slot_{str(i)}.dx9.database") + symlink(f"{track}/Beta_Nat_Track_Slot_{str(i)}.dx9.level", + f"{database_dir}Beta_Nat_Track_Slot_{str(i)}.dx9.level") + symlink(f"{track}/Beta_Nat_Track_Slot_{str(i)}.dx9.package", + f"{database_dir}Beta_Nat_Track_Slot_{str(i)}.dx9.package") + symlink(f"{track}/Beta_Nat_Track_Slot_{str(i)}.dx9.scene", + f"{database_dir}Beta_Nat_Track_Slot_{str(i)}.dx9.scene") + except IndexError: + pass # supercross options = [f.path for f in scandir(sorted_dir + 'Supercross/' + str(i)) if f.is_dir()] - track = choice(options) - if islink(f"{database_dir}Beta_Sx_Track_Slot_{str(i)}.dx9.database"): - remove(f"{database_dir}Beta_Sx_Track_Slot_{str(i)}.dx9.database") - if islink(f"{database_dir}Beta_Sx_Track_Slot_{str(i)}.dx9.level"): - remove(f"{database_dir}Beta_Sx_Track_Slot_{str(i)}.dx9.level") - if islink(f"{database_dir}Beta_Sx_Track_Slot_{str(i)}.dx9.package"): - remove(f"{database_dir}Beta_Sx_Track_Slot_{str(i)}.dx9.package") - if islink(f"{database_dir}Beta_Sx_Track_Slot_{str(i)}.dx9.scene"): - remove(f"{database_dir}Beta_Sx_Track_Slot_{str(i)}.dx9.scene") - symlink(f"{track}/Beta_Sx_Track_Slot_{str(i)}.dx9.database", - f"{database_dir}Beta_Sx_Track_Slot_{str(i)}.dx9.database") - symlink(f"{track}/Beta_Sx_Track_Slot_{str(i)}.dx9.level", - f"{database_dir}Beta_Sx_Track_Slot_{str(i)}.dx9.level") - symlink(f"{track}/Beta_Sx_Track_Slot_{str(i)}.dx9.package", - f"{database_dir}Beta_Sx_Track_Slot_{str(i)}.dx9.package") - symlink(f"{track}/Beta_Sx_Track_Slot_{str(i)}.dx9.scene", - f"{database_dir}Beta_Sx_Track_Slot_{str(i)}.dx9.scene") + try: + track = choice(options) + if islink(f"{database_dir}Beta_Sx_Track_Slot_{str(i)}.dx9.database"): + remove(f"{database_dir}Beta_Sx_Track_Slot_{str(i)}.dx9.database") + if islink(f"{database_dir}Beta_Sx_Track_Slot_{str(i)}.dx9.level"): + remove(f"{database_dir}Beta_Sx_Track_Slot_{str(i)}.dx9.level") + if islink(f"{database_dir}Beta_Sx_Track_Slot_{str(i)}.dx9.package"): + remove(f"{database_dir}Beta_Sx_Track_Slot_{str(i)}.dx9.package") + if islink(f"{database_dir}Beta_Sx_Track_Slot_{str(i)}.dx9.scene"): + remove(f"{database_dir}Beta_Sx_Track_Slot_{str(i)}.dx9.scene") + symlink(f"{track}/Beta_Sx_Track_Slot_{str(i)}.dx9.database", + f"{database_dir}Beta_Sx_Track_Slot_{str(i)}.dx9.database") + symlink(f"{track}/Beta_Sx_Track_Slot_{str(i)}.dx9.level", + f"{database_dir}Beta_Sx_Track_Slot_{str(i)}.dx9.level") + symlink(f"{track}/Beta_Sx_Track_Slot_{str(i)}.dx9.package", + f"{database_dir}Beta_Sx_Track_Slot_{str(i)}.dx9.package") + symlink(f"{track}/Beta_Sx_Track_Slot_{str(i)}.dx9.scene", + f"{database_dir}Beta_Sx_Track_Slot_{str(i)}.dx9.scene") + except IndexError: + pass # free ride options = [f.path for f in scandir(sorted_dir + 'Free Ride/' + str(i)) if f.is_dir()] - track = choice(options) - if islink(f"{database_dir}Beta_Track_Slot_{str(i)}.dx9.database"): - remove(f"{database_dir}Beta_Track_Slot_{str(i)}.dx9.database") - if islink(f"{database_dir}Beta_Track_Slot_{str(i)}.dx9.level"): - remove(f"{database_dir}Beta_Track_Slot_{str(i)}.dx9.level") - if islink(f"{database_dir}Beta_Track_Slot_{str(i)}.dx9.package"): - remove(f"{database_dir}Beta_Track_Slot_{str(i)}.dx9.package") - if islink(f"{database_dir}Beta_Track_Slot_{str(i)}.dx9.scene"): - remove(f"{database_dir}Beta_Track_Slot_{str(i)}.dx9.scene") - symlink(f"{track}/Beta_Track_Slot_{str(i)}.dx9.database", - f"{database_dir}Beta_Track_Slot_{str(i)}.dx9.database") - symlink(f"{track}/Beta_Track_Slot_{str(i)}.dx9.level", - f"{database_dir}Beta_Track_Slot_{str(i)}.dx9.level") - symlink(f"{track}/Beta_Track_Slot_{str(i)}.dx9.package", - f"{database_dir}Beta_Track_Slot_{str(i)}.dx9.package") - symlink(f"{track}/Beta_Track_Slot_{str(i)}.dx9.scene", - f"{database_dir}Beta_Track_Slot_{str(i)}.dx9.scene") - + try: + track = choice(options) + if islink(f"{database_dir}Beta_Track_Slot_{str(i)}.dx9.database"): + remove(f"{database_dir}Beta_Track_Slot_{str(i)}.dx9.database") + if islink(f"{database_dir}Beta_Track_Slot_{str(i)}.dx9.level"): + remove(f"{database_dir}Beta_Track_Slot_{str(i)}.dx9.level") + if islink(f"{database_dir}Beta_Track_Slot_{str(i)}.dx9.package"): + remove(f"{database_dir}Beta_Track_Slot_{str(i)}.dx9.package") + if islink(f"{database_dir}Beta_Track_Slot_{str(i)}.dx9.scene"): + remove(f"{database_dir}Beta_Track_Slot_{str(i)}.dx9.scene") + symlink(f"{track}/Beta_Track_Slot_{str(i)}.dx9.database", + f"{database_dir}Beta_Track_Slot_{str(i)}.dx9.database") + symlink(f"{track}/Beta_Track_Slot_{str(i)}.dx9.level", + f"{database_dir}Beta_Track_Slot_{str(i)}.dx9.level") + symlink(f"{track}/Beta_Track_Slot_{str(i)}.dx9.package", + f"{database_dir}Beta_Track_Slot_{str(i)}.dx9.package") + symlink(f"{track}/Beta_Track_Slot_{str(i)}.dx9.scene", + f"{database_dir}Beta_Track_Slot_{str(i)}.dx9.scene") + except IndexError: + pass