コード例 #1
0
 def test_specification_to_dict(self):
     """
     """
     data = json.loads(SPEC)
     s = Specification("task.spec")
     s.from_dict(data)
     data = s.to_dict()
     self._verify(s, data)
コード例 #2
0
 def test_specification_to_dict(self):
     """
     """
     data = json.loads(SPEC)
     s = Specification("task.spec")
     s.from_dict(data)
     data = s.to_dict()
     self._verify(s, data)
コード例 #3
0
    def test_specification_from_dict(self):
        """ Convert REST names to Python

        """
        data = json.loads(SPEC)
        s = Specification("task.spec")
        s.from_dict(data)
        self._verify(s, data)
コード例 #4
0
    def test_specification_from_dict(self):
        """ Convert REST names to Python

        """
        data = json.loads(SPEC)
        s = Specification("task.spec")
        s.from_dict(data)
        self._verify(s, data)
コード例 #5
0
 def test_specification_to_dict(self):
     """
     """
     data = json.loads(SPEC)
     monolithe_config = MonolitheConfig()
     s = Specification(filename="task.spec", monolithe_config=monolithe_config)
     s.from_dict(data)
     data = s.to_dict()
     self._verify(s, data)
コード例 #6
0
    def test_specification_from_dict(self):
        """ Convert REST names to Python

        """
        data = json.loads(SPEC)
        monolithe_config = MonolitheConfig()
        s = Specification(filename="task.spec", monolithe_config=monolithe_config)
        s.from_dict(data)
        self._verify(s, data)
コード例 #7
0
 def test_specification_to_dict(self):
     """
     """
     data = json.loads(SPEC)
     monolithe_config = MonolitheConfig()
     s = Specification(filename="task.spec",
                       monolithe_config=monolithe_config)
     s.from_dict(data)
     data = s.to_dict()
     self._verify(s, data)
コード例 #8
0
    def test_specification_from_dict(self):
        """ Convert REST names to Python

        """
        data = json.loads(SPEC)
        monolithe_config = MonolitheConfig()
        s = Specification(filename="task.spec",
                          monolithe_config=monolithe_config)
        s.from_dict(data)
        self._verify(s, data)
コード例 #9
0
 def get_specification(self,
                       name,
                       branch="master",
                       archive=None,
                       mode=MODE_NORMAL):
     """ Returns a Specification object from the given specification file name 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:
             Specification object.
     """
     return Specification(filename=name,
                          data=self.get_specification_data(
                              name, branch, archive),
                          monolithe_config=self.monolithe_config)
コード例 #10
0
    def export_specification(self, specification, session_username):
        """
        """
        mono_spec = Specification(monolithe_config=None, filename=specification.name)

        mono_spec.description = specification.description
        mono_spec.package = specification.package
        mono_spec.allows_get = specification.allows_get
        mono_spec.allows_update = specification.allows_update
        mono_spec.allows_create = specification.allows_create
        mono_spec.allows_delete = specification.allows_delete

        if specification.rest_name == self._sdk.SDSpecification.rest_name:
            response = self._storage_controller.get_all(user_identifier=session_username, parent=specification, resource_name=self._sdk.SDAbstract.rest_name)

            if response.count:
                mono_spec.extends = sorted([abstract.name.replace(".spec", "") for abstract in response.data])

            mono_spec.is_root = specification.root
            mono_spec.entity_name = specification.entity_name
            mono_spec.rest_name = specification.object_rest_name
            mono_spec.resource_name = specification.object_resource_name
            mono_spec.userlabel = specification.userlabel
            mono_spec.template = specification.template
            mono_spec.allowed_job_commands = sorted(specification.allowed_job_commands) if specification.allowed_job_commands else None

        mono_spec.child_apis = self._export_child_apis(specification=specification, session_username=session_username)
        mono_spec.attributes = self._export_attributes(specification=specification, session_username=session_username)

        return mono_spec
コード例 #11
0
    def get_all_specifications(self, branch="master", mode=MODE_NORMAL):
        """ Returns all availables specifications using zipball feature of GitHub
            This is extremely fast if you need to get a lot of Specifications in one
            shot.
            Args:
                branch: the branch where to find files (default: "master")
            Returns:
                list of Specification objects.
        """
        specifications = {}
        archive_fd, archive_path = tempfile.mkstemp("archive.zip")
        url = self._repo.get_archive_link("zipball", ref=branch)
        req = requests.get(url, stream=True, verify=False)

        # retrieve and write the archive content to a temporary file
        with open(archive_path, "wb") as f:
            for chunk in req.iter_content(chunk_size=1024):
                if not chunk:
                    continue
                f.write(chunk)
                f.flush()

        stripped_repository_path = self.repository_path.strip("/")

        # reads the content of the archive and generate Specification objects
        with zipfile.ZipFile(archive_path, "r") as archive_content:
            for file_name in archive_content.namelist():

                spec_dir = os.path.split(file_name)[0]

                if not spec_dir.startswith(stripped_repository_path):
                    continue

                spec_name = os.path.split(file_name)[1]

                if spec_name == "api.info":
                    continue

                ext = os.path.splitext(spec_name)[1]
                is_abstract = spec_name.startswith("@")

                if ext != ".spec":
                    continue

                if mode in (MODE_NORMAL, MODE_RAW_SPECS) and is_abstract:
                    continue

                if mode == MODE_RAW_ABSTRACTS and not is_abstract:
                    continue

                specifications[spec_name.replace(".spec", "")] = Specification(
                    filename=spec_name,
                    data=self.get_specification_data(name=spec_name,
                                                     archive=archive_content,
                                                     mode=mode),
                    monolithe_config=self.monolithe_config)

        # cleanup the temporary archive
        os.close(archive_fd)
        os.remove(archive_path)

        return specifications
コード例 #12
0
    def export_specification(self, specification, session_username):
        """
        """
        mono_spec = Specification(monolithe_config=None, filename=specification.name)

        mono_spec.description = specification.description
        mono_spec.package = specification.package
        mono_spec.allows_get = specification.allows_get
        mono_spec.allows_update = specification.allows_update
        mono_spec.allows_create = specification.allows_create
        mono_spec.allows_delete = specification.allows_delete

        if specification.rest_name == self._sdk.SDSpecification.rest_name:
            response = self._storage_controller.get_all(user_identifier=session_username, parent=specification, resource_name=self._sdk.SDAbstract.rest_name)

            if response.count:
                mono_spec.extends = sorted([abstract.name.replace(".spec", "") for abstract in response.data])

            mono_spec.is_root = specification.root
            mono_spec.entity_name = specification.entity_name
            mono_spec.rest_name = specification.object_rest_name
            mono_spec.resource_name = specification.object_resource_name

        mono_spec.child_apis = self._export_child_apis(specification=specification, session_username=session_username)
        mono_spec.attributes = self._export_attributes(specification=specification, session_username=session_username)

        return mono_spec