Better autodetection
This commit is contained in:
parent
a8084a934b
commit
a8f37f10d6
|
|
@ -12,7 +12,7 @@ def main(argm):
|
|||
:param argm: List of arguments
|
||||
:type argm: argparse.Namespace
|
||||
"""
|
||||
agnostic_path = agnostic_paths.AgnosticPaths(argm.ptb, argm.force_path)
|
||||
agnostic_path = agnostic_paths.AgnosticPaths(argm)
|
||||
test_runner = main_runner.run_check(argm, agnostic_path)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ if __name__ == "__main__":
|
|||
argv = sys.argv[1:]
|
||||
if len(argv) == 0:
|
||||
user_path = os.path.join(os.path.expanduser("~"), "Documents", "DiscordHelper")
|
||||
argv = f"--all --launch --continue --timeout 12 --gen-data {user_path}/new_test_data_{int(time.time())}.yaml".split(" ")
|
||||
argv = f"--all --autodetect --launch --continue --timeout 10 --gen-data {user_path}/new_test_data_{int(time.time())}.yaml".split(" ")
|
||||
|
||||
args = discordHelper.argument_parser.parse(argv)
|
||||
|
||||
|
|
|
|||
|
|
@ -11,17 +11,16 @@ class AgnosticPaths:
|
|||
An agnostic path object, containing all methods to access the files and folders in a standard discord install
|
||||
"""
|
||||
|
||||
def __init__(self, ptb, force_path=None):
|
||||
def __init__(self, args):
|
||||
"""
|
||||
:param ptb: Whether the discord is a public beta install (ptb="PTB") or not (ptb="")
|
||||
:type ptb: str
|
||||
:param force_path: An alternative discord install path, usefull to test the script on a non standard install
|
||||
:type force_path: str
|
||||
:param args: The arguments passed to the script
|
||||
:type args: argparse.Namespace
|
||||
"""
|
||||
self.ptb = ptb
|
||||
self.args = args
|
||||
self.ptb = args.ptb
|
||||
self.os = self.get_os()
|
||||
if force_path is not None:
|
||||
self.force_path = force_path[0]
|
||||
if args.force_path is not None:
|
||||
self.force_path = args.force_path[0]
|
||||
else:
|
||||
self.force_path = None
|
||||
self.main_path = self._get_path()
|
||||
|
|
@ -59,11 +58,17 @@ class AgnosticPaths:
|
|||
return self.force_path
|
||||
if self.os == 'windows':
|
||||
base_path = os.path.join(os.path.expanduser('~'), "AppData", "Local", f"Discord")
|
||||
ptb_path = base_path+"PTB"
|
||||
if self.args.autodetect:
|
||||
if os.path.exists(ptb_path):
|
||||
self.ptb = "PTB"
|
||||
self.args.ptb = "PTB"
|
||||
return ptb_path
|
||||
else:
|
||||
return base_path
|
||||
if self.ptb == 'PTB':
|
||||
return base_path+"PTB"
|
||||
else:
|
||||
if os.path.exists(base_path):
|
||||
return base_path
|
||||
return base_path+"PTB" # Try to find the PTB version
|
||||
elif self.os == 'linux':
|
||||
return os.path.join("/", "opt", "discord")
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ def parse(_args):
|
|||
)
|
||||
|
||||
parser.add_argument('--ptb', action='store_const', const="PTB", default="", help='Force use of Public Test Version')
|
||||
parser.add_argument('--autodetect', action='store_true', help='Try to autodetect the discord folder, will override --ptb')
|
||||
|
||||
# General arguments
|
||||
parser.add_argument('-v', '--version', action='version', version='%(prog)s 1.0')
|
||||
|
|
|
|||
|
|
@ -288,12 +288,12 @@ def run_check(args, agnpath):
|
|||
if not os.path.exists(folder):
|
||||
print("Making folder...")
|
||||
os.makedirs(args.gen_data)
|
||||
print("Exporting data...") # TODO : Advertize where the data is exported
|
||||
print(f"Exporting the test data to {file_path}") # TODO : Advertize where the data is exported
|
||||
main_data = export_data(tr, data)
|
||||
# print(main_data)
|
||||
with open(file_path, "w") as f:
|
||||
json.dump(main_data, f, indent=4)
|
||||
|
||||
print(f"Exiting in {args.timeout} seconds...")
|
||||
print(f"The program executed succesfully, exiting in {args.timeout} seconds...")
|
||||
time.sleep(args.timeout)
|
||||
sys.exit(tr.get_exit_code())
|
||||
|
|
|
|||
Reference in New Issue