Exemplo n.º 1
0
    def rez_bin_path(self):
        """Get path containing rez binaries, or None if no binaries are
        available, or Rez is not a production install.
        """
        binpath = None
        if sys.argv and sys.argv[0]:
            executable = sys.argv[0]
            path = which("rezolve",
                         env={
                             "PATH": os.path.dirname(executable),
                             "PATHEXT": os.environ.get("PATHEXT", "")
                         })
            binpath = os.path.dirname(path) if path else None

        # TODO: improve this, could still pick up non-production 'rezolve'
        if not binpath:
            path = which("rezolve")
            if path:
                binpath = os.path.dirname(path)

        if binpath:
            validation_file = os.path.join(binpath, ".rez_production_install")
            if os.path.exists(validation_file):
                return os.path.realpath(binpath)

        return None
Exemplo n.º 2
0
 def find_executable(cls, name):
     exe = which(name)
     if not exe:
         raise ReleaseVCSError(
             "Couldn't find executable '%s' for VCS '%s'" %
             (name, cls.name()))
     return exe
Exemplo n.º 3
0
    def setUpClass(cls):
        TempdirMixin.setUpClass()
        cls.settings = dict()
        cls.tempdir = tempfile.mkdtemp()

        python = which("python")
        assert python, "No Python found"

        result = subprocess.check_output(
            [python, "--version"],
            universal_newlines=True,
            stderr=subprocess.STDOUT,
        )
        _, version = result.rstrip().split(" ", 1)
        version = version.split()[-1]
        version = int(version[0])

        with make_package("python", cls.tempdir) as maker:
            PATH = os.path.dirname(python).replace("\\", "/")
            maker.version = str(version)
            maker.commands = "\n".join(["env.PATH.prepend(r'%s')" % PATH])

        cls.context = ResolvedContext(["python"], package_paths=[cls.tempdir])

        cls.python_version = version
Exemplo n.º 4
0
    def _editor(self):
        ed = os.getenv("EDITOR")
        if ed is None:
            from rez.util import which

            ed = which("vi", "vim", "xdg-open")
        return ed
Exemplo n.º 5
0
    def _terminal_emulator_command(self):
        term = which("x-terminal-emulator", "xterm")
        if term is None:
            return None

        term = os.path.basename(term)
        if term == "x-terminal-emulator":
            return "%s --noclose -e" % term
        else:
            return "%s -hold -e" % term
Exemplo n.º 6
0
    def _terminal_emulator_command(self):
        term = which("x-terminal-emulator", "xterm")
        if term is None:
            return None

        term = os.path.basename(term)
        if term == "x-terminal-emulator":
            return "%s --noclose -e" % term
        else:
            return "%s -hold -e" % term
Exemplo n.º 7
0
    def test_rez_env_output(self):
        # here we are making sure that running a command via rez-env prints
        # exactly what we expect.
        echo_cmd = which("echo")
        if not echo_cmd:
            print("\nskipping test, 'echo' command not found.")
            return

        cmd = [os.path.join(system.rez_bin_path, "rez-env"), "--", "echo", "hey"]
        process = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        sh_out, _ = process.communicate()
        out = str(sh_out).strip()
        self.assertEqual(out, "hey")
Exemplo n.º 8
0
    def test_rez_env_output(self):
        # here we are making sure that running a command via rez-env prints
        # exactly what we expect.
        echo_cmd = which("echo")
        if not echo_cmd:
            print "\nskipping test, 'echo' command not found."
            return

        cmd = [os.path.join(system.rez_bin_path, "rez-env"), "--", "echo", "hey"]
        process = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        sh_out, _ = process.communicate()
        out = str(sh_out).strip()
        self.assertEqual(out, "hey")
Exemplo n.º 9
0
    def rez_bin_path(self):
        """Get path containing rez binaries, or None if no binaries are
        available, or Rez is not a production install.
        """
        binpath = None
        if sys.argv and sys.argv[0]:
            executable = sys.argv[0]
            path = which("rezolve", env={"PATH": os.path.dirname(executable), "PATHEXT": os.environ.get("PATHEXT", "")})
            binpath = os.path.dirname(path) if path else None

        # TODO: improve this, could still pick up non-production 'rezolve'
        if not binpath:
            path = which("rezolve")
            if path:
                binpath = os.path.dirname(path)

        if binpath:
            validation_file = os.path.join(binpath, ".rez_production_install")
            if os.path.exists(validation_file):
                return os.path.realpath(binpath)

        return None
Exemplo n.º 10
0
    def test_rez_env_output(self):
        # TODO: this test does not run on Windows using the CMD shell as it
        # does not accept commands from stdin.  Rather than explicitly skipping
        # the test (via the decorator) perhaps we should check for startup
        # capabilities as the other tests do.
        from rez.vendor.sh import sh

        # here we are making sure that running a command via rez-env prints
        # exactly what we expect. We use 'sh' because subprocess strips special
        # characters such as color codes - we want to ensure that the output
        # EXACTLY matches the output of the command being run.
        echo_cmd = which("echo")
        if not echo_cmd:
            print "\nskipping test, 'echo' command not found."
            return

        cmd = sh.Command(os.path.join(system.rez_bin_path, "rez-env"))
        sh_out = cmd(["--", "echo", "hey"])
        out = str(sh_out).strip()
        self.assertEqual(out, "hey")
Exemplo n.º 11
0
    def test_rez_env_output(self):
        # TODO: this test does not run on Windows using the CMD shell as it
        # does not accept commands from stdin.  Rather than explicitly skipping
        # the test (via the decorator) perhaps we should check for startup
        # capabilities as the other tests do.
        from rez.vendor.sh import sh

        # here we are making sure that running a command via rez-env prints
        # exactly what we expect. We use 'sh' because subprocess strips special
        # characters such as color codes - we want to ensure that the output
        # EXACTLY matches the output of the command being run.
        echo_cmd = which("echo")
        if not echo_cmd:
            print "\nskipping test, 'echo' command not found."
            return

        cmd = sh.Command(os.path.join(system.rez_bin_path, "rez-env"))
        sh_out = cmd(["--", "echo", "hey"])
        out = str(sh_out).strip()
        self.assertEqual(out, "hey")
Exemplo n.º 12
0
def find_exe(name, filepath=None):
    """Find an executable.

    Args:
        name: Name of the program, eg 'python'.
        filepath: Path to executable, a search is performed if None.

    Returns:
        Path to the executable if found, otherwise an error is raised.
    """
    if filepath:
        if not os.path.exists(filepath):
            open(filepath)  # raise IOError
        elif not os.path.isfile(filepath):
            raise RezBindError("not a file: %s" % filepath)
    else:
        filepath = which(name)
        if not filepath:
            raise RezBindError("could not find executable: %s" % name)

    return filepath
Exemplo n.º 13
0
def find_exe(name, filepath=None):
    """Find an executable.

    Args:
        name: Name of the program, eg 'python'.
        filepath: Path to executable, a search is performed if None.

    Returns:
        Path to the executable if found, otherwise an error is raised.
    """
    if filepath:
        if not os.path.exists(filepath):
            open(filepath)  # raise IOError
        elif not os.path.isfile(filepath):
            raise RezBindError("not a file: %s" % filepath)
    else:
        filepath = which(name)
        if not filepath:
            raise RezBindError("could not find executable: %s" % name)

    return filepath
Exemplo n.º 14
0
    def execute_command(self, cmd_name, cmd_arguments, user, errors, env=None):
        def _err(msg):
            errors.append(msg)
            if self.settings.print_error:
                print >> sys.stderr, msg

        kwargs = {}
        if env:
            kwargs["env"] = env

        def _execute(commands):
            process = Popen(commands, stdout=PIPE, stderr=STDOUT, **kwargs)
            stdout, _ = process.communicate()

            if process.returncode != 0:
                msg = "command failed:\n%s" % stdout
                _err(msg)
                return False
            if self.settings.print_output:
                print stdout.strip()
            return True

        if not os.path.isfile(cmd_name):
            cmd_full_path = which(cmd_name)
        else:
            cmd_full_path = cmd_name
        if not cmd_full_path:
            msg = "%s: command not found" % cmd_name
            _err(msg)
            return False

        cmds = [cmd_full_path] + (cmd_arguments or [])
        if user == 'root':
            cmds = ['sudo'] + cmds
            return _execute(cmds)
        elif user and user != getpass.getuser():
            raise NotImplementedError  # TODO
        else:
            return _execute(cmds)
Exemplo n.º 15
0
    def execute_command(self, cmd_name, cmd_arguments, user, errors, env=None):
        def _err(msg):
            errors.append(msg)
            if self.settings.print_error:
                print(msg, file=sys.stderr)

        kwargs = {}
        if env:
            kwargs["env"] = env

        def _execute(commands):
            process = Popen(commands, stdout=PIPE, stderr=STDOUT, **kwargs)
            stdout, _ = process.communicate()

            if process.returncode != 0:
                msg = "command failed:\n%s" % stdout
                _err(msg)
                return False
            if self.settings.print_output:
                print(stdout.strip())
            return True

        if not os.path.isfile(cmd_name):
            cmd_full_path = which(cmd_name)
        else:
            cmd_full_path = cmd_name
        if not cmd_full_path:
            msg = "%s: command not found" % cmd_name
            _err(msg)
            return False

        cmds = [cmd_full_path] + (cmd_arguments or [])
        if user == 'root':
            cmds = ['sudo'] + cmds
            return _execute(cmds)
        elif user and user != getpass.getuser():
            raise NotImplementedError  # TODO
        else:
            return _execute(cmds)
Exemplo n.º 16
0
 def _difftool(self):
     from rez.util import which
     return which("meld", "diff")
Exemplo n.º 17
0
 def _image_viewer(self):
     return which("xdg-open", "eog", "kview")
Exemplo n.º 18
0
 def _image_viewer(self):
     from rez.util import which
     return which("xdg-open", "eog", "kview")
Exemplo n.º 19
0
Arquivo: shells.py Projeto: rvsiy/rez
 def find_executable(cls, name):
     exe = which(name)
     if not exe:
         raise RuntimeError("Couldn't find executable '%s'." % name)
     return exe
Exemplo n.º 20
0
 def _image_viewer(self):
     return which("xdg-open", "eog", "kview")
Exemplo n.º 21
0
 def _editor(self):
     ed = os.getenv("EDITOR")
     if ed is None:
         from rez.util import which
         ed = which("vi", "vim", "xdg-open")
     return ed
Exemplo n.º 22
0
 def _editor(self):
     ed = os.getenv("EDITOR")
     if ed is None:
         ed = which("xdg-open", "vim", "vi")
     return ed
Exemplo n.º 23
0
 def _difftool(self):
     return which("kdiff3", "meld", "diff")
Exemplo n.º 24
0
 def _difftool(self):
     from rez.util import which
     return which("meld", "diff")
Exemplo n.º 25
0
 def find_executable(cls, name):
     exe = which(name)
     if not exe:
         raise ReleaseVCSError("Couldn't find executable '%s' for VCS '%s'"
                               % (name, cls.name()))
     return exe
Exemplo n.º 26
0
 def _difftool(self):
     # although meld would be preferred, fc ships with all Windows versions back to DOS
     from rez.util import which
     return which("meld", "fc")
Exemplo n.º 27
0
 def _image_viewer(self):
     from rez.util import which
     return which("xdg-open", "eog", "kview")
Exemplo n.º 28
0
 def find_executable(cls, name):
     exe = which(name)
     if not exe:
         raise RuntimeError("Couldn't find executable '%s'." % name)
     return exe
Exemplo n.º 29
0
 def _editor(self):
     ed = os.getenv("EDITOR")
     if ed is None:
         ed = which("xdg-open", "vim", "vi")
     return ed
Exemplo n.º 30
0
 def _difftool(self):
     return which("kdiff3", "meld", "diff")
Exemplo n.º 31
0
 def _difftool(self):
     # although meld would be preferred, fc ships with all Windows versions back to DOS
     from rez.util import which
     return which("meld", "fc")
Exemplo n.º 32
0
    def _patch_libs_linux(self):
        """Fix elfs that reference elfs outside of the bundle.

        Finds elf files, inspects their runpath/rpath, then looks to see if
        those paths map to packages also inside the bundle. If they do, those
        rpath entries are remapped to form "$ORIGIN/{relative-path}".
        """
        from rez.utils.elf import get_rpaths, patch_rpaths

        elfs = self._find_files(executable=True,
                                filename_substrs=(".so", ".so.", ".so-"))

        if not elfs:
            self._info("No elfs found, thus no patching performed")
            return

        readelf = which("readelf")
        patchelf = which("patchelf")

        if not readelf:
            self._warning(
                "Could not patch %d files: cannot find 'readelf' utility.",
                len(elfs))
            return

        for elf in elfs:
            try:
                rpaths = get_rpaths(elf)
            except RuntimeError as e:

                # there can be lots of false positives (not an elf) due to
                # executable shebanged scripts. Ignore these.
                #
                msg = str(e)
                if "Not an ELF file" in msg or \
                        "Failed to read file header" in msg:
                    continue

                self._warning(msg)
                continue

            if not rpaths:
                continue  # nothing to do

            # remap rpath entries where equivalent bundled path is found
            new_rpaths = []

            for rpath in rpaths:

                # leave relpaths as-is, can't do sensible remapping.
                # Note that os.path.isabs('$ORIGIN/...') equates to False
                #
                if not os.path.isabs(rpath):
                    new_rpaths.append(rpath)
                    continue

                new_rpath = None

                for (src_variant,
                     dest_variant) in self.copied_variants.values():
                    if is_subdirectory(rpath, src_variant.root):

                        # rpath is within the payload of another package that
                        # is present in the bundle. Here we remap to
                        # '$ORIGIN/{relpath}' form
                        #
                        relpath = os.path.relpath(rpath, src_variant.root)
                        new_rpath_abs = os.path.join(dest_variant.root,
                                                     relpath)

                        elfpath = os.path.dirname(elf)
                        new_rel_rpath = os.path.relpath(new_rpath_abs, elfpath)

                        new_rpath = os.path.join("$ORIGIN", new_rel_rpath)
                        break

                if new_rpath:
                    new_rpaths.append(new_rpath)
                    self._info("Remapped rpath %s in file %s to %s", rpath,
                               elf, new_rpath)
                else:
                    new_rpaths.append(rpath)

            if new_rpaths == rpaths:
                self._info("Left rpaths unchanged in %s: [%s]", elf,
                           ':'.join(rpaths))
                continue

            # use patchelf to replace rpath
            if not patchelf:
                self._warning(
                    "Could not patch rpaths in %s from [%s] to [%s]: cannot "
                    "find 'patchelf' utility.", elf, ':'.join(rpaths),
                    ':'.join(new_rpaths))
                continue

            try:
                patch_rpaths(elf, new_rpaths)
            except RuntimeError as e:
                self._warning(str(e))
                continue

            self._info("Patched rpaths in file %s from [%s] to [%s]", elf,
                       ':'.join(rpaths), ':'.join(new_rpaths))