()
| 626 | main() |
| 627 | |
| 628 | def _script(): |
| 629 | help = """\ |
| 630 | %s [--user-base] [--user-site] |
| 631 | |
| 632 | Without arguments print some useful information |
| 633 | With arguments print the value of USER_BASE and/or USER_SITE separated |
| 634 | by '%s'. |
| 635 | |
| 636 | Exit codes with --user-base or --user-site: |
| 637 | 0 - user site directory is enabled |
| 638 | 1 - user site directory is disabled by user |
| 639 | 2 - user site directory is disabled by super user |
| 640 | or for security reasons |
| 641 | >2 - unknown error |
| 642 | """ |
| 643 | args = sys.argv[1:] |
| 644 | if not args: |
| 645 | user_base = getuserbase() |
| 646 | user_site = getusersitepackages() |
| 647 | print("sys.path = [") |
| 648 | for dir in sys.path: |
| 649 | print(" %r," % (dir,)) |
| 650 | print("]") |
| 651 | def exists(path): |
| 652 | if path is not None and os.path.isdir(path): |
| 653 | return "exists" |
| 654 | else: |
| 655 | return "doesn't exist" |
| 656 | print(f"USER_BASE: {user_base!r} ({exists(user_base)})") |
| 657 | print(f"USER_SITE: {user_site!r} ({exists(user_site)})") |
| 658 | print(f"ENABLE_USER_SITE: {ENABLE_USER_SITE!r}") |
| 659 | sys.exit(0) |
| 660 | |
| 661 | buffer = [] |
| 662 | if '--user-base' in args: |
| 663 | buffer.append(USER_BASE) |
| 664 | if '--user-site' in args: |
| 665 | buffer.append(USER_SITE) |
| 666 | |
| 667 | if buffer: |
| 668 | print(os.pathsep.join(buffer)) |
| 669 | if ENABLE_USER_SITE: |
| 670 | sys.exit(0) |
| 671 | elif ENABLE_USER_SITE is False: |
| 672 | sys.exit(1) |
| 673 | elif ENABLE_USER_SITE is None: |
| 674 | sys.exit(2) |
| 675 | else: |
| 676 | sys.exit(3) |
| 677 | else: |
| 678 | import textwrap |
| 679 | print(textwrap.dedent(help % (sys.argv[0], os.pathsep))) |
| 680 | sys.exit(10) |
| 681 | |
| 682 | if __name__ == '__main__': |
| 683 | _script() |
no test coverage detected