diff --git a/DungeonRandomizer.py b/DungeonRandomizer.py index 15e73f85..4723b8db 100755 --- a/DungeonRandomizer.py +++ b/DungeonRandomizer.py @@ -9,9 +9,10 @@ import shlex import sys from source.classes.BabelFish import BabelFish +import source.classes.diags as diagnostics from CLI import parse_cli, get_args_priority -from Main import main, EnemizerError +from Main import main, EnemizerError, __version__ from Rom import get_sprite_from_name from Utils import is_bundled, close_console from Fill import FillError @@ -19,6 +20,13 @@ from Fill import FillError def start(): args = parse_cli(None) + # print diagnostics + # usage: py DungeonRandomizer.py --diags + if args.diags: + diags = diagnostics.output(__version__) + print("\n".join(diags)) + sys.exit(0) + if is_bundled() and len(sys.argv) == 1: # for the bundled builds, if we have no arguments, the user # probably wants the gui. Users of the bundled build who want the command line diff --git a/resources/app/cli/args.json b/resources/app/cli/args.json index 38cbba8c..e74e1736 100644 --- a/resources/app/cli/args.json +++ b/resources/app/cli/args.json @@ -1,5 +1,9 @@ { "lang": {}, + "diags": { + "action": "store_true", + "type": "bool" + }, "create_spoiler": { "action": "store_false", "type": "bool" diff --git a/source/classes/diags.py b/source/classes/diags.py new file mode 100644 index 00000000..3e2c4121 --- /dev/null +++ b/source/classes/diags.py @@ -0,0 +1,47 @@ +import platform, sys, os, subprocess +import pkg_resources +from datetime import datetime + +def diagpad(str): + return str.ljust(len("ALttP Door Randomizer Version") + 5,'.') + +def output(APP_VERSION): + lines = [ + "ALttP Door Randomizer Diagnostics", + "=================================", + diagpad("UTC Time") + str(datetime.utcnow())[:19], + diagpad("ALttP Door Randomizer Version") + APP_VERSION, + diagpad("Python Version") + platform.python_version() + ] + lines.append(diagpad("OS Version") + "%s %s" % (platform.system(), platform.release())) + if hasattr(sys, "executable"): + lines.append(diagpad("Executable") + sys.executable) + lines.append(diagpad("Build Date") + platform.python_build()[1]) + lines.append(diagpad("Compiler") + platform.python_compiler()) + if hasattr(sys, "api_version"): + lines.append(diagpad("Python API") + str(sys.api_version)) + if hasattr(os, "sep"): + lines.append(diagpad("Filepath Separator") + os.sep) + if hasattr(os, "pathsep"): + lines.append(diagpad("Path Env Separator") + os.pathsep) + lines.append("") + lines.append("Packages") + lines.append("--------") + ''' + #this breaks when run from the .exe + reqs = subprocess.check_output([sys.executable, '-m', 'pip', 'freeze']) + installed_packages = [r.decode() for r in reqs.split()] + for pkg in installed_packages: + pkg = pkg.split("==") + lines.append(diagpad(pkg[0]) + pkg[1]) + ''' + installed_packages = [str(d) for d in pkg_resources.working_set] #this doesn't work from the .exe either, but it doesn't crash the program + installed_packages.sort() + for pkg in installed_packages: + pkg = pkg.split(' ') + lines.append(diagpad(pkg[0]) + pkg[1]) + + return lines + +if __name__ == "__main__": + raise AssertionError(f"Called main() on utility library {__file__}")