#!/usr/bin/env python3 """This code determines the astro-wise os/machine name""" __version__ = 'Revision: GIT.21' 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() # check for microversion if this is centos if distribution[0] == 'centos': if distribution[1].find('.') == -1: for line in open('/etc/redhat-release'): distribution = (distribution[0], '.'.join(line.split()[3].split('.')[:2])) 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[0] == 'centos' and distribution[1].find('.') == -1: try: line = open('/etc/redhat-release').readline() version = line.split()[3] version = '.'.join(version.split('.')[:2]) distribution = ('centos', version) except IOError: pass except ValueError: 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)