#!/usr/bin/env python3 """This code determines the astro-wise os/machine name""" __version__ = 'Revision: GIT.20' def distro_from_os_release(): """determine the distribution from the file /etc/os-release""" dist_id = '' dist_version = '' try: for line in open('/etc/os-release'): name, value = line.split('=') value = value.strip().strip('"').strip("'") if name == 'ID': dist_id = value elif name == 'VERSION_ID': dist_version = value except IOError: pass except ValueError: pass return dist_id, dist_version def targetplatform(): """gets the astro-wise name of target platform""" import os distribution = distro_from_os_release() system = os.uname()[0] machine = os.uname()[-1] if distribution == ('', ''): try: import distro except (ImportError, RuntimeError): pass else: distribution = (distro.id(), distro.version()) if distribution == ('', ''): result = (system, machine) else: result = (system, '-'.join(distribution), machine) return '-'.join(result).replace('/', '.') if __name__ == '__main__': import sys print(targetplatform()) sys.exit(0)