示例#1
0
    def _updateWithUserOverrides(self, project_overrides=None):
        self._userEnviron = self._origStartupEnv.copy()
        
        # now overwrite with the userEnvironment preference
        prefs = components.classes["@activestate.com/koPrefService;1"]\
                .getService(components.interfaces.koIPrefService).prefs
        _environUtils = components.classes[
            "@activestate.com/koEnvironUtils;1"] \
            .getService(components.interfaces.koIEnvironUtils)
        havePATHOverride = False
        all_overrides = [prefs.getString("userEnvironmentStartupOverride", ""),
                         project_overrides]
        for overrides in all_overrides:
            if overrides:
                env = re.split('\r?\n|\r', overrides, re.U)
                if not env: env = []
                sysenv = self.GetEnvironmentStrings()
                newenv = _environUtils.MergeEnvironmentStrings(sysenv, env)
                if not newenv:
                    return
                self._userEnviron = {}
                for line in newenv:
                    item =  _ParseBashEnvStr(line)
                    if item:
                        if item[0] == "PATH":
                            havePATHOverride = True
                        self._userEnviron[item[0]] = item[1]
        
        # For some platforms we implicitly add some common dirs to the PATH.
        # It is common, for example, on Mac OS X for a Komodo user to have
        # "/usr/local/bin" on the PATH in their shell, but not in Komodo
        # because Mac applications don't start from a login shell. This is
        # confusing to users. (Bug 80656.)
        implicitPathAdditionsFromPlat = {
            "darwin": ["/usr/local/bin",
                       "/opt/local/bin"],  # Mac Ports
            "linux2": ["/usr/local/bin"],
        }
        if (not havePATHOverride
            and sys.platform in implicitPathAdditionsFromPlat
            and prefs.getBoolean("userEnvironmentAllowImplicitPATHAdditions", True)):
            implicitPathAdditions = implicitPathAdditionsFromPlat[sys.platform]
            path = self._userEnviron.get("PATH", "").split(os.pathsep)
            if sys.platform in ("darwin", "win32"):
                comparePath = set(p.lower() for p in path) # case-insensitive comparison
            else:
                comparePath = set(path)
            for ipa in implicitPathAdditions:
                compareIpa = (sys.platform in ("darwin", "win32")
                              and ipa.lower() or ipa)
                if compareIpa not in comparePath:
                    path.append(ipa)
            if path:
                self._userEnviron["PATH"] = os.pathsep.join(path)

        # we must reset this in order for some services to pick up on the
        # changes (eg. SCC services)
        koprocessutils.resetUserEnv()
示例#2
0
    def UpdateFromShell(self, shell):
        """Update the internal user environment cache from the given shell.

        Returns None is successful, otherwise returns an error message.
        """
        import koprocessutils
        assert sys.platform != "win32", "'UpdateFromShell' is not available for Windows"

        ##XXX Disable updating user environment from the shell. This can
        ##    be a source of hangs! See bug 38216.
        #return "updating user environment with shell is disabled"

        if not shell:
            self._UpdateFromStartupEnv()
            koprocessutils.resetUserEnv()
            return
        if not (os.path.isfile(shell)):
            return "given shell path does not exist: %r" % shell

        # Determine what class of shell this is: bash, csh, etc.
        patterns = [  # pattern to match against basename
            ("csh", re.compile("csh")),
            ("korn", re.compile("ksh")),
            ("zorn", re.compile("zsh")),
            ("bash", re.compile("bash|^sh$")),
            ("ash", re.compile("^ash$")),
        ]
        basename = os.path.basename(shell)
        type = None
        for name, pattern in patterns:
            if pattern.search(basename):
                type = name
                break
        else:
            return "Don't know what kind of shell '%s' is. It doesn't look "\
                   "like any of Bash, csh, zorn or ash." % shell

        # Run the correct voodoo to get the environment from this shell.
        # the important part here is that the shell must be a login shell,
        # and should not be an interactive shell.  interactive shells
        # have a tendency to lock up komodo (at least on tiger)
        stdin = None
        if ' ' in shell:
            return "cannot yet handle spaces in shell path: %r" % shell

        if type == "bash":
            # interactive bash locks up on tiger
            cmd = "%s -lc printenv" % shell

        elif type == "csh":
            # first *arg* is '-' or -l for login shell, so we must use stdin
            cmd = "%s -l" % shell
            stdin = "printenv"

        # all other shell man pages I looked at say
        # first char of arg 0 is - means login shell, so -c printenv should
        # be fine.
        else:
            cmd = "%s -c printenv" % shell

        stdout, stderr, retval = run(cmd, stdin)
        if retval:
            return "error getting environment from '%s'" % cmd
        if not stdout:
            return "no stdout received from printenv"
        self._userEnviron = parse_bash_set_output(stdout)
        koprocessutils.resetUserEnv()
示例#3
0
    def _updateWithUserOverrides(self, project_overrides=None):
        self._userEnviron = self._origStartupEnv.copy()

        # now overwrite with the userEnvironment preference
        prefs = components.classes["@activestate.com/koPrefService;1"]\
                .getService(components.interfaces.koIPrefService).prefs
        _environUtils = components.classes[
            "@activestate.com/koEnvironUtils;1"] \
            .getService(components.interfaces.koIEnvironUtils)
        havePATHOverride = False
        all_overrides = [
            prefs.getString("userEnvironmentStartupOverride", ""),
            project_overrides
        ]
        for overrides in all_overrides:
            if overrides:
                env = re.split('\r?\n|\r', overrides, re.U)
                if not env: env = []
                sysenv = self.GetEnvironmentStrings()
                newenv = _environUtils.MergeEnvironmentStrings(sysenv, env)
                if not newenv:
                    return
                self._userEnviron = {}
                for line in newenv:
                    item = _ParseBashEnvStr(line)
                    if item:
                        if item[0] == "PATH":
                            havePATHOverride = True
                        self._userEnviron[item[0]] = item[1]

        # For some platforms we implicitly add some common dirs to the PATH.
        # It is common, for example, on Mac OS X for a Komodo user to have
        # "/usr/local/bin" on the PATH in their shell, but not in Komodo
        # because Mac applications don't start from a login shell. This is
        # confusing to users. (Bug 80656.)
        implicitPathAdditionsFromPlat = {
            "darwin": ["/usr/local/bin", "/opt/local/bin"],  # Mac Ports
            "linux2": ["/usr/local/bin"],
        }
        if (not havePATHOverride
                and sys.platform in implicitPathAdditionsFromPlat
                and prefs.getBoolean(
                    "userEnvironmentAllowImplicitPATHAdditions", True)):
            implicitPathAdditions = implicitPathAdditionsFromPlat[sys.platform]
            path = self._userEnviron.get("PATH", "").split(os.pathsep)
            if sys.platform in ("darwin", "win32"):
                comparePath = set(p.lower()
                                  for p in path)  # case-insensitive comparison
            else:
                comparePath = set(path)
            for ipa in implicitPathAdditions:
                compareIpa = (sys.platform in ("darwin", "win32")
                              and ipa.lower() or ipa)
                if compareIpa not in comparePath:
                    path.append(ipa)
            if path:
                self._userEnviron["PATH"] = os.pathsep.join(path)

        # we must reset this in order for some services to pick up on the
        # changes (eg. SCC services)
        koprocessutils.resetUserEnv()
示例#4
0
    def UpdateFromShell(self, shell):
        """Update the internal user environment cache from the given shell.

        Returns None is successful, otherwise returns an error message.
        """
        import koprocessutils
        assert sys.platform != "win32", "'UpdateFromShell' is not available for Windows"

        ##XXX Disable updating user environment from the shell. This can
        ##    be a source of hangs! See bug 38216.
        #return "updating user environment with shell is disabled"

        if not shell:
            self._UpdateFromStartupEnv()
            koprocessutils.resetUserEnv()
            return
        if not (os.path.isfile(shell)):
            return "given shell path does not exist: %r" % shell

        # Determine what class of shell this is: bash, csh, etc.
        patterns = [  # pattern to match against basename
            ("csh", re.compile("csh")),
            ("korn", re.compile("ksh")),
            ("zorn", re.compile("zsh")),
            ("bash", re.compile("bash|^sh$")),
            ("ash", re.compile("^ash$")),
        ]
        basename = os.path.basename(shell)
        type = None
        for name, pattern in patterns:
            if pattern.search(basename):
                type = name
                break
        else:
            return "Don't know what kind of shell '%s' is. It doesn't look "\
                   "like any of Bash, csh, zorn or ash." % shell

        # Run the correct voodoo to get the environment from this shell.
        # the important part here is that the shell must be a login shell,
        # and should not be an interactive shell.  interactive shells
        # have a tendency to lock up komodo (at least on tiger)
        stdin = None
        if ' ' in shell:
            return "cannot yet handle spaces in shell path: %r" % shell

        if type == "bash":
            # interactive bash locks up on tiger
            cmd = "%s -lc printenv" % shell

        elif type == "csh":
            # first *arg* is '-' or -l for login shell, so we must use stdin
            cmd = "%s -l" % shell
            stdin = "printenv"

        # all other shell man pages I looked at say
        # first char of arg 0 is - means login shell, so -c printenv should
        # be fine.
        else:
            cmd = "%s -c printenv" % shell

        stdout, stderr, retval = run(cmd, stdin)
        if retval:
            return "error getting environment from '%s'" % cmd
        if not stdout:
            return "no stdout received from printenv"
        self._userEnviron = parse_bash_set_output(stdout)
        koprocessutils.resetUserEnv()