예제 #1
0
	def _graphical_sudo(self):
		import which
		if which.whichall('pkexec'):
			return ['pkexec']
		elif which.whichall('gksudo'):
			return ['gksudo', '--']
		return ['sudo', '--']
예제 #2
0
 def _locateExecutables(self, exeName, interpreterPrefName=None, exts=None, paths=None):
     is_windows = sys.platform.startswith('win')
     if exts is None and is_windows:
         exts = ['.exe']
     if paths is None:
         paths = self._userPath
     executables = which.whichall(exeName, exts=exts, path=paths)
     if self.versionCheckExecutables:
         # Only want supported versions.
         executables = [exe for exe in executables if self._isValidExecutable(exe)]
     if interpreterPrefName:
         prefs = self._prefSvc.prefs
         if prefs.hasStringPref(interpreterPrefName):
             prefexe = prefs.getStringPref(interpreterPrefName)
             if prefexe and os.path.exists(prefexe):
                 if is_windows or sys.platform.startswith('darwin'):
                     prefexe_lc = prefexe.lower()
                     executables_lc = [x.lower() for x in executables]
                 else:
                     prefexe_lc = prefexe
                     executables_lc = executables
                 # Make sure the user-chosen interpreter is always first
                 if prefexe_lc not in executables_lc:
                     executables.insert(0, prefexe)
                 else:
                     found_prefexe = executables_lc.index(prefexe_lc)
                     if found_prefexe > 0:
                         del executables[found_prefexe]
                         executables.insert(0, prefexe)
     return [os.path.normcase(os.path.normpath(exe)) for exe in executables]
예제 #3
0
def _gen_pythons():
    python_from_ver = {}
    for name in _gen_python_names():
        for python in which.whichall(name):
            ver = _python_ver_from_python(python)
            if ver not in python_from_ver:
                python_from_ver[ver] = python
    for ver, python in sorted(python_from_ver.items()):
        yield ver, python
예제 #4
0
def _gen_pythons():
    python_from_ver = {}
    for name in _gen_python_names():
        for python in which.whichall(name):
            ver = _python_ver_from_python(python)
            if ver not in python_from_ver:
                python_from_ver[ver] = python
    for ver, python in sorted(python_from_ver.items()):
        yield ver, python
예제 #5
0
 def _gen_pythons(self):
     import which  # `pypm|pip install which`
     python_from_ver = {}
     for name in self._gen_python_names():
         for python in which.whichall(name):
             ver = self._python_ver_from_python(python)
             if ver not in python_from_ver:
                 python_from_ver[ver] = python
     for ver, python in sorted(python_from_ver.items()):
         yield ver, python
예제 #6
0
파일: Makefile.py 프로젝트: trentm/platinfo
 def _gen_pythons(self):
     import which  # get it from http://trentm.com/projects/which
     python_from_ver = {}
     for name in self._gen_python_names():
         for python in which.whichall(name):
             ver = self._python_ver_from_python(python)
             if ver not in python_from_ver:
                 python_from_ver[ver] = python
     for ver, python in sorted(python_from_ver.items()):
         yield ver, python
예제 #7
0
파일: Makefile.py 프로젝트: bdrung/appdirs
 def _gen_pythons(self):
     import which  # `pypm|pip install which`
     python_from_ver = {}
     for name in self._gen_python_names():
         for python in which.whichall(name):
             ver = self._python_ver_from_python(python)
             if ver not in python_from_ver:
                 python_from_ver[ver] = python
     for ver, python in sorted(python_from_ver.items()):
         yield ver, python
예제 #8
0
    def get_firefox_paths(self):
        #TODO: Could just use the new `self._gen_possible_browsers_and_types()`
        #      and only use the `browser_type == 'firefox'` results.
        firefoxes = []
        # If on Windows, add the browser(s) assigned as the default handlers
        # for .html, .htm, etc. (i.e. for common browser-y filetypes).
        if sys.platform.startswith("win"):
            import wininteg
            for ext in (".html", ".htm"):
                try:
                    type, name, actions = wininteg.getFileAssociation(ext)
                except wininteg.WinIntegError:
                    pass
                else:
                    if actions:
                        command = actions[0][2]
                        argv = self._parseAssociationAction(command)
                        if argv and "firefox" in argv[0].lower():
                            firefoxes.append(argv[0])

        # Search the PATH as it was when Komodo started, otherwise Komodo's
        # internal mozilla.exe might be listed as a possible browser.
        #   http://bugs.activestate.com/show_bug.cgi?id=26373
        PATH = koprocessutils.getUserEnv().get("PATH", "")
        path = PATH.split(os.pathsep)
        if sys.platform.startswith('win'):
            firefoxes += which.whichall("firefox", exts=['.exe'], path=path)
        elif sys.platform == 'darwin':
            path = ['/Applications', '/Network/Applications'] + path
            firefoxes += which.whichall("Firefox.app", path=path)
        else:
            firefoxes += which.whichall("firefox", path=path)

        # check for duplicates
        firefoxesWithoutDups = []
        for i in range(len(firefoxes)):
            for j in range(i + 1, len(firefoxes)):
                if self._SameFile(firefoxes[i], firefoxes[j]):
                    break
            else:
                firefoxesWithoutDups.append(firefoxes[i])
        return firefoxesWithoutDups
예제 #9
0
    def get_firefox_paths(self):
        #TODO: Could just use the new `self._gen_possible_browsers_and_types()`
        #      and only use the `browser_type == 'firefox'` results.
        firefoxes = []
        # If on Windows, add the browser(s) assigned as the default handlers
        # for .html, .htm, etc. (i.e. for common browser-y filetypes).
        if sys.platform.startswith("win"):
            import wininteg
            for ext in (".html", ".htm"):
                try:
                    type, name, actions = wininteg.getFileAssociation(ext)
                except wininteg.WinIntegError:
                    pass
                else:
                    if actions:
                        command = actions[0][2]
                        argv = self._parseAssociationAction(command)
                        if argv and "firefox" in argv[0].lower():
                            firefoxes.append(argv[0])

        # Search the PATH as it was when Komodo started, otherwise Komodo's
        # internal mozilla.exe might be listed as a possible browser.
        #   http://bugs.activestate.com/show_bug.cgi?id=26373
        PATH = koprocessutils.getUserEnv().get("PATH", "")
        path = PATH.split(os.pathsep)
        if sys.platform.startswith('win'):
            firefoxes += which.whichall("firefox", exts=['.exe'], path=path)
        elif sys.platform == 'darwin':
            path = ['/Applications', '/Network/Applications'] + path
            firefoxes += which.whichall("Firefox.app", path=path)
        else:
            firefoxes += which.whichall("firefox", path=path)

        # check for duplicates
        firefoxesWithoutDups = []
        for i in range(len(firefoxes)):
            for j in range(i+1, len(firefoxes)):
                if self._SameFile(firefoxes[i], firefoxes[j]):
                    break
            else:
                firefoxesWithoutDups.append(firefoxes[i])
        return firefoxesWithoutDups
예제 #10
0
    def _haveSufficientPHP(self, stopOnFirst=1, minVersion=None):
        """Return true iff a PHP installation meeting the above conditions
        can be found.
            "stopOnFirst" is a boolean indicating if the search should stop
                on the "first" found interpreter. This is because things like
                syntax checking are just going to use this
                one anyway. Default is true.

        If false is returned, then the last error (see koILastErrorService)
        is set with a reason why.
        """
        # Try the user's selected php interpreter.
        phpDefaultInterp = self._prefProxy.prefs.getStringPref(
            "phpDefaultInterpreter")
        if phpDefaultInterp:
            self._phpInfoEx.installationPath =\
                self._phpInfoEx.getInstallationPathFromBinary(phpDefaultInterp)
            if self._isSufficientPHP(self._phpInfoEx, minVersion):
                return 1
            elif stopOnFirst:
                return 0

        # Look on PATH.
        if sys.platform.startswith('win'):
            exts = ['.exe']
        else:
            exts = None
        phps = which.whichall('php', exts=exts, path=self._userPath) + \
               which.whichall('php-cgi', exts=exts, path=self._userPath) + \
               which.whichall('php4', exts=exts, path=self._userPath) + \
               which.whichall('php-cli', exts=exts, path=self._userPath)
        for php in phps:
            self._phpInfoEx.installationPath =\
                self._phpInfoEx.getInstallationPathFromBinary(php)
            if self._isSufficientPHP(self._phpInfoEx, minVersion):
                return 1
            elif stopOnFirst:
                return 0

        errmsg = "Could not find a suitable PHP installation."
        self._lastErrorProxy.setLastError(0, errmsg)
        return 0
예제 #11
0
 def _gen_pythons(self):
     sys.path.insert(0, join(self.dir, "externals", "which"))
     import which  # get it from http://trentm.com/projects/which
     python_from_ver = {}
     for name in self._gen_python_names():
         for python in which.whichall(name):
             ver = self._python_ver_from_python(python)
             if ver not in python_from_ver:
                 python_from_ver[ver] = python
     for ver, python in sorted(python_from_ver.items()):
         yield ver, python
예제 #12
0
 def _gen_pythons(self):
     sys.path.insert(0, join(self.dir, "externals", "which"))
     import which  # get it from http://trentm.com/projects/which
     python_from_ver = {}
     for name in self._gen_python_names():
         for python in which.whichall(name):
             ver = self._python_ver_from_python(python)
             if ver not in python_from_ver:
                 python_from_ver[ver] = python
     for ver, python in sorted(python_from_ver.items()):
         yield ver, python
    def _haveSufficientPHP(self, stopOnFirst=1, minVersion=None):
        """Return true iff a PHP installation meeting the above conditions
        can be found.
            "stopOnFirst" is a boolean indicating if the search should stop
                on the "first" found interpreter. This is because things like
                syntax checking are just going to use this
                one anyway. Default is true.

        If false is returned, then the last error (see koILastErrorService)
        is set with a reason why.
        """
        # Try the user's selected php interpreter.
        phpDefaultInterp = self._prefs.getStringPref("phpDefaultInterpreter")
        if phpDefaultInterp:
            self._phpInfoEx.installationPath = self._phpInfoEx.getInstallationPathFromBinary(phpDefaultInterp)
            if self._isSufficientPHP(self._phpInfoEx, minVersion):
                return 1
            elif stopOnFirst:
                return 0

        # Look on PATH.
        if sys.platform.startswith("win"):
            exts = [".exe"]
        else:
            exts = None
        phps = (
            which.whichall("php", exts=exts, path=self._userPath)
            + which.whichall("php-cgi", exts=exts, path=self._userPath)
            + which.whichall("php4", exts=exts, path=self._userPath)
            + which.whichall("php-cli", exts=exts, path=self._userPath)
        )
        for php in phps:
            self._phpInfoEx.installationPath = self._phpInfoEx.getInstallationPathFromBinary(php)
            if self._isSufficientPHP(self._phpInfoEx, minVersion):
                return 1
            elif stopOnFirst:
                return 0

        errmsg = "Could not find a suitable PHP installation."
        self._lastErrorSvc.setLastError(0, errmsg)
        return 0
예제 #14
0
def get_py_ci_executable():
    global _py_ci_executable
    if _py_ci_executable is None:
        from glob import glob
        from os.path import abspath, dirname, join
        ci_dir = dirname(dirname(dirname(dirname(abspath(__file__)))))
        eggfiles = glob(join(ci_dir, "lib", "ciElementTree-*.egg-info"))
        if not eggfiles:
            raise RuntimeError("No ciElementTree .egg-info file found in %r" %
                               (join(ci_dir, "lib")))
        if len(eggfiles) > 1:
            raise RuntimeError("Too many ciElementTree .egg-info files in %r" %
                               (join(ci_dir, "lib")))
        wanted_version = re.match(".*-py(\d.\d).egg-info$",
                                  eggfiles[0]).group(1)
        import subprocess
        try:
            import which
        except ImportError:
            # Try adding support to the PYTHONPATH.
            sys.path.append(join(ci_dir, "support"))
            import which
        python_exe = "python"
        if sys.platform.startswith('win'):
            python_exe = "python.exe"
        for python_exe in which.whichall(python_exe):
            version = ""
            cwd = os.path.dirname(python_exe)
            argv = [
                python_exe, "-c", "import sys; sys.stdout.write(sys.version)"
            ]
            p = subprocess.Popen(argv, cwd=cwd, stdout=subprocess.PIPE)
            stdout, stderr = p.communicate()
            if not p.returncode:
                # Some example output:
                #   2.0 (#8, Mar  7 2001, 16:04:37) [MSC 32 bit (Intel)]
                #   2.5.2 (r252:60911, Mar 27 2008, 17:57:18) [MSC v.1310 32 bit (Intel)]
                # 2.6rc2 (r26rc2:66504, Sep 26 2008, 15:20:44) [MSC v.1500 32
                # bit (Intel)]
                version_re = re.compile("^(\d+\.\d+)")
                if sys.version_info[0] >= 3:
                    stdout = str(stdout, "ascii")
                match = version_re.match(stdout)
                if match:
                    version = match.group(1)
            if version.startswith(wanted_version):
                _py_ci_executable = python_exe
                break
        if _py_ci_executable is None:
            raise RuntimeError("No Python %s executable found for ciling." %
                               (wanted_version, ))
    return _py_ci_executable
예제 #15
0
    def _haveSufficientNodeJS(self, stopOnFirst=1, minVersion=None):
        """Return true iff a NodeJS installation meeting the above conditions
        can be found.
            "stopOnFirst" is a boolean indicating if the search should stop
                on the "first" found interpreter. This is because things like
                syntax checking are just going to use this
                one anyway. Default is true.

        If false is returned, then the last error (see koILastErrorService)
        is set with a reason why.
        """
        # Try the user's selected nodejs interpreter.
        nodejsDefaultInterp = self._prefs.getStringPref(
            "nodejsDefaultInterpreter")
        if nodejsDefaultInterp:
            log.debug("nodejsDefaultInterp")
            self._nodejsInfoEx.installationPath =\
                self._nodejsInfoEx.getInstallationPathFromBinary(nodejsDefaultInterp)
            log.debug("self._nodejsInfoEx.installationPath=%r",
                      self._nodejsInfoEx.installationPath)
            if self._isSufficientNodeJS(self._nodejsInfoEx, minVersion):
                log.debug("self._isSufficientNodeJS: 1")
                return 1
            elif stopOnFirst:
                log.debug("self._isSufficientNodeJS: 0, stopOnFirst")
                return 0
            else:
                log.debug("self._isSufficientNodeJS: 0")
        else:
            log.debug("no nodejsDefaultInterp")

        # Look on PATH.
        if sys.platform.startswith('win'):
            exts = ['.exe']
        else:
            exts = None
        nodejses = which.whichall('node', exts=exts, path=self._userPath)
        log.debug("no nodejsDefaultInterp")
        for nodejs in nodejses:
            self._nodejsInfoEx.installationPath =\
                self._nodejsInfoEx.getInstallationPathFromBinary(nodejs)
            log.debug("self._nodejsInfoEx.installationPath=%r",
                      self._nodejsInfoEx.installationPath)
            if self._isSufficientNodeJS(self._nodejsInfoEx, minVersion):
                return 1
            elif stopOnFirst:
                return 0

        errmsg = "Could not find a suitable NodeJS installation."
        self._lastErrorSvc.setLastError(0, errmsg)
        return 0
예제 #16
0
def get_py_ci_executable():
    global _py_ci_executable
    if _py_ci_executable is None:
        from glob import glob
        from os.path import abspath, dirname, join
        ci_dir = dirname(dirname(dirname(dirname(abspath(__file__)))))
        eggfiles = glob(join(ci_dir, "lib", "ciElementTree-*.egg-info"))
        if not eggfiles:
            raise RuntimeError("No ciElementTree .egg-info file found in %r" %
                               (join(ci_dir, "lib")))
        if len(eggfiles) > 1:
            raise RuntimeError("Too many ciElementTree .egg-info files in %r" %
                               (join(ci_dir, "lib")))
        wanted_version = re.match(
            ".*-py(\d.\d).egg-info$", eggfiles[0]).group(1)
        import subprocess
        try:
            import which
        except ImportError:
            # Try adding support to the PYTHONPATH.
            sys.path.append(join(ci_dir, "support"))
            import which
        python_exe = "python"
        if sys.platform.startswith('win'):
            python_exe = "python.exe"
        for python_exe in which.whichall(python_exe):
            version = ""
            cwd = os.path.dirname(python_exe)
            argv = [
                python_exe, "-c", "import sys; sys.stdout.write(sys.version)"]
            p = subprocess.Popen(argv, cwd=cwd, stdout=subprocess.PIPE)
            stdout, stderr = p.communicate()
            if not p.returncode:
                # Some example output:
                #   2.0 (#8, Mar  7 2001, 16:04:37) [MSC 32 bit (Intel)]
                #   2.5.2 (r252:60911, Mar 27 2008, 17:57:18) [MSC v.1310 32 bit (Intel)]
                # 2.6rc2 (r26rc2:66504, Sep 26 2008, 15:20:44) [MSC v.1500 32
                # bit (Intel)]
                version_re = re.compile("^(\d+\.\d+)")
                if sys.version_info[0] >= 3:
                    stdout = str(stdout, "ascii")
                match = version_re.match(stdout)
                if match:
                    version = match.group(1)
            if version.startswith(wanted_version):
                _py_ci_executable = python_exe
                break
        if _py_ci_executable is None:
            raise RuntimeError("No Python %s executable found for ciling." %
                               (wanted_version, ))
    return _py_ci_executable
예제 #17
0
파일: Makefile.py 프로젝트: trentm/eol
    def _gen_pythons(self):
        test_dir = join(self.dir, "test")
        sys.path.insert(0, test_dir)
        import which
        sys.path.remove(test_dir)

        python_from_ver = {}
        for name in self._gen_python_names():
            for python in which.whichall(name):
                ver = self._python_ver_from_python(python)
                if ver not in python_from_ver:
                    python_from_ver[ver] = python
        for ver, python in sorted(python_from_ver.items()):
            yield ver, python
예제 #18
0
 def FindInstallationPaths(self):
     if sys.platform.startswith('win'):
         exts = ['.exe']
     else:
         exts = None
     interpreters = ['cl','gcc','cc']
     self._executables = []
     installationPaths = None
     for interp in interpreters:
         self._executables += which.whichall(interp, exts=exts, path=self._userPath)
     if self._executables:
         installationPaths = [self.getInstallationPathFromBinary(p)\
                                for p in self._executables]
     return installationPaths
    def _haveSufficientNodeJS(self, stopOnFirst=1, minVersion=None):
        """Return true iff a NodeJS installation meeting the above conditions
        can be found.
            "stopOnFirst" is a boolean indicating if the search should stop
                on the "first" found interpreter. This is because things like
                syntax checking are just going to use this
                one anyway. Default is true.

        If false is returned, then the last error (see koILastErrorService)
        is set with a reason why.
        """
        # Try the user's selected nodejs interpreter.
        nodejsDefaultInterp = self._prefs.getStringPref("nodejsDefaultInterpreter")
        if nodejsDefaultInterp:
            log.debug("nodejsDefaultInterp")
            self._nodejsInfoEx.installationPath =\
                self._nodejsInfoEx.getInstallationPathFromBinary(nodejsDefaultInterp)
            log.debug("self._nodejsInfoEx.installationPath=%r",
                      self._nodejsInfoEx.installationPath)
            if self._isSufficientNodeJS(self._nodejsInfoEx, minVersion):
                log.debug("self._isSufficientNodeJS: 1")
                return 1
            elif stopOnFirst:
                log.debug("self._isSufficientNodeJS: 0, stopOnFirst")
                return 0
            else:
                log.debug("self._isSufficientNodeJS: 0")
        else:
            log.debug("no nodejsDefaultInterp")
            
        # Look on PATH.
        if sys.platform.startswith('win'):
            exts = ['.exe']
        else:
            exts = None
        nodejses = which.whichall('node', exts=exts, path=self._userPath)
        log.debug("no nodejsDefaultInterp")
        for nodejs in nodejses:
            self._nodejsInfoEx.installationPath =\
                self._nodejsInfoEx.getInstallationPathFromBinary(nodejs)
            log.debug("self._nodejsInfoEx.installationPath=%r",
                      self._nodejsInfoEx.installationPath)
            if self._isSufficientNodeJS(self._nodejsInfoEx, minVersion):
                return 1
            elif stopOnFirst:
                return 0
        
        errmsg = "Could not find a suitable NodeJS installation."
        self._lastErrorSvc.setLastError(0, errmsg)
        return 0
예제 #20
0
파일: Makefile.py 프로젝트: zaxebo1/eol
    def _gen_pythons(self):
        test_dir = join(self.dir, "test")
        sys.path.insert(0, test_dir)
        import which
        sys.path.remove(test_dir)

        python_from_ver = {}
        for name in self._gen_python_names():
            for python in which.whichall(name):
                ver = self._python_ver_from_python(python)
                if ver not in python_from_ver:
                    python_from_ver[ver] = python
        for ver, python in sorted(python_from_ver.items()):
            yield ver, python
예제 #21
0
    def _haveSufficientPerl(self,
                            stopOnFirst=1,
                            minVersion=None,
                            isActivePerl=None,
                            minActivePerlBuild=None,
                            haveModules=[]):
        """Return true iff a Perl installation meeting the above conditions
        can be found.
            "stopOnFirst" is a boolean indicating if the search should stop
                on the "first" found interpreter. This is because things like
                syntax checking are just going to use this
                one anyway. Default is true.

        If false is returned, then the last error (see koILastErrorService)
        is set with a reason why.
        """
        # Try the user's selected perl interpreter.
        perlDefaultInterp = self._prefs.getStringPref("perlDefaultInterpreter")
        if perlDefaultInterp:
            self._perlInfoEx.installationPath =\
                self._perlInfoEx.getInstallationPathFromBinary(perlDefaultInterp)
            if self._isSufficientPerl(self._perlInfoEx, minVersion,
                                      isActivePerl, minActivePerlBuild,
                                      haveModules):
                return 1
            elif stopOnFirst:
                return 0

        # Look on PATH.
        if sys.platform.startswith('win'):
            exts = ['.exe']
        else:
            exts = None
        perls = which.whichall('perl', exts=exts, path=self._userPath)
        for perl in perls:
            self._perlInfoEx.installationPath =\
                self._perlInfoEx.getInstallationPathFromBinary(perl)
            if self._isSufficientPerl(self._perlInfoEx, minVersion,
                                      isActivePerl, minActivePerlBuild,
                                      haveModules):
                return 1
            elif stopOnFirst:
                return 0

        errmsg = "Could not find a suitable Perl installation."
        self._lastErrorSvc.setLastError(0, errmsg)
        return 0
    def _haveSufficientPerl(self, stopOnFirst=1, minVersion=None,
                            isActivePerl=None, minActivePerlBuild=None,
                            haveModules=[]):
        """Return true iff a Perl installation meeting the above conditions
        can be found.
            "stopOnFirst" is a boolean indicating if the search should stop
                on the "first" found interpreter. This is because things like
                syntax checking are just going to use this
                one anyway. Default is true.

        If false is returned, then the last error (see koILastErrorService)
        is set with a reason why.
        """
        # Try the user's selected perl interpreter.
        perlDefaultInterp = self._prefs.getStringPref("perlDefaultInterpreter")
        if perlDefaultInterp:
            self._perlInfoEx.installationPath =\
                self._perlInfoEx.getInstallationPathFromBinary(perlDefaultInterp)
            if self._isSufficientPerl(self._perlInfoEx, minVersion,
                                      isActivePerl, minActivePerlBuild,
                                      haveModules):
                return 1
            elif stopOnFirst:
                return 0
            
        # Look on PATH.
        if sys.platform.startswith('win'):
            exts = ['.exe']
        else:
            exts = None
        perls = which.whichall('perl', exts=exts, path=self._userPath)
        for perl in perls:
            self._perlInfoEx.installationPath =\
                self._perlInfoEx.getInstallationPathFromBinary(perl)
            if self._isSufficientPerl(self._perlInfoEx, minVersion,
                                      isActivePerl, minActivePerlBuild,
                                      haveModules):
                return 1
            elif stopOnFirst:
                return 0
        
        errmsg = "Could not find a suitable Perl installation."
        self._lastErrorSvc.setLastError(0, errmsg)
        return 0
예제 #23
0
        def version(cmd):
            """
            Returns a true response only
            if a valid version was found.
            """
            item("Commands","%s" % " ".join(cmd))
            try:
                p = self.ctx.popen(cmd)
            except OSError:
                self.ctx.err("not found")
                return False

            rv = p.wait()
            io = p.communicate()
            try:
                v = io[0].split()
                v.extend(io[1].split())
                v = "".join(v)
                m = re.match("^\D*(\d[.\d]+\d)\D?.*$", v)
                v = "%-10s" % m.group(1)
                self.ctx.out(v, False)
                try:
                    where = whichall(cmd[0])
                    sz = len(where)
                    if sz == 0:
                        where = "unknown"
                    else:
                        where = where[0]
                        if sz > 1:
                            where += " -- %s others" % sz

                except:
                    where = "unknown"
                self.ctx.out("(%s)" % where)
                return True
            except exceptions.Exception, e:
                self.ctx.err("error:%s" % e)
                return False
    def _haveSufficientRuby(self, stopOnFirst=1, minVersion=None):
        """Return true iff a Ruby installation meeting the above conditions
        can be found.
            "stopOnFirst" is a boolean indicating if the search should stop
                on the "first" found interpreter. This is because things like
                syntax checking are just going to use this
                one anyway. Default is true.

        If false is returned, then the last error (see koILastErrorService)
        is set with a reason why.
        """
        # Try the user's selected ruby interpreter.
        rubyDefaultInterp = self._prefs.getStringPref("rubyDefaultInterpreter")
        if rubyDefaultInterp:
            self._rubyInfoEx.installationPath =\
                self._rubyInfoEx.getInstallationPathFromBinary(rubyDefaultInterp)
            if self._isSufficientRuby(self._rubyInfoEx, minVersion):
                return 1
            elif stopOnFirst:
                return 0
            
        # Look on PATH.
        if sys.platform.startswith('win'):
            exts = ['.exe']
        else:
            exts = None
        rubys = which.whichall('ruby', exts=exts, path=self._userPath)
        for ruby in rubys:
            self._rubyInfoEx.installationPath =\
                self._rubyInfoEx.getInstallationPathFromBinary(ruby)
            if self._isSufficientRuby(self._rubyInfoEx, minVersion):
                return 1
            elif stopOnFirst:
                return 0
        
        errmsg = "Could not find a suitable Ruby installation."
        self._lastErrorSvc.setLastError(0, errmsg)
        return 0
예제 #25
0
 def _locateExecutables(self, exeName, interpreterPrefName=None, exts=None, paths=None):
     is_windows = sys.platform.startswith('win')
     if exts is None and is_windows:
         exts = ['.exe']
     if paths is None:
         paths = self._userPath
     executables = which.whichall(exeName, exts=exts, path=paths)
     if self.versionCheckExecutables:
         # Only want supported versions.
         # _isValidExecutable can throw exceptions, so don't use a
         # list comprehension
         valid_executables = []
         for exe in executables:
             try:
                 if self._isValidExecutable(exe):
                     valid_executables.append(exe)
             except ValueError:
                 pass
         executables = valid_executables
                 
     if interpreterPrefName:
         prefexe = self._prefs.getString(interpreterPrefName, "")
         if prefexe and os.path.exists(prefexe):
             if is_windows or sys.platform.startswith('darwin'):
                 prefexe_lc = prefexe.lower()
                 executables_lc = [x.lower() for x in executables]
             else:
                 prefexe_lc = prefexe
                 executables_lc = executables
             # Make sure the user-chosen interpreter is always first
             if prefexe_lc not in executables_lc:
                 executables.insert(0, prefexe)
             else:
                 found_prefexe = executables_lc.index(prefexe_lc)
                 if found_prefexe > 0:
                     del executables[found_prefexe]
                     executables.insert(0, prefexe)
     return [os.path.normcase(os.path.normpath(exe)) for exe in executables]
예제 #26
0
 def _locateExecutables(self,
                        exeName,
                        interpreterPrefName=None,
                        exts=None,
                        paths=None):
     is_windows = sys.platform.startswith('win')
     if exts is None and is_windows:
         exts = ['.exe']
     if paths is None:
         paths = self._userPath
     executables = which.whichall(exeName, exts=exts, path=paths)
     if self.versionCheckExecutables:
         # Only want supported versions.
         executables = [
             exe for exe in executables if self._isValidExecutable(exe)
         ]
     if interpreterPrefName:
         prefs = self._prefSvc.prefs
         if prefs.hasStringPref(interpreterPrefName):
             prefexe = prefs.getStringPref(interpreterPrefName)
             if prefexe and os.path.exists(prefexe):
                 if is_windows or sys.platform.startswith('darwin'):
                     prefexe_lc = prefexe.lower()
                     executables_lc = [x.lower() for x in executables]
                 else:
                     prefexe_lc = prefexe
                     executables_lc = executables
                 # Make sure the user-chosen interpreter is always first
                 if prefexe_lc not in executables_lc:
                     executables.insert(0, prefexe)
                 else:
                     found_prefexe = executables_lc.index(prefexe_lc)
                     if found_prefexe > 0:
                         del executables[found_prefexe]
                         executables.insert(0, prefexe)
     return [os.path.normcase(os.path.normpath(exe)) for exe in executables]
예제 #27
0
 def WhichAll(self, exeName):
     path = self._userEnvSvc.get("PATH", "").split(os.pathsep)
     return which.whichall(exeName, path=path)
예제 #28
0
                    browser_type, browser_type)
                bpath = path + default_install_dirs_from_browser_type.get(
                    browser_type, [])
                for browser in which.whichall(exe_name,
                                              exts=[".exe"],
                                              path=bpath):
                    if browser not in browser_paths:
                        browser_paths.add(browser)
                        yield browser, browser_type
        elif sys.platform == 'darwin':
            path = ['/Applications', '/Network/Applications'] + path
            for browser_type in ("firefox", "safari", "camino", "googlechrome",
                                 "chromium", "opera", "mozilla", "flock"):
                app_name = self._mac_app_name_from_browser_type.get(
                    browser_type, browser_type)
                for browser in which.whichall(app_name, path=path):
                    if browser not in browser_paths:
                        browser_paths.add(browser)
                        yield browser, browser_type
        else:
            for browser_type in ("firefox", "konqueror", "mozilla",
                                 "googlechrome", "chromium", "opera", "flock",
                                 "kfm"):
                exe_name = self._exe_name_from_browser_type.get(
                    browser_type, browser_type)
                for browser in which.whichall(exe_name, path=path):
                    if browser not in browser_paths:
                        browser_paths.add(browser)
                        yield browser, browser_type

    def get_firefox_paths(self):
예제 #29
0
    def _gen_possible_browsers_and_types(self):
        browser_paths = _PathSet(
        )  # set of yielded browser paths, used to avoid dupes

        # If on Windows, add the browser(s) assigned as the default handlers
        # for .html, .htm, etc. (i.e. for common browser-y filetypes).
        if sys.platform.startswith("win"):
            import wininteg
            for ext in (".html", ".htm"):
                try:
                    type, name, actions = wininteg.getFileAssociation(ext)
                except wininteg.WinIntegError:
                    pass
                else:
                    if actions:
                        command = actions[0][2]
                        argv = self._parseAssociationAction(command)
                        if not argv:
                            continue
                        browser = argv[0]
                        if browser not in browser_paths:
                            browser_paths.add(browser)
                            yield browser, self._guess_browser_type_from_path(
                                browser)

        # Search the PATH as it was when Komodo started, otherwise Komodo's
        # internal mozilla.exe might be listed as a possible browser.
        #   http://bugs.activestate.com/show_bug.cgi?id=26373
        PATH = koprocessutils.getUserEnv().get("PATH", "")
        path = PATH.split(os.pathsep)

        if sys.platform.startswith('win'):
            from applib import _get_win_folder

            # Gather some default install dirs on Windows, because some of the
            # current stock of Windows browsers don't register themselves in
            # the usual ways.
            default_install_dirs_from_browser_type = defaultdict(list)
            programFiles = os.environ.get("ProgramFiles")
            if programFiles:
                default_install_dirs_from_browser_type["safari"].append(
                    join(programFiles, "Safari"))
                default_install_dirs_from_browser_type["opera"].append(
                    join(programFiles, "Opera"))
            try:
                localAppDataDir = _get_win_folder("CSIDL_LOCAL_APPDATA")
            except Exception, ex:
                log.warn("error getting local appdata dir: %s", ex)
            else:
                if localAppDataDir:
                    default_install_dirs_from_browser_type[
                        "googlechrome"].append(
                            join(localAppDataDir, "Google", "Chrome",
                                 "Application"))
            matches = []
            for browser_type in ("firefox", "internetexplorer", "safari",
                                 "googlechrome", "chromium", "opera",
                                 "mozilla", "msnexplorer", "flock"):
                exe_name = self._exe_name_from_browser_type.get(
                    browser_type, browser_type)
                bpath = path + default_install_dirs_from_browser_type.get(
                    browser_type, [])
                for browser in which.whichall(exe_name,
                                              exts=[".exe"],
                                              path=bpath):
                    if browser not in browser_paths:
                        browser_paths.add(browser)
                        yield browser, browser_type
예제 #30
0
 def WhichAll(self, exeName):
     path = self._userEnvProxy.get("PATH").split(os.pathsep)
     return which.whichall(exeName, path=path)
예제 #31
0
         for browser in which.whichall(exe_name, exts=[".exe"], path=bpath):
             if browser not in browser_paths:
                 browser_paths.add(browser)
                 yield browser, browser_type
 elif sys.platform == 'darwin':
     path = ['/Applications','/Network/Applications'] + path
     for browser_type in ("firefox",
                          "safari",
                          "camino",
                          "googlechrome",
                          "chromium",
                          "opera",
                          "mozilla",
                          "flock"):
         app_name = self._mac_app_name_from_browser_type.get(browser_type, browser_type)
         for browser in which.whichall(app_name, path=path):
             if browser not in browser_paths:
                 browser_paths.add(browser)
                 yield browser, browser_type
 else:
     for browser_type in ("firefox",
                          "konqueror",
                          "mozilla",
                          "googlechrome",
                          "chromium",
                          "opera",
                          "flock",
                          "kfm"):
         exe_name = self._exe_name_from_browser_type.get(browser_type, browser_type)
         for browser in which.whichall(exe_name, path=path):
             if browser not in browser_paths:
예제 #32
0
    def _gen_possible_browsers_and_types(self):
        browser_paths = _PathSet()  # set of yielded browser paths, used to avoid dupes

        # If on Windows, add the browser(s) assigned as the default handlers
        # for .html, .htm, etc. (i.e. for common browser-y filetypes).
        if sys.platform.startswith("win"):
            import wininteg
            for ext in (".html", ".htm"):
                try:
                    type, name, actions = wininteg.getFileAssociation(ext)
                except wininteg.WinIntegError:
                    pass
                else:
                    if actions:
                        command = actions[0][2]
                        argv = self._parseAssociationAction(command)
                        if not argv:
                            continue
                        browser = argv[0]
                        if browser not in browser_paths:
                            browser_paths.add(browser)
                            yield browser, self._guess_browser_type_from_path(browser)

        # Search the PATH as it was when Komodo started, otherwise Komodo's
        # internal mozilla.exe might be listed as a possible browser.
        #   http://bugs.activestate.com/show_bug.cgi?id=26373
        PATH = koprocessutils.getUserEnv().get("PATH", "")
        path = PATH.split(os.pathsep)

        if sys.platform.startswith('win'):
            from applib import _get_win_folder

            # Gather some default install dirs on Windows, because some of the
            # current stock of Windows browsers don't register themselves in
            # the usual ways.
            default_install_dirs_from_browser_type = defaultdict(list)
            programFiles = os.environ.get("ProgramFiles")
            if programFiles:
                default_install_dirs_from_browser_type["safari"].append(
                    join(programFiles, "Safari"))
                default_install_dirs_from_browser_type["opera"].append(
                    join(programFiles, "Opera"))
            try:
                localAppDataDir = _get_win_folder("CSIDL_LOCAL_APPDATA")
            except Exception, ex:
                log.warn("error getting local appdata dir: %s", ex)
            else:
                if localAppDataDir:
                    default_install_dirs_from_browser_type["googlechrome"].append(
                        join(localAppDataDir, "Google", "Chrome", "Application"))
            matches = []
            for browser_type in ("firefox",
                                 "internetexplorer",
                                 "safari",
                                 "googlechrome",
                                 "chromium",
                                 "opera",
                                 "mozilla",
                                 "msnexplorer",
                                 "flock"):
                exe_name = self._exe_name_from_browser_type.get(browser_type, browser_type)
                bpath = path + default_install_dirs_from_browser_type.get(browser_type, [])
                for browser in which.whichall(exe_name, exts=[".exe"], path=bpath):
                    if browser not in browser_paths:
                        browser_paths.add(browser)
                        yield browser, browser_type