예제 #1
0
    def get_specification_data(self, name, branch="master", archive=None, mode=MODE_NORMAL):
        """ Returns the content of the specification_file in the given branch

            Args:
                name: the name of the specification file of which you want to get the content
                branch: the branch where to find files (default: "master")

            Returns:
                JSON decoded structure of the specification file.
        """
        data = {}
        full_path = None

        if archive:
            full_path = os.path.normpath("%s%s/%s" % (archive.namelist()[0], self._repository_path, name))
            try:
                data = json.loads(archive.read(full_path))
            except Exception as e:
                raise Exception("could not parse %s" % name, e)
        else:
            full_path = os.path.normpath("%s/%s" % (self._repository_path, name))
            try:
                data = json.loads(base64.b64decode(self._repo.get_file_contents(full_path, ref=branch).content))
            except Exception as e:
                raise Exception("could not parse %s" % name, e)

        if mode == MODE_NORMAL and "model" in data and "extends" in data["model"]:
            for extension in data["model"]["extends"]:
                data = merge_dict(data, self.get_specification_data(name="%s.spec" % extension, branch=branch, archive=archive, mode=MODE_NORMAL))

        return data
예제 #2
0
 def get_specification_data(self, name):
     """
     """
     data = {}
     with open("%s/%s" % (self._folder, name), "r") as f:
         try:
             data = json.loads(f.read())
             if "model" in data and "extends" in data["model"]:
                 for extension in data["model"]["extends"]:
                     data = merge_dict(data, self.get_specification_data(name="%s.spec" % extension))
         except Exception as e:
             raise Exception("Could not parse %s" % name, e)
     return data
예제 #3
0
    def get_specification_data(self,
                               name,
                               branch="master",
                               archive=None,
                               mode=MODE_NORMAL):
        """ Returns the content of the specification_file in the given branch

            Args:
                name: the name of the specification file of which you want to get the content
                branch: the branch where to find files (default: "master")

            Returns:
                JSON decoded structure of the specification file.
        """
        data = {}
        full_path = None

        if archive:
            full_path = os.path.normpath(
                "%s%s/%s" %
                (archive.namelist()[0], self._repository_path, name))
            try:
                data = json.loads(archive.read(full_path))
            except Exception as e:
                raise Exception("could not parse %s" % name, e)
        else:
            full_path = os.path.normpath("%s/%s" %
                                         (self._repository_path, name))
            try:
                data = json.loads(
                    base64.b64decode(
                        self._repo.get_file_contents(full_path,
                                                     ref=branch).content))
            except Exception as e:
                raise Exception("could not parse %s" % name, e)

        if mode == MODE_NORMAL and "model" in data and "extends" in data[
                "model"]:
            for extension in data["model"]["extends"]:
                data = merge_dict(
                    data,
                    self.get_specification_data(name="%s.spec" % extension,
                                                branch=branch,
                                                archive=archive,
                                                mode=MODE_NORMAL))

        return data