2021-10-05 23:50:53 +00:00
|
|
|
import argparse
|
2021-09-15 03:02:03 +00:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
2021-10-05 23:50:53 +00:00
|
|
|
from voussoirkit import betterhelp
|
2021-09-15 03:02:03 +00:00
|
|
|
from voussoirkit import pathclass
|
|
|
|
from voussoirkit import winwhich
|
|
|
|
|
2021-10-05 23:50:53 +00:00
|
|
|
def namedpython_argparse(args):
|
2021-10-13 04:38:58 +00:00
|
|
|
this_python = pathclass.Path(sys.executable)
|
2021-09-15 03:02:03 +00:00
|
|
|
|
2021-10-13 04:38:58 +00:00
|
|
|
base = this_python.replace_extension('').basename.split('-', 1)[0]
|
2021-10-05 23:50:53 +00:00
|
|
|
name = args.name.strip()
|
2021-10-13 04:38:58 +00:00
|
|
|
extension = this_python.extension.with_dot
|
|
|
|
named_python = this_python.parent.with_child(f'{base}-{name}{extension}')
|
2021-09-15 03:02:03 +00:00
|
|
|
if named_python.exists:
|
|
|
|
return 0
|
|
|
|
|
2021-10-13 04:38:58 +00:00
|
|
|
os.link(this_python.absolute_path, named_python.absolute_path)
|
2021-10-05 23:50:53 +00:00
|
|
|
print(named_python.absolute_path)
|
2021-09-15 03:02:03 +00:00
|
|
|
return 0
|
|
|
|
|
2021-10-05 23:50:53 +00:00
|
|
|
def main(argv):
|
2022-02-13 03:50:00 +00:00
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description='''
|
|
|
|
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 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.
|
|
|
|
''',
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
'name',
|
|
|
|
type=str,
|
|
|
|
help='''
|
|
|
|
If you invoke this script with python.exe, a hardlink python-{name}.exe
|
|
|
|
will be created. Also works with pythonw.
|
|
|
|
''',
|
|
|
|
)
|
2021-10-05 23:50:53 +00:00
|
|
|
parser.set_defaults(func=namedpython_argparse)
|
|
|
|
|
2022-02-13 03:50:00 +00:00
|
|
|
return betterhelp.go(parser, argv)
|
2021-10-05 23:50:53 +00:00
|
|
|
|
2021-09-15 03:02:03 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
raise SystemExit(main(sys.argv[1:]))
|