Example #1
0
 def initialize_repository_manager(self, api_url, login_or_token, password,
                                   organization, repository,
                                   repository_path):
     """
     """
     self.repository_manager = RepositoryManager(
         monolithe_config=self.monolithe_config,
         api_url=api_url,
         login_or_token=login_or_token,
         password=password,
         organization=organization,
         repository=repository,
         repository_path=repository_path)
Example #2
0
 def initialize_repository_manager(self, api_url, login_or_token, password, organization, repository, repository_path):
     """
     """
     self.repository_manager = RepositoryManager(monolithe_config=self.monolithe_config,
                                                 api_url=api_url,
                                                 login_or_token=login_or_token,
                                                 password=password,
                                                 organization=organization,
                                                 repository=repository,
                                                 repository_path=repository_path)
Example #3
0
class Generator(object):

    def __init__(self, monolithe_config):
        """
        """
        self.monolithe_config = monolithe_config

    def initialize_folder_manager(self, folder):
        """
        """
        self.folder_manager = FolderManager(folder=folder, monolithe_config=self.monolithe_config)

    def retrieve_monolithe_config_from_folder(self, language="python"):
        """
        """
        parser = self.folder_manager.get_monolithe_config()
        self.monolithe_config = MonolitheConfig()
        self.monolithe_config.set_config(parser)
        self.monolithe_config.language = language
        self.folder_manager.monolithe_config = self.monolithe_config
        return self.monolithe_config

    def generate_from_folder(self):
        """
        """
        specification_info = []

        Printer.log("retrieving specifications from folder \"%s\"" % (self.folder_manager.folder))
        api_info = self.folder_manager.get_api_info()
        specifications = self.folder_manager.get_all_specifications()
        self._resolve_parent_apis(specifications)
        specification_info.append({"specifications": specifications, "api": api_info})
        Printer.log("%d specifications retrieved from folder \"%s\" (api version: %s)" % (len(specifications), self.folder_manager.folder, api_info["version"]))

        self.generate(specification_info=specification_info)

    def initialize_repository_manager(self, api_url, login_or_token, password, organization, repository, repository_path):
        """
        """
        self.repository_manager = RepositoryManager(monolithe_config=self.monolithe_config,
                                                    api_url=api_url,
                                                    login_or_token=login_or_token,
                                                    password=password,
                                                    organization=organization,
                                                    repository=repository,
                                                    repository_path=repository_path)

    def retrieve_monolithe_config_from_repo(self, branch, language):
        """
        """
        parser = self.repository_manager.get_monolithe_config(branch=branch)
        self.monolithe_config = MonolitheConfig()
        self.monolithe_config.set_config(parser)
        self.monolithe_config.language = language
        self.repository_manager.monolithe_config = self.monolithe_config
        return self.monolithe_config

    def generate_from_repo(self, branches):
        """
        """
        specification_info = []

        for branch in branches:
            Printer.log("retrieving specifications from github \"%s/%s%s@%s\"" % (self.repository_manager.organization.lower(), self.repository_manager.repository.lower(), self.repository_manager.repository_path, branch))
            api_info = self.repository_manager.get_api_info(branch=branch)
            specifications = self.repository_manager.get_all_specifications(branch=branch)
            self._resolve_parent_apis(specifications)
            specification_info.append({"specifications": specifications, "api": api_info})
            Printer.log("%d specifications retrieved from branch \"%s\" (api version: %s)" % (len(specifications), branch, api_info["version"]))

        self.generate(specification_info=specification_info)

    def generate(self, specification_info):
        """
        """
        pass

    def install_user_vanilla(self, user_vanilla_path, output_path, multi_lang=True):
        """
        """
        if not user_vanilla_path or not len(user_vanilla_path):
            return

        if multi_lang:
            user_vanilla_path = os.path.join(user_vanilla_path, self.monolithe_config.language)
        else:
            user_vanilla_path = os.path.join(user_vanilla_path)

        if not os.path.exists(user_vanilla_path):
            Printer.warn("Could not find user vanilla folder at path %s. Ignoring" % user_vanilla_path)
            return

        for item in os.listdir(user_vanilla_path):
            s = os.path.join(user_vanilla_path, item)
            d = os.path.join(output_path, item)
            if os.path.isdir(s):
                shutil.copytree(s, d, False, None)
            else:
                shutil.copy2(s, d)

    # Utilities
    def _resolve_parent_apis(self, specifications):
        """
        """

        # certainly not the best algo ever... but I need to get somthing done :)
        for specification_rest_name, specification in specifications.items():

            for rest_name, remote_spec in specifications.items():

                for related_child_api in remote_spec.child_apis:

                    if related_child_api.rest_name == specification.rest_name:

                        parent_api = SpecificationAPI(specification=specification)
                        parent_api.rest_name = related_child_api.rest_name
                        if specification.allows_get:
                            parent_api.allows_get = True
                        if specification.allows_create:
                            parent_api.allows_create = True
                        if specification.allows_update:
                            parent_api.allows_update = True
                        if specification.allows_delete:
                            parent_api.allows_Delete = True

                        specification.parent_apis.append(parent_api)
Example #4
0
class Generator(object):
    def __init__(self, monolithe_config):
        """
        """
        self.monolithe_config = monolithe_config

    def initialize_folder_manager(self, folder):
        """
        """
        self.folder_manager = FolderManager(
            folder=folder, monolithe_config=self.monolithe_config)

    def retrieve_monolithe_config_from_folder(self):
        """
        """
        parser = self.folder_manager.get_monolithe_config()
        self.monolithe_config = MonolitheConfig()
        self.monolithe_config.set_config(parser)
        self.folder_manager.monolithe_config = self.monolithe_config

    def generate_from_folder(self):
        """
        """
        specification_info = []

        Printer.log("retrieving specifications from folder \"%s\"" %
                    (self.folder_manager.folder))
        api_info = self.folder_manager.get_api_info()
        specifications = self.folder_manager.get_all_specifications()
        self._resolve_parent_apis(specifications)
        specification_info.append({
            "specifications": specifications,
            "api": api_info
        })
        Printer.log(
            "%d specifications retrieved from folder \"%s\" (api version: %s)"
            % (len(specifications), self.folder_manager.folder,
               api_info["version"]))

        self.generate(specification_info=specification_info)

    def initialize_repository_manager(self, api_url, login_or_token, password,
                                      organization, repository,
                                      repository_path):
        """
        """
        self.repository_manager = RepositoryManager(
            monolithe_config=self.monolithe_config,
            api_url=api_url,
            login_or_token=login_or_token,
            password=password,
            organization=organization,
            repository=repository,
            repository_path=repository_path)

    def retrieve_monolithe_config_from_repo(self, branch):
        """
        """
        parser = self.repository_manager.get_monolithe_config(branch=branch)
        self.monolithe_config = MonolitheConfig()
        self.monolithe_config.set_config(parser)
        self.repository_manager.monolithe_config = self.monolithe_config

    def generate_from_repo(self, branches):
        """
        """
        specification_info = []

        for branch in branches:
            Printer.log(
                "retrieving specifications from github \"%s/%s%s@%s\"" %
                (self.repository_manager.organization.lower(),
                 self.repository_manager.repository.lower(),
                 self.repository_manager.repository_path, branch))
            api_info = self.repository_manager.get_api_info(branch=branch)
            specifications = self.repository_manager.get_all_specifications(
                branch=branch)
            self._resolve_parent_apis(specifications)
            specification_info.append({
                "specifications": specifications,
                "api": api_info
            })
            Printer.log(
                "%d specifications retrieved from branch \"%s\" (api version: %s)"
                % (len(specifications), branch, api_info["version"]))

        self.generate(specification_info=specification_info)

    def generate(self, specification_info):
        """
        """
        pass

    def install_system_vanilla(self, current_file, output_path):
        """
        """
        if os.path.exists(output_path):
            shutil.rmtree(output_path)

        system_vanilla_path = os.path.join(os.path.dirname(current_file),
                                           "vanilla")
        shutil.copytree(system_vanilla_path, output_path)

    def install_user_vanilla(self, user_vanilla_path, output_path):
        """
        """
        if not user_vanilla_path or not len(user_vanilla_path):
            return

        if not os.path.exists(user_vanilla_path):
            Printer.raiseError(
                "Could not find user vanilla folder at path %s" %
                user_vanilla_path)

        for item in os.listdir(user_vanilla_path):
            s = os.path.join(user_vanilla_path, item)
            d = os.path.join(output_path, item)
            if os.path.isdir(s):
                shutil.copytree(s, d, False, None)
            else:
                shutil.copy2(s, d)

    ## Utilities

    def _resolve_parent_apis(self, specifications):
        """
        """

        # certainly not the best algo ever... but I need to get somthing done :)
        for specification_rest_name, specification in specifications.iteritems(
        ):

            for rest_name, remote_spec in specifications.iteritems():

                for related_child_api in remote_spec.child_apis:

                    if related_child_api.remote_specification_name == specification.rest_name:

                        parent_api = SpecificationAPI(
                            remote_specification_name=related_child_api.
                            remote_specification_name,
                            specification=specification)

                        if specification.allows_get:
                            parent_api.allows_get = True
                        if specification.allows_create:
                            parent_api.allows_create = True
                        if specification.allows_update:
                            parent_api.allows_update = True
                        if specification.allows_delete:
                            parent_api.allows_Delete = True

                        specification.parent_apis.append(parent_api)