Queries the given executable (defaults to the Python interpreter binary) for various architecture information. Returns a tuple (bits, linkage) which contains information about the bit architecture and the linkage format used for the executable. Both values are
(executable=sys.executable, bits='', linkage='')
| 644 | } |
| 645 | |
| 646 | def architecture(executable=sys.executable, bits='', linkage=''): |
| 647 | |
| 648 | """ Queries the given executable (defaults to the Python interpreter |
| 649 | binary) for various architecture information. |
| 650 | |
| 651 | Returns a tuple (bits, linkage) which contains information about |
| 652 | the bit architecture and the linkage format used for the |
| 653 | executable. Both values are returned as strings. |
| 654 | |
| 655 | Values that cannot be determined are returned as given by the |
| 656 | parameter presets. If bits is given as '', the sizeof(pointer) |
| 657 | (or sizeof(long) on Python version < 1.5.2) is used as |
| 658 | indicator for the supported pointer size. |
| 659 | |
| 660 | The function relies on the system's "file" command to do the |
| 661 | actual work. This is available on most if not all Unix |
| 662 | platforms. On some non-Unix platforms where the "file" command |
| 663 | does not exist and the executable is set to the Python interpreter |
| 664 | binary defaults from _default_architecture are used. |
| 665 | |
| 666 | """ |
| 667 | # Use the sizeof(pointer) as default number of bits if nothing |
| 668 | # else is given as default. |
| 669 | if not bits: |
| 670 | import struct |
| 671 | size = struct.calcsize('P') |
| 672 | bits = str(size * 8) + 'bit' |
| 673 | |
| 674 | # Get data from the 'file' system command |
| 675 | if executable: |
| 676 | fileout = _syscmd_file(executable, '') |
| 677 | else: |
| 678 | fileout = '' |
| 679 | |
| 680 | if not fileout and \ |
| 681 | executable == sys.executable: |
| 682 | # "file" command did not return anything; we'll try to provide |
| 683 | # some sensible defaults then... |
| 684 | if sys.platform in _default_architecture: |
| 685 | b, l = _default_architecture[sys.platform] |
| 686 | if b: |
| 687 | bits = b |
| 688 | if l: |
| 689 | linkage = l |
| 690 | return bits, linkage |
| 691 | |
| 692 | if 'executable' not in fileout and 'shared object' not in fileout: |
| 693 | # Format not supported |
| 694 | return bits, linkage |
| 695 | |
| 696 | # Bits |
| 697 | if '32-bit' in fileout: |
| 698 | bits = '32bit' |
| 699 | elif '64-bit' in fileout: |
| 700 | bits = '64bit' |
| 701 | |
| 702 | # Linkage |
| 703 | if 'ELF' in fileout: |
no test coverage detected