From 555e2fccb126e56db457debcd676bf5428a69f62 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Tue, 5 Oct 2021 16:50:53 -0700 Subject: [PATCH] Improved named_python. --- named_python.py | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/named_python.py b/named_python.py index 899e566..f537e99 100644 --- a/named_python.py +++ b/named_python.py @@ -1,30 +1,50 @@ ''' -Because Python is interpreted, when you look at the task manager process list +named_python +============ + +Because Python is interpreted, when you look at the task manager / process list you'll see that every running python instance has the same name, python.exe. -This scripts helps you name the executables so they stand out. +This script helps you name the executables so they stand out. For the time being this script doesn't automatically call your new exe, you have to write a second command to actually run it. I tried using subprocess.Popen to spawn the new python with the rest of argv but the behavior was different on Linux and Windows and neither was really clean. + +> named_python name + +Examples: +> named_python myserver && python-myserver server.py --port 8080 +> named_python hnarchive && python-hnarchive hnarchive.py livestream ''' +import argparse import os import sys +from voussoirkit import betterhelp from voussoirkit import pathclass from voussoirkit import winwhich -def main(argv): - python = pathclass.Path(winwhich.which('python')) +def namedpython_argparse(args): + python = pathclass.Path(sys.executable) - name = argv[0].strip() + name = args.name.strip() named_python = python.parent.with_child(f'python-{name}{python.extension.with_dot}') if named_python.exists: return 0 os.link(python.absolute_path, named_python.absolute_path) + print(named_python.absolute_path) return 0 +def main(argv): + parser = argparse.ArgumentParser(description=__doc__) + + parser.add_argument('name') + parser.set_defaults(func=namedpython_argparse) + + return betterhelp.single_main(argv, parser, __doc__) + if __name__ == '__main__': raise SystemExit(main(sys.argv[1:]))