OLD | NEW |
1 #!/usr/bin/env python3 | 1 #!/usr/bin/env python3 |
2 | 2 |
3 """ This module tries to retrieve as much platform-identifying data as | 3 """ This module tries to retrieve as much platform-identifying data as |
4 possible. It makes this information available via function APIs. | 4 possible. It makes this information available via function APIs. |
5 | 5 |
6 If called from the command line, it prints the platform | 6 If called from the command line, it prints the platform |
7 information concatenated as single string to stdout. The output | 7 information concatenated as single string to stdout. The output |
8 format is useable as part of a filename. | 8 format is useable as part of a filename. |
9 | 9 |
10 """ | 10 """ |
(...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
803 filepath = os.path.abspath(filepath) | 803 filepath = os.path.abspath(filepath) |
804 while os.path.islink(filepath): | 804 while os.path.islink(filepath): |
805 filepath = os.path.normpath( | 805 filepath = os.path.normpath( |
806 os.path.join(os.path.dirname(filepath), os.readlink(filepath))) | 806 os.path.join(os.path.dirname(filepath), os.readlink(filepath))) |
807 return filepath | 807 return filepath |
808 | 808 |
809 def _syscmd_uname(option, default=''): | 809 def _syscmd_uname(option, default=''): |
810 | 810 |
811 """ Interface to the system's uname command. | 811 """ Interface to the system's uname command. |
812 """ | 812 """ |
813 if sys.platform in ('dos', 'win32', 'win16'): | 813 if sys.platform in ('dos', 'win32', 'win16', 'ios'): |
814 # XXX Others too ? | 814 # XXX Others too ? |
815 return default | 815 return default |
816 try: | 816 try: |
817 f = os.popen('uname %s 2> %s' % (option, DEV_NULL)) | 817 f = os.popen('uname %s 2> %s' % (option, DEV_NULL)) |
818 except (AttributeError, OSError): | 818 except (AttributeError, OSError): |
819 return default | 819 return default |
820 output = f.read().strip() | 820 output = f.read().strip() |
821 rc = f.close() | 821 rc = f.close() |
822 if not output or rc: | 822 if not output or rc: |
823 return default | 823 return default |
824 else: | 824 else: |
825 return output | 825 return output |
826 | 826 |
827 def _syscmd_file(target, default=''): | 827 def _syscmd_file(target, default=''): |
828 | 828 |
829 """ Interface to the system's file command. | 829 """ Interface to the system's file command. |
830 | 830 |
831 The function uses the -b option of the file command to have it | 831 The function uses the -b option of the file command to have it |
832 omit the filename in its output. Follow the symlinks. It returns | 832 omit the filename in its output. Follow the symlinks. It returns |
833 default in case the command should fail. | 833 default in case the command should fail. |
834 | 834 |
835 """ | 835 """ |
836 if sys.platform in ('dos', 'win32', 'win16'): | 836 if sys.platform in ('dos', 'win32', 'win16', 'ios'): |
837 # XXX Others too ? | 837 # XXX Others too ? |
838 return default | 838 return default |
839 target = _follow_symlinks(target) | 839 target = _follow_symlinks(target) |
840 try: | 840 try: |
841 proc = subprocess.Popen(['file', target], | 841 proc = subprocess.Popen(['file', target], |
842 stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | 842 stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
843 | 843 |
844 except (AttributeError, OSError): | 844 except (AttributeError, OSError): |
845 return default | 845 return default |
846 output = proc.communicate()[0].decode('latin-1') | 846 output = proc.communicate()[0].decode('latin-1') |
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1444 return platform | 1444 return platform |
1445 | 1445 |
1446 ### Command line interface | 1446 ### Command line interface |
1447 | 1447 |
1448 if __name__ == '__main__': | 1448 if __name__ == '__main__': |
1449 # Default is to print the aliased verbose platform string | 1449 # Default is to print the aliased verbose platform string |
1450 terse = ('terse' in sys.argv or '--terse' in sys.argv) | 1450 terse = ('terse' in sys.argv or '--terse' in sys.argv) |
1451 aliased = (not 'nonaliased' in sys.argv and not '--nonaliased' in sys.argv) | 1451 aliased = (not 'nonaliased' in sys.argv and not '--nonaliased' in sys.argv) |
1452 print(platform(aliased, terse)) | 1452 print(platform(aliased, terse)) |
1453 sys.exit(0) | 1453 sys.exit(0) |
OLD | NEW |