Ejemplo n.º 1
0
    def __init__(self):
        _kernel = utf8_decode(check_output(KERNEL_COMMAND)).strip()
        if _kernel != SUPPORTED_KERNEL:
            raise OSError(
                "Invalid kernel found: %s. Expected %s." % (
                    _kernel,
                    SUPPORTED_KERNEL,
                )
            )

        try:
            self.dist, self.codename = tuple(
                utf8_decode(s).strip()
                for s in check_output(RELEASE_COMMAND).split()
            )
        except OSError:
            # Fall back to using lsb-release info file if lsb_release command
            # is not available. e.g. Ubuntu minimal (core, docker image).
            try:
                with open(RELEASE_FILE, 'rU') as release_file:
                    try:
                        lsb_info = dict(
                            line.strip().split('=')
                            for line in release_file.readlines()
                        )
                    except ValueError:
                        raise OSError(
                            "Unexpected release file format found in %s." % RELEASE_FILE
                        )

                    try:
                        self.dist = lsb_info['DISTRIB_ID']
                        self.codename = lsb_info['DISTRIB_CODENAME']
                    except KeyError:
                        raise OSError(
                            "Expected distribution keys missing from %s." % RELEASE_FILE
                        )

            except (IOError, OSError):
                raise OSError((
                    "Unable to determine system distribution. "
                    "%s is required." % SUPPORTED_DISTRIBUTION_TYPE
                ))

        if self.dist != SUPPORTED_DISTRIBUTION_TYPE:
            raise OSError(
                "%s distributions are not supported. %s is required." % (
                    self.dist, SUPPORTED_DISTRIBUTION_TYPE
                )
            )

        self.arch = LAUNCHPAD_ARCH_32
        if utf8_decode(check_output(MACHINE_COMMAND).strip()) == 'x86_64':
            self.arch = LAUNCHPAD_ARCH_64
Ejemplo n.º 2
0
    def __init__(self):
        _kernel = utf8_decode(check_output(KERNEL_COMMAND)).strip()
        if _kernel != SUPPORTED_KERNEL:
            raise OSError("Invalid kernel found: %s. Expected %s." % (
                _kernel,
                SUPPORTED_KERNEL,
            ))

        try:
            self.dist, self.codename = tuple(
                utf8_decode(s).strip()
                for s in check_output(RELEASE_COMMAND).split())
        except OSError:
            # Fall back to using lsb-release info file if lsb_release command
            # is not available. e.g. Ubuntu minimal (core, docker image).
            try:
                with open(RELEASE_FILE, 'rU') as release_file:
                    try:
                        lsb_info = dict(line.strip().split('=')
                                        for line in release_file.readlines())
                    except ValueError:
                        raise OSError(
                            "Unexpected release file format found in %s." %
                            RELEASE_FILE)

                    try:
                        self.dist = lsb_info['DISTRIB_ID']
                        self.codename = lsb_info['DISTRIB_CODENAME']
                    except KeyError:
                        raise OSError(
                            "Expected distribution keys missing from %s." %
                            RELEASE_FILE)

            except (IOError, OSError):
                raise OSError(
                    ("Unable to determine system distribution. "
                     "%s is required." % SUPPORTED_DISTRIBUTION_TYPE))

        if self.dist != SUPPORTED_DISTRIBUTION_TYPE:
            raise OSError(
                "%s distributions are not supported. %s is required." %
                (self.dist, SUPPORTED_DISTRIBUTION_TYPE))

        self.arch = LAUNCHPAD_ARCH_32
        if utf8_decode(check_output(MACHINE_COMMAND).strip()) == 'x86_64':
            self.arch = LAUNCHPAD_ARCH_64
Ejemplo n.º 3
0
    def get_arch():
        """Return architecture information in Launchpad format"""
        if utf8_decode(check_output(["uname", "-m"]).strip()) == 'x86_64':
            return LAUNCHPAD_ARCH_64

        return LAUNCHPAD_ARCH_32
Ejemplo n.º 4
0
 def get_release():
     """Call system for Ubuntu release information"""
     return [
         utf8_decode(s).strip()
         for s in check_output(["lsb_release", "-ics"]).split()
     ]
Ejemplo n.º 5
0
def get_arch():
    """Return architecture information in Launchpad format"""
    if utf8_decode(check_output(["uname", "-m"]).strip()) == u'x86_64':
        return u'amd64'
    return u'i386'