def get_os_version(): # relace old to better module and pretty name try: import distro distro_name = distro.os_release_attr('name')+" ("+ distro.os_release_attr('version')+")" return distro_name except ImportError: return _get_os_version_lsb_release()
def __init__(self): # First we check whether the Kernel has been compiled as a WSL. if 'microsoft' in check_output(['uname', '-r'], universal_newlines=True).lower(): self._distribution = Distributions.WINDOWS else: try: self._distribution = Distributions(distro.id()) except ValueError: # See <https://www.freedesktop.org/software/systemd/man/os-release.html#ID_LIKE=>. for distro_like in distro.like().split(' '): try: self._distribution = Distributions(distro_like) except ValueError: continue break else: # Well, we didn't match anything so let's fall-back to default `Linux`. self._distribution = Distributions.LINUX # Fetch the colors palette related to this distribution. self._colors_palette = COLOR_DICT[self._distribution] # If `os-release`'s `ANSI_COLOR` option is set, honor it. # See <https://www.freedesktop.org/software/systemd/man/os-release.html#ANSI_COLOR=>. ansi_color = distro.os_release_attr('ansi_color') if ansi_color and Configuration().get( 'colors_palette')['honor_ansi_color']: # Replace each Archey integrated colors by `ANSI_COLOR`. self._colors_palette = len(self._colors_palette) * \ [Colors.escape_code_from_attrs(ansi_color)] # Each class output will be added in the list below afterwards self._results = []
def _guess_chroot(self): """ Guess which chroot is equivalent to this machine """ # FIXME Copr should generate non-specific arch repo dist = self.chroot_config if dist is None or (dist[0] is False) or (dist[1] is False): dist = linux_distribution() # Get distribution architecture distarch = self.base.conf.substitutions['basearch'] if "Fedora" in dist: if "Rawhide" in dist: chroot = ("fedora-rawhide-" + distarch) # workaround for enabling repos in Rawhide when VERSION in os-release # contains a name other than Rawhide elif "rawhide" in os_release_attr( "redhat_support_product_version"): chroot = ("fedora-rawhide-" + distarch) else: chroot = ("fedora-{0}-{1}".format(dist[1], distarch)) elif "Mageia" in dist: # Set the chroot if "Cauldron" in dist: chroot = ("mageia-cauldron-{}".format(distarch)) else: chroot = ("mageia-{0}-{1}".format(dist[1], distarch)) elif "openSUSE" in dist: # Set the chroot if "Tumbleweed" in dist: chroot = ("opensuse-tumbleweed-{}".format(distarch)) else: chroot = ("opensuse-leap-{0}-{1}".format(dist[1], distarch)) else: chroot = ("epel-%s-x86_64" % dist[1].split(".", 1)[0]) return chroot
def _guess_chroot(chroot_config): """ Guess which chroot is equivalent to this machine """ # FIXME Copr should generate non-specific arch repo dist = chroot_config if dist is None or (dist[0] is False) or (dist[1] is False): dist = linux_distribution() if "Fedora" in dist: # x86_64 because repo-file is same for all arch # ($basearch is used) if "Rawhide" in dist: chroot = ("fedora-rawhide-x86_64") # workaround for enabling repos in Rawhide when VERSION in os-release # contains a name other than Rawhide elif "rawhide" in os_release_attr( "redhat_support_product_version"): chroot = ("fedora-rawhide-x86_64") else: chroot = ("fedora-{}-x86_64".format(dist[1])) elif "Mageia" in dist: # Get distribution architecture (Mageia does not use $basearch) distarch = rpm.expandMacro("%{distro_arch}") # Set the chroot if "Cauldron" in dist: chroot = ("mageia-cauldron-{}".format(distarch)) else: chroot = ("mageia-{0}-{1}".format(dist[1], distarch)) elif "openSUSE" in dist: # Get distribution architecture (openSUSE does not use $basearch) distarch = rpm.expandMacro("%{_target_cpu}") # Set the chroot if "Tumbleweed" in dist: chroot = ("opensuse-tumbleweed-{}".format(distarch)) else: chroot = ("opensuse-leap-{0}-{1}".format(dist[1], distarch)) else: chroot = ("epel-%s-x86_64" % dist[1].split(".", 1)[0]) return chroot
def _guess_chroot(chroot_config): """ Guess which chroot is equivalent to this machine """ # FIXME Copr should generate non-specific arch repo dist = chroot_config if dist is None or (dist[0] is False) or (dist[1] is False): dist = linux_distribution() if "Fedora" in dist: # x86_64 because repo-file is same for all arch # ($basearch is used) if "Rawhide" in dist: chroot = ("fedora-rawhide-x86_64") # workaround for enabling repos in Rawhide when VERSION in os-release # contains a name other than Rawhide elif "rawhide" in os_release_attr("redhat_support_product_version"): chroot = ("fedora-rawhide-x86_64") else: chroot = ("fedora-{}-x86_64".format(dist[1])) elif "Mageia" in dist: # Get distribution architecture (Mageia does not use $basearch) distarch = rpm.expandMacro("%{distro_arch}") # Set the chroot if "Cauldron" in dist: chroot = ("mageia-cauldron-{}".format(distarch)) else: chroot = ("mageia-{0}-{1}".format(dist[1], distarch)) elif "openSUSE" in dist: # Get distribution architecture (openSUSE does not use $basearch) distarch = rpm.expandMacro("%{_target_cpu}") # Set the chroot if "Tumbleweed" in dist: chroot = ("opensuse-tumbleweed-{}".format(distarch)) else: chroot = ("opensuse-leap-{0}-{1}".format(dist[1], distarch)) else: chroot = ("epel-%s-x86_64" % dist[1].split(".", 1)[0]) return chroot
def getLinuxVersion(): """ Returns the version of the Linux distribution """ return distro.os_release_attr('pretty_name')
import platform import sys from six.moves import input install_command = None if platform.system().lower() == "linux": pm = { 'redhat': ('sudo yum install', ('python2-pyaudio', 'python3-pyaudio')), 'arch': ('sudo packman -S', ('python2-pyaudio', 'python-pyaudio')), 'gentoo': ('sudo emerge --ask --verbose', ('pyaudio', 'pyaudio')), 'suse': ('sudo zypper install', ('python-PyAudio', 'python3-PyAudio')), 'debian': ('sudo apt-get install', ('python-pyaudio', 'python3-pyaudio')) } distroid = distro.os_release_attr('id_like') for distribution, command in pm.items(): base_command, packages_names = command if distribution in distroid: if len(sys.argv) > 1 and sys.argv[1] == 'py2': python_version = 0 elif len(sys.argv) > 1 and sys.argv[1] == 'py3': python_version = 1 else: print("Usage: python installpyaudio.py (py2/py3)") sys.exit(1) install_command = "{} {}".format(base_command, packages_names[python_version]) elif platform.system().lower() == "Darwin": install_command = 'brew install portaudio'
def get_ansi_color(): """ Simple wrapper to `distro` to return the distribution preferred ANSI color. See <https://www.freedesktop.org/software/systemd/man/os-release.html#ANSI_COLOR=>. """ return distro.os_release_attr('ansi_color') or None
('python2-pyaudio', 'python-pyaudio')), 'gentoo': ( 'sudo emerge --ask --verbose', ('pyaudio', 'pyaudio')), 'suse': ( 'sudo zypper install', ('python-PyAudio', 'python3-PyAudio')), 'debian': ( 'sudo apt-get install', ('python-pyaudio', 'python3-pyaudio'))} distroid = distro.os_release_attr('id_like') for distribution, command in pm.items(): base_command, packages_names = command if distribution in distroid: if len(sys.argv) > 1 and sys.argv[1] == 'py2': python_version = 0 elif len(sys.argv) > 1 and sys.argv[1] == 'py3': python_version = 1 else: print("Usage: python installpyaudio.py (py2/py3)") sys.exit(1) install_command = "{} {}".format( base_command, packages_names[python_version]) elif platform.system().lower() == "darwin": install_command = 'brew install portaudio'
def __init__( self, context: PackagerContext[PackagerOptions], executor: Optional[Executor] = None, ): l = logging.getLogger(__name__) # noqa: VNE001,E741 super().__init__(context, executor) if not self.options.target_platform: plat = distro.linux_distribution(full_distribution_name=False) self.options.target_platform = plat[0].lower() self.options.target_platform_variant = plat[1].partition( '.')[0].lower() # This will likely change once we are building on ubi8 if not self.options.target_platform_base: os_plat_id = distro.os_release_attr('platform_id') plat_id_re = None if os_plat_id is not None: plat_id_re = re.match('^platform:(?P<platform>\S+)', os_plat_id) if plat_id_re is not None: self.options.target_platform_base = plat_id_re.group( 'platform') if self.options.target_platform_base == 'none' or self.options.target_platform_base == '': self.options.target_platform_base = None if self.options.target_platform_variant == 'none' or self.options.target_platform_variant == 'rolling': self.options.target_platform_variant = None if self.options.target_platform == 'centos': if not self.options.target_platform_base: self.options.target_platform_base = 'el' + self.options.target_platform_variant if self.options.target_platform_variant == '7' and self.options.set_origin_flag is None: self.options.set_origin_flag = not self.lief_info.fragile_builder context.lief_info.check_and_whine() self.elfinfo_util = ElfInfoUtil(context, executor=executor, raise_if_ldd_not_found=True) self.strip_util = StripUtil(context, self.elfinfo_util, executor=executor) self.runpath_util = RunpathUtil(context, executor=executor) self.tar_util = TarUtil(context) if not self.runpath_util.tool_state.cmake: raise OSError(errno.ENOENT, 'Could not find cmake tool') if not context.lief_info.lief_usable: l.warning( 'lief functionality not available. Will not be able to remove DT_NEEDED ' 'entries for unneeded libraries, set DF_ORIGIN flags, or set RUNPATH in binaries ' 'without pre-existing values. This can result in additional libraries being ' 'included in the package, and may also result in LD_LIBRARY_PATH needing to be ' 'set to run programs from the package.') if not self.runpath_util.tool_state: l.error( 'Niehter chrpath nor cmake could be found. Without lief, cmake, or chrpath, ' 'runpath will not be set in package binaries. This will result in bad ' 'runpath/rpath values and LD_LIBRARY_PATH needing to be set to run programs ' 'from the package.') self.lib_directives = LibDirectives(context) self.work_dir = self.options.work_dir self.pkg_dir = path.join(self.work_dir, 'pkg') if self.options.tarball_root_dir_name: self.pkg_dir_root = path.join(self.pkg_dir, self.options.tarball_root_dir_name) else: self.pkg_dir_root = self.pkg_dir if path.isabs(self.options.install_bindir): self.pkg_bin_dir = path.join(self.pkg_dir_root, 'bin') else: self.pkg_bin_dir = path.join(self.pkg_dir_root, self.options.install_bindir) if path.isabs(self.options.irods_libdir): l.warning( 'irods-install-libdir is an absolute path. ' 'If iRODS was built with CMAKE_INSTALL_LIBDIR or IRODS_PLUGINS_DIRECTORY ' 'set to an absolute path, userspace packages will likely not function.' ) self.pkg_lib_dir = path.join(self.pkg_dir_root, 'lib') else: self.pkg_lib_dir = path.join(self.pkg_dir_root, self.options.irods_libdir) if path.isabs(self.options.irods_plugsdir): l.warning( 'irods-pluginsdir is an absolute path. ' 'If iRODS was built with CMAKE_INSTALL_LIBDIR or IRODS_PLUGINS_DIRECTORY ' 'set to an absolute path, userspace packages will likely not function.' ) self.pkg_plugs_dir = path.join(self.pkg_lib_dir, 'irods/plugins') else: self.pkg_plugs_dir = path.join(self.pkg_dir_root, self.options.irods_plugsdir) self.icommand_binaries = {} self.icommand_scripts = {} self.irods_runtime_libs = {} self.irods_runtime_plugs = set() # all libs go in here as soon as they've been prepared # soname : path self.prepared_libs = {} # mapping of soname to path for all external libraries we depend on (pre-strip) self.ext_lib_paths = {} # virtual libs (vdso), ld itself, etc. self.ldd_other_libs = set() # libraries encountered during dependency resolution that do not have a directive self.untracked_libs = {}