예제 #1
0
    def __init__(self, software, command):
        # Get the name of the software (usually the first command in string)
        self.software = software
        self.command = command

        # Get platform, os, and version
        if sys.platform.startswith('win32'):
            self.distro = platform.system() + ' ' + platform.release()
            self.version = platform.version()
        elif sys.platform.startswith('linux'):
            self.distro = ld.name(pretty=False)
            self.version = ld.version(pretty=False)
        elif sys.platform.startswith('darwin'):
            self.distro = platform.system() + ' ' + platform.mac_ver()[0]
            self.version = platform.mac_ver()[0]

        # Initialize self.specification
        self.specification = {"cmd": self.command}

        # Use strace to scan system calls and get open/write file_results
        data_file_results = self.get_open_files()
        output_file_results = self.get_open_files(file_type='O_WRONLY')
        software_file_results = self.get_open_files(file_type='software')

        # Get information about the system, software, data files, package manager, and output files
        self.get_project()
        self.get_kernel()
        self.get_hardware()
        self.get_os()
        self.get_software(software_file_results)
        self.get_data(data_file_results)
        self.get_output(output_file_results)
        self.get_environ()
        self.get_pm(data_file_results)
예제 #2
0
    def fetch_system_data(cls) -> None:
        """Fetch info from the host system.

        The function should be the only one that use system calls or programs
        to fetch information from the current system. Overriding this method
        should be enough for example for testing purposes as all the other
        methods use information retrieved in this function.

        The function should set all the class attributes described at the
        beginning of this class.
        """
        # Compute result of uname
        cls.uname = Uname(*platform_uname())

        # Fetch linux distribution info on linux OS
        if cls.uname.system == "Linux":  # linux-only
            import ld

            cls.ld_info = {
                "name": ld.name(),
                "major_version": ld.major_version(),
                "version": ld.version(),
            }

        # Fetch core numbers. Note that the methods does not work
        # on AIX platform but we usually override manually that
        # setting anyway.
        cls.core_number = 1
        try:
            import multiprocessing

            cls.core_number = multiprocessing.cpu_count()
        except Exception:  # defensive code
            e3.log.debug("multiprocessing error", exc_info=True)
            try:
                import psutil

                cls.core_number = psutil.cpu_count()
            except Exception:
                e3.log.debug("psutil error", exc_info=True)

        cls.nis_domain = UNKNOWN

        if sys.platform != "win32":  # windows: no cover
            try:
                import nis
            except ImportError:  # defensive code
                e3.log.debug("cannot import nis", exc_info=True)
                nis = None  # type: ignore

            if nis is not None:
                try:
                    cls.nis_domain = nis.get_default_domain()
                    if not cls.nis_domain:  # defensive code
                        cls.nis_domain = UNKNOWN
                except nis.error:  # defensive code
                    e3.log.debug("nis error", exc_info=True)
예제 #3
0
    def get(self):

        if IS_LINUX:
            return dict(
                id=ld.id(),
                name=ld.name(),
                version=ld.version(),
                like=ld.like(),
                codename=ld.codename(),
                base=ld.base()
            )
예제 #4
0
    def __init__(self, software, command):
        # Get the name of the software (usually the first command in string)
        self.software = software
        self.command = command

        # Get platform, os, and version
        if sys.platform.startswith('win32'):
            self.distro = platform.system() + ' ' + platform.release()
            self.version = platform.version()
        elif sys.platform.startswith('linux'):
            self.distro = ld.name(pretty=False)
            self.version = ld.version(pretty=False)
        elif sys.platform.startswith('darwin'):
            self.distro = platform.system() + ' ' + platform.mac_ver()[0]
            self.version = platform.mac_ver()[0]

        # Initialize self.specification
        self.specification = {
            "cmd": self.command
        }

        # Use strace to scan system calls and get open/write file_results
        data_file_results = self.get_open_files()
        output_file_results = self.get_open_files(file_type='O_WRONLY')
        software_file_results = self.get_open_files(file_type='software')

        # Get information about the system, software, data files, package manager, and output files
        self.get_project()
        self.get_kernel()
        self.get_hardware()
        self.get_os()
        self.get_software(software_file_results)
        self.get_data(data_file_results)
        self.get_output(output_file_results)
        self.get_environ()
        self.get_pm(data_file_results)
예제 #5
0
    def fetch_system_data(cls):
        """Fetch info from the host system.

        The function should be the only one that use system calls or programs
        to fetch information from the current system. Overriding this method
        should be enough for example for testing purposes as all the other
        methods use information retrieved in this function.

        The function should set all the class attributes described at the
        beginning of this class.
        """
        # Compute result of uname
        cls.uname = Uname(*platform_uname())

        # Fetch linux distribution info on linux OS
        if cls.uname.system == 'Linux':  # linux-only
            import ld
            cls.ld_info = {
                'name': ld.name(),
                'major_version': ld.major_version(),
                'version': ld.version()
            }

        # Fetch network interfaces
        try:
            from netifaces import interfaces, ifaddresses, address_families
            # use string for address families instead of integers which are
            # system dependents
            cls.network_ifs = {
                itf: {
                    address_families[k]: v
                    for k, v in ifaddresses(itf).iteritems()
                }
                for itf in interfaces()
            }
        except Exception:  # defensive code
            e3.log.debug('cannot get network info', exc_info=True)
            cls.network_ifs = None

        # Fetch core numbers. Note that the methods does not work
        # on AIX platform but we usually override manually that
        # setting anyway.
        cls.core_number = 1
        try:
            import multiprocessing
            cls.core_number = multiprocessing.cpu_count()
        except Exception:  # defensive code
            e3.log.debug('multiprocessing error', exc_info=True)
            try:
                import psutil
                cls.core_number = psutil.cpu_count()
            except Exception:
                e3.log.debug('psutil error', exc_info=True)

        cls.nis_domain = UNKNOWN

        if sys.platform != 'win32':  # windows: no cover
            try:
                import nis
            except ImportError:  # defensive code
                e3.log.debug('cannot import nis', exc_info=True)
                nis = None

            if nis is not None:
                try:
                    cls.nis_domain = nis.get_default_domain()
                    if not cls.nis_domain:  # defensive code
                        cls.nis_domain = UNKNOWN
                except nis.error:  # defensive code
                    e3.log.debug('nis error', exc_info=True)
예제 #6
0
#!/usr/bin/env python

import ld

print 'os_release_info: {0}'.format(ld.os_release_info())
print 'lsb_release_info: {0}'.format(ld.lsb_release_info())
print 'distro_release_info: {0}'.format(ld.distro_release_info())
print 'id: {0}'.format(ld.id())
print 'name: {0}'.format(ld.name())
print 'name_pretty: {0}'.format(ld.name(True))
print 'version: {0}'.format(ld.version())
print 'version_pretty: {0}'.format(ld.version(True))
print 'like: {0}'.format(ld.like())
print 'codename: {0}'.format(ld.codename())
print 'linux_distribution_full: {0}'.format(ld.linux_distribution())
print 'linux_distribution: {0}'.format(ld.linux_distribution(False))
print 'major_version: {0}'.format(ld.major_version())
print 'minor_version: {0}'.format(ld.minor_version())
print 'build_number: {0}'.format(ld.build_number())
예제 #7
0
    def test_global(self):
        # Because the module-level functions use the module-global
        # LinuxDistribution instance, it would influence the tested
        # code too much if we mocked that in order to use the distro
        # specific release files. Instead, we let the functions use
        # the release files of the distro this test runs on, and
        # compare the result of the global functions with the result
        # of the methods on the global LinuxDistribution object.

        self.assertEqual(ld.id(), MODULE_LDI.id())

        self.assertEqual(ld.name(), MODULE_LDI.name(pretty=False))
        self.assertEqual(ld.name(pretty=False), MODULE_LDI.name())
        self.assertEqual(ld.name(pretty=True), MODULE_LDI.name(pretty=True))

        self.assertEqual(ld.version(), MODULE_LDI.version(pretty=False))
        self.assertEqual(ld.version(pretty=False), MODULE_LDI.version())
        self.assertEqual(ld.version(pretty=True),
                         MODULE_LDI.version(pretty=True))
        self.assertEqual(ld.version(), MODULE_LDI.version(best=False))
        self.assertEqual(ld.version(best=False), MODULE_LDI.version())
        self.assertEqual(ld.version(best=True), MODULE_LDI.version(best=True))

        self.assertEqual(ld.version_parts(),
                         MODULE_LDI.version_parts(best=False))
        self.assertEqual(ld.version_parts(best=False),
                         MODULE_LDI.version_parts())
        self.assertEqual(ld.version_parts(best=True),
                         MODULE_LDI.version_parts(best=True))

        self.assertEqual(ld.major_version(),
                         MODULE_LDI.major_version(best=False))
        self.assertEqual(ld.major_version(best=False),
                         MODULE_LDI.major_version())
        self.assertEqual(ld.major_version(best=True),
                         MODULE_LDI.major_version(best=True))

        self.assertEqual(ld.minor_version(),
                         MODULE_LDI.minor_version(best=False))
        self.assertEqual(ld.minor_version(best=False),
                         MODULE_LDI.minor_version())
        self.assertEqual(ld.minor_version(best=True),
                         MODULE_LDI.minor_version(best=True))

        self.assertEqual(ld.build_number(),
                         MODULE_LDI.build_number(best=False))
        self.assertEqual(ld.build_number(best=False),
                         MODULE_LDI.build_number())
        self.assertEqual(ld.build_number(best=True),
                         MODULE_LDI.build_number(best=True))

        self.assertEqual(ld.like(), MODULE_LDI.like())

        self.assertEqual(ld.codename(), MODULE_LDI.codename())

        self.assertEqual(
            ld.linux_distribution(),
            MODULE_LDI.linux_distribution(full_distribution_name=True))
        self.assertEqual(ld.linux_distribution(full_distribution_name=True),
                         MODULE_LDI.linux_distribution())
        self.assertEqual(
            ld.linux_distribution(full_distribution_name=False),
            MODULE_LDI.linux_distribution(full_distribution_name=False))

        self.assertEqual(ld.os_release_info(), MODULE_LDI.os_release_info())

        self.assertEqual(ld.lsb_release_info(), MODULE_LDI.lsb_release_info())

        self.assertEqual(ld.distro_release_info(),
                         MODULE_LDI.distro_release_info())

        self.assertEqual(ld.info(), MODULE_LDI.info())
예제 #8
0
파일: test_ld.py 프로젝트: digideskio/ld
    def test_global(self):
        # Because the module-level functions use the module-global
        # LinuxDistribution instance, it would influence the tested
        # code too much if we mocked that in order to use the distro
        # specific release files. Instead, we let the functions use
        # the release files of the distro this test runs on, and
        # compare the result of the global functions with the result
        # of the methods on the global LinuxDistribution object.

        self.assertEqual(ld.id(),
            MODULE_LDI.id())

        self.assertEqual(ld.name(),
            MODULE_LDI.name(pretty=False))
        self.assertEqual(ld.name(pretty=False),
            MODULE_LDI.name())
        self.assertEqual(ld.name(pretty=True),
            MODULE_LDI.name(pretty=True))

        self.assertEqual(ld.version(),
            MODULE_LDI.version(pretty=False))
        self.assertEqual(ld.version(pretty=False),
            MODULE_LDI.version())
        self.assertEqual(ld.version(pretty=True),
            MODULE_LDI.version(pretty=True))
        self.assertEqual(ld.version(),
            MODULE_LDI.version(best=False))
        self.assertEqual(ld.version(best=False),
            MODULE_LDI.version())
        self.assertEqual(ld.version(best=True),
            MODULE_LDI.version(best=True))

        self.assertEqual(ld.version_parts(),
            MODULE_LDI.version_parts(best=False))
        self.assertEqual(ld.version_parts(best=False),
            MODULE_LDI.version_parts())
        self.assertEqual(ld.version_parts(best=True),
            MODULE_LDI.version_parts(best=True))

        self.assertEqual(ld.major_version(),
            MODULE_LDI.major_version(best=False))
        self.assertEqual(ld.major_version(best=False),
            MODULE_LDI.major_version())
        self.assertEqual(ld.major_version(best=True),
            MODULE_LDI.major_version(best=True))

        self.assertEqual(ld.minor_version(),
            MODULE_LDI.minor_version(best=False))
        self.assertEqual(ld.minor_version(best=False),
            MODULE_LDI.minor_version())
        self.assertEqual(ld.minor_version(best=True),
            MODULE_LDI.minor_version(best=True))

        self.assertEqual(ld.build_number(),
            MODULE_LDI.build_number(best=False))
        self.assertEqual(ld.build_number(best=False),
            MODULE_LDI.build_number())
        self.assertEqual(ld.build_number(best=True),
            MODULE_LDI.build_number(best=True))

        self.assertEqual(ld.like(),
            MODULE_LDI.like())

        self.assertEqual(ld.codename(),
            MODULE_LDI.codename())

        self.assertEqual(ld.linux_distribution(),
            MODULE_LDI.linux_distribution(full_distribution_name=True))
        self.assertEqual(ld.linux_distribution(full_distribution_name=True),
            MODULE_LDI.linux_distribution())
        self.assertEqual(ld.linux_distribution(full_distribution_name=False),
            MODULE_LDI.linux_distribution(full_distribution_name=False))

        self.assertEqual(ld.os_release_info(),
            MODULE_LDI.os_release_info())

        self.assertEqual(ld.lsb_release_info(),
            MODULE_LDI.lsb_release_info())

        self.assertEqual(ld.distro_release_info(),
            MODULE_LDI.distro_release_info())

        self.assertEqual(ld.info(),
            MODULE_LDI.info())
예제 #9
0
파일: platform.py 프로젝트: AdaCore/e3-core
    def fetch_system_data(cls):
        """Fetch info from the host system.

        The function should be the only one that use system calls or programs
        to fetch information from the current system. Overriding this method
        should be enough for example for testing purposes as all the other
        methods use information retrieved in this function.

        The function should set all the class attributes described at the
        beginning of this class.
        """
        # Compute result of uname
        cls.uname = Uname(*platform_uname())

        # Fetch linux distribution info on linux OS
        if cls.uname.system == 'Linux':
            import ld
            cls.ld_info = {'name': ld.name(),
                           'major_version': ld.major_version(),
                           'version': ld.version()}

        # Fetch network interfaces
        try:
            from netifaces import interfaces, ifaddresses, address_families
            # use string for address families instead of integers which are
            # system dependents
            cls.network_ifs = {itf: {address_families[k]: v
                                     for k, v in ifaddresses(itf).iteritems()}
                               for itf in interfaces()}
        except Exception:
            e3.log.debug('cannot get network info', exc_info=True)
            cls.network_ifs = None

        # Fetch core numbers. Note that the methods does not work
        # on AIX platform but we usually override manually that
        # setting anyway.
        cls.core_number = 1
        try:
            import multiprocessing
            cls.core_number = multiprocessing.cpu_count()
        except Exception:
            e3.log.debug('multiprocessing error', exc_info=True)
            try:
                import psutil
                cls.core_number = psutil.cpu_count()
            except Exception:
                e3.log.debug('psutil error', exc_info=True)
                pass

        cls.nis_domain = UNKNOWN

        try:
            import nis
        except ImportError:
            e3.log.debug('cannot import nis', exc_info=True)
            nis = None

        if nis is not None:
            try:
                cls.nis_domain = nis.get_default_domain()
                if not cls.nis_domain:
                    cls.nis_domain = UNKNOWN
            except nis.error:
                e3.log.debug('nis error', exc_info=True)
                pass
예제 #10
0
#!/usr/bin/env python

import ld

print "os_release_info: {0}".format(ld.os_release_info())
print "lsb_release_info: {0}".format(ld.lsb_release_info())
print "distro_release_info: {0}".format(ld.distro_release_info())
print "id: {0}".format(ld.id())
print "name: {0}".format(ld.name())
print "name_pretty: {0}".format(ld.name(True))
print "version: {0}".format(ld.version())
print "version_pretty: {0}".format(ld.version(True))
print "like: {0}".format(ld.like())
print "codename: {0}".format(ld.codename())
print "linux_distribution_full: {0}".format(ld.linux_distribution())
print "linux_distribution: {0}".format(ld.linux_distribution(False))
print "major_version: {0}".format(ld.major_version())
print "minor_version: {0}".format(ld.minor_version())
print "build_number: {0}".format(ld.build_number())
예제 #11
0
    def get(self):

        if IS_LINUX:
            return dict(
                id=ld.id(), name=ld.name(), version=ld.version(), like=ld.like(), codename=ld.codename(), base=ld.base()
            )