Пример #1
0
    def parse_conf(self, path):
        def paired(iterable):
            """s -> (s0, s1), (s2, s3), (s4, s5), ..."""
            cursor = iter(iterable)
            return zip(cursor, cursor)

        def unwrap_if_sexp_symbol(datum):
            """
            Convert Symbol(':key') to ':key' (Symbol isn't hashable for dict keys).
            """
            return datum.value() if isinstance(datum, sexpdata.Symbol) else datum

        def sexp2dict(sexps):
            """
            Transforms a nested list structure from sexpdata to dict.

            NOTE: This probably isn't general for all S-expression shapes parsed by
            sexpdata, focused only on .ensime thus far.
            """
            newdict = {}

            # Turn flat list into associative pairs
            for key, value in paired(sexps):
                key = str(unwrap_if_sexp_symbol(key)).lstrip(':')

                # Recursively transform nested lists
                if isinstance(value, list) and value and isinstance(value[0], list):
                    newdict[key] = [sexp2dict(value[0])]
                else:
                    newdict[key] = value

            return newdict

        conf = sexpdata.loads(Util.read_file(path))
        return sexp2dict(conf)
Пример #2
0
    def launch(self):
        if not self.isinstalled():
            raise LaunchError('Bootstrap classpath file does not exist at {}'
                              .format(self.classpath_file))

        classpath = Util.read_file(self.classpath_file) + ':' + self.toolsjar
        return self._start_process(classpath)
Пример #3
0
 def load_classpath(self, scala_version, java_home):
     project_dir = self.classpath_project_dir(scala_version)
     classpath_file = os.path.join(project_dir, "classpath")
     if not os.path.exists(classpath_file):
         if not self.generate_classpath(scala_version, classpath_file):
             return None
     return "{}:{}/lib/tools.jar".format(
         Util.read_file(classpath_file), java_home)
Пример #4
0
 def parse_conf(self, path):
     conf = Util.read_file(path).replace("\n", "").replace(
             "(", " ").replace(")", " ").replace('"', "").split(" :")
     pattern = re.compile("([^ ]*) *(.*)$")
     conf = [(m[0], m[1])for m in [pattern.match(x).groups() for x in conf]]
     result = {}
     for item in conf:
         result[item[0]] = item[1]
     return result
Пример #5
0
    def load_classpath(self, scala_version, java_home):
        project_dir = self.classpath_project_dir(scala_version)
        classpath_file = os.path.join(project_dir, "classpath")
        if not os.path.exists(classpath_file):
            if not self.generate_classpath(scala_version, classpath_file):
                return None
        classpath = "{}:{}/lib/tools.jar".format(
            Util.read_file(classpath_file), java_home)

        for x in os.listdir(self.base_dir):
            if fnmatch.fnmatch(x, "ensime_" + scala_version[:4] + "*-assembly.jar"):
                classpath = os.path.join(self.base_dir, x) + ":" + classpath

        return classpath
Пример #6
0
    def load_classpath(self):
        if not os.path.exists(self.classpath_file):
            if not self.generate_classpath():
                return None

        classpath = "{}:{}/lib/tools.jar".format(Util.read_file(self.classpath_file), self.config["java-home"])

        # Allow override with a local development server jar, see:
        # http://ensime.github.io/contributing/#manual-qa-testing
        for x in os.listdir(self.base_dir):
            if fnmatch.fnmatch(x, "ensime_" + self.scala_minor + "*-assembly.jar"):
                classpath = os.path.join(self.base_dir, x) + ":" + classpath

        return classpath
Пример #7
0
    def load_classpath(self):
        if not os.path.exists(self.classpath_file):
            if not self.generate_classpath():
                return None

        classpath = "{}:{}/lib/tools.jar".format(
            Util.read_file(self.classpath_file), self.config['java-home'])

        # Allow override with a local development server jar, see:
        # http://ensime.github.io/contributing/#manual-qa-testing
        for x in os.listdir(self.base_dir):
            if fnmatch.fnmatch(x, "ensime_" + self.scala_minor +
                               "*-assembly.jar"):
                classpath = os.path.join(self.base_dir, x) + ":" + classpath

        return classpath
Пример #8
0
    def parse(path):
        """Parse an ``.ensime`` config file from S-expressions.

        Args:
            path (str): Path of an ``.ensime`` file to parse.

        Returns:
            dict: Configuration values with string keys.
        """

        def paired(iterable):
            """s -> (s0, s1), (s2, s3), (s4, s5), ..."""
            cursor = iter(iterable)
            return zip(cursor, cursor)

        def unwrap_if_sexp_symbol(datum):
            """Convert Symbol(':key') to ':key' (Symbol isn't hashable for dict keys).
            """
            return datum.value() if isinstance(datum, sexpdata.Symbol) else datum

        def sexp2dict(sexps):
            """Transforms a nested list structure from sexpdata to dict."""
            newdict = {}

            # Turn flat list into associative pairs
            for key, value in paired(sexps):
                key = str(unwrap_if_sexp_symbol(key)).lstrip(':')

                # Recursively transform nested lists
                if isinstance(value, list) and value:
                    if isinstance(value[0], list):
                        newdict[key] = [sexp2dict(val) for val in value]
                    elif isinstance(value[0], sexpdata.Symbol):
                        newdict[key] = sexp2dict(value)
                    else:
                        newdict[key] = value
                else:
                    newdict[key] = value

            return newdict

        conf = sexpdata.loads(Util.read_file(path))
        return sexp2dict(conf)
Пример #9
0
    def parse(path):
        """Parse an ``.ensime`` config file from S-expressions.

        Args:
            path (str): Path of an ``.ensime`` file to parse.

        Returns:
            dict: Configuration values with string keys.
        """
        def paired(iterable):
            """s -> (s0, s1), (s2, s3), (s4, s5), ..."""
            cursor = iter(iterable)
            return zip(cursor, cursor)

        def unwrap_if_sexp_symbol(datum):
            """Convert Symbol(':key') to ':key' (Symbol isn't hashable for dict keys).
            """
            return datum.value() if isinstance(datum,
                                               sexpdata.Symbol) else datum

        def sexp2dict(sexps):
            """Transforms a nested list structure from sexpdata to dict."""
            newdict = {}

            # Turn flat list into associative pairs
            for key, value in paired(sexps):
                key = str(unwrap_if_sexp_symbol(key)).lstrip(':')

                # Recursively transform nested lists
                if isinstance(value, list) and value:
                    if isinstance(value[0], list):
                        newdict[key] = [sexp2dict(val) for val in value]
                    elif isinstance(value[0], sexpdata.Symbol):
                        newdict[key] = sexp2dict(value)
                    else:
                        newdict[key] = value
                else:
                    newdict[key] = value

            return newdict

        conf = sexpdata.loads(Util.read_file(path))
        return sexp2dict(conf)
Пример #10
0
    def parse_config(path):
        """Parse an .ensime project config file, from S-expressions to dict."""
        def paired(iterable):
            """s -> (s0, s1), (s2, s3), (s4, s5), ..."""
            cursor = iter(iterable)
            return zip(cursor, cursor)

        def unwrap_if_sexp_symbol(datum):
            """
            Convert Symbol(':key') to ':key' (Symbol isn't hashable for dict keys).
            """
            return datum.value() if isinstance(datum,
                                               sexpdata.Symbol) else datum

        def sexp2dict(sexps):
            """
            Transforms a nested list structure from sexpdata to dict.

            NOTE: This probably isn't general for all S-expression shapes parsed by
            sexpdata, focused only on .ensime thus far.
            """
            newdict = {}

            # Turn flat list into associative pairs
            for key, value in paired(sexps):
                key = str(unwrap_if_sexp_symbol(key)).lstrip(':')

                # Recursively transform nested lists
                if isinstance(value, list) and value and isinstance(
                        value[0], list):
                    newdict[key] = [sexp2dict(value[0])]
                else:
                    newdict[key] = value

            return newdict

        conf = sexpdata.loads(Util.read_file(path))
        return sexp2dict(conf)
Пример #11
0
 def http_port(self):
     return int(Util.read_file(os.path.join(self.cache_dir, "http")))
Пример #12
0
 def http_port(self):
     return int(Util.read_file(os.path.join(self.cache_dir, "http")))