Пример #1
0
    def _export_entity(self, res, res_folder, export_files = False, export_thumb = False):
        print "exporting", res.name, "to", res_folder
        # Ensures local repository does not contain stale data
        if(os.path.exists(res_folder) and len(os.listdir(res_folder)) > 0) and not self._force:
            raise ExportException(res_folder + " already exists and is not empty.")

        res.dump(res_folder)

        if export_files:
            # Dump files' content to disk
            files_folder = os.path.join(res_folder, "files")
            ensure(files_folder)
            self._export_files_content(res, files_folder)

        if export_thumb:
            # Dump thumbnail to disk
            try:
                content_reader = res.get_thumbnail_content()
                with open(os.path.join(res_folder, "thumb"), "w") as f:
                    f.write(content_reader.read())
            except ApiException as e:
                if e.code == 404:
                    pass
                else:
                    raise e
Пример #2
0
 def dump(self, dest_folder):
     """
     Dumps the state of this object in given folder. Several files may be
     created in destination folder, as well as sub-folders.
     
     @param dest_folder: The path to destination folder
     @type dest_folder: string
     """
     path.ensure(dest_folder)
     plat_file = os.path.join(dest_folder, "definition.json")
     self.dump_json(plat_file)
Пример #3
0
 def dump(self, dest_folder):
     """
     Dumps the state of this object in given folder. Several files may be
     created in destination folder, as well as sub-folders.
     
     @param dest_folder: The path to destination folder
     @type dest_folder: string
     """
     path.ensure(dest_folder)
     plat_file = os.path.join(dest_folder, "definition.json")
     self.dump_json(plat_file)
Пример #4
0
    def render(self, root_dir, skip_chmod, skip_chown):
        path.ensure(root_dir)

        org = self._client.get_organization(self._org_name)
        env = org.get_environment(self._env_name)
        host = env.get_host(self._host_name)

        for app_name in host.application_names:
            # Get application from organization
            app = org.get_application(app_name)

            # Render files of app
            for f in app.files_f:
                file_path = f.file_path
                if file_path[0] == '/':
                    rel_path = file_path[1:]  # remove heading "/"
                else:
                    rel_path = file_path

                # Output rendered file
                (dir_path, file_name) = os.path.split(rel_path)
                output_dir = os.path.join(root_dir, dir_path)
                path.ensure(output_dir)
                output_file = os.path.join(output_dir, file_name)

                content = host.render_app_file(app_name, f.name)
                with open(output_file, "w") as fd:
                    fd.write(content.read())

                if not skip_chmod:
                    try:
                        path.chmod(output_file, f.mode)
                    except OSError, e:
                        raise ControllerException(
                            "Could not set permissions on file " +
                            output_file + ": " + e.strerror)

                if not skip_chown:
                    try:
                        path.chown(output_file, f.owner, f.group)
                    except OSError, e:
                        raise ControllerException(
                            "Could not set ownership on file " + output_file +
                            ": " + e.strerror)
Пример #5
0
    def render(self, root_dir, skip_chmod, skip_chown):
        path.ensure(root_dir)

        org = self._client.get_organization(self._org_name)
        env = org.get_environment(self._env_name)
        host = env.get_host(self._host_name)

        for app_name in host.application_names:
            # Get application from organization
            app = org.get_application(app_name)

            # Render files of app
            for f in app.files_f:
                file_path = f.file_path
                if file_path[0] == '/':
                    rel_path = file_path[1:]  # remove heading "/"
                else:
                    rel_path = file_path

                # Output rendered file
                (dir_path, file_name) = os.path.split(rel_path)
                output_dir = os.path.join(root_dir, dir_path)
                path.ensure(output_dir)
                output_file = os.path.join(output_dir, file_name)

                content = host.render_app_file(app_name, f.name)
                with open(output_file, "w") as fd:
                    fd.write(content.read())

                if not skip_chmod:
                    try:
                        path.chmod(output_file, f.mode)
                    except OSError, e:
                        raise ControllerException("Could not set permissions on file " + output_file + ": " + e.strerror)

                if not skip_chown:
                    try:
                        path.chown(output_file, f.owner, f.group)
                    except OSError, e:
                        raise ControllerException("Could not set ownership on file " + output_file + ": " + e.strerror)
Пример #6
0
    def export_host(self, host, path):
        """
        Exports a host to a local folder. Contexts and instance are exported
        also.

        @param host: The host to export.
        @type host: L{Host}
        @param path: Path to local directory.
        @type path: string
        """

        self._export_entity(host, path)

        # Export instance
        if host.state != Host.State.DEFINED:
            try:
                instance = host.get_instance()
                instance.dump_json(os.path.join(path, "instance.json"))
            except PythonApiException:
                pass

        # Export application contexts
        app_folder = os.path.join(path, "applications")
        ensure(app_folder)
        for context in host.applications():
            context.dump_json(
                os.path.join(app_folder, context.application + ".json"))

        # Export platform context
        try:
            host.get_platform().dump_json(os.path.join(path, "platform.json"))
        except EntityNotFoundException:
            pass

        # Export distribution context
        try:
            host.get_distribution().dump_json(
                os.path.join(path, "distribution.json"))
        except EntityNotFoundException:
            pass
Пример #7
0
    def export_host(self, host, path):
        """
        Exports a host to a local folder. Contexts and instance are exported
        also.

        @param host: The host to export.
        @type host: L{Host}
        @param path: Path to local directory.
        @type path: string
        """

        self._export_entity(host, path)

        # Export instance
        if host.state != Host.State.DEFINED:
            try:
                instance = host.get_instance()
                instance.dump_json(os.path.join(path, "instance.json"))
            except PythonApiException:
                pass

        # Export application contexts
        app_folder = os.path.join(path, "applications")
        ensure(app_folder)
        for context in host.applications():
            context.dump_json(os.path.join(app_folder, context.application + ".json"))

        # Export platform context
        try:
            host.get_platform().dump_json(os.path.join(path, "platform.json"))
        except EntityNotFoundException:
            pass

        # Export distribution context
        try:
            host.get_distribution().dump_json(os.path.join(path, "distribution.json"))
        except EntityNotFoundException:
            pass