コード例 #1
0
ファイル: __init__.py プロジェクト: ReignInChaos/ydk-gen
    def generate(self, profile_file, output_directory, ydk_root,
                 groupings_as_class, language):
        """
            Generate ydk-py based in the output_directory using the supplied
            profile_file

            :param str profile_file: The profile file to use
            :param str output_directory: The output directory where the generated ydk python code will be created.
            :param str ydk_root: The ydk root directory. Relative file names in the profile file are resolved relative to this.
            :param bool groupings_as_class: If set to true YANG grouping is converted to a class.
            :raise YdkGenException: if an error has occurred
        """
        self.language = language
        if language != 'cpp' and language != 'python':
            raise YdkGenException(
                'Language {0} not supported'.format(language))
        ydk_directory = self._get_ydk_directory(output_directory, language)

        self._perform_argument_checks(profile_file, output_directory, ydk_root)
        self._create_ydk_directories(output_directory, ydk_root, language)
        resolved_model_dir = self._get_resolved_model_dir(
            profile_file, ydk_root, ydk_directory)

        pyang_builder = PyangModelBuilder(resolved_model_dir)
        modules = pyang_builder.parse_and_return_modules()

        # create the packages
        packages = self._build_api_model_packages(modules, groupings_as_class)
        packages.extend(SubModuleBuilder().generate(
            pyang_builder.get_submodules()))

        # call the language emitter
        printer = printer_factory.PrinterFactory().get_printer(language)(
            ydk_directory)
        printer.emit(packages)
コード例 #2
0
    def _print_packages(self, pkgs, output_dir, bundle):
        """ Emit generated APIs.

        Args:
            pkgs (List[.api_model.Package]): List of api packages to print.
            package_name (str): Package name for generated APIs.
                            For example 'ydk_bgp', 'ydk_ietf'.
        """
        global classes_per_source_file
        factory = printer_factory.PrinterFactory()
        ydk_printer = factory.get_printer(self.language)(output_dir, bundle, self.generate_tests, self.sort_clazz)
        generated_files = ydk_printer.emit(pkgs, classes_per_source_file)
        return generated_files
コード例 #3
0
ファイル: __init__.py プロジェクト: sangmeshcp/ydk-gen
    def _print_pkgs(self, pkgs, output_dir, bundle_name=''):
        """ Emit generated APIs.

        Args:
            pkgs (List[.api_model.Package]): List of api packages to print.
            pkg_name (str): Package name for generated APIs.
                            For example 'ydk_bgp', 'ydk_ietf'.
        """
        factory = printer_factory.PrinterFactory()
        ydk_printer = factory.get_printer(self.language)(output_dir,
                                                         bundle_name,
                                                         self.generate_tests,
                                                         self.sort_clazz)
        ydk_printer.emit(pkgs)
コード例 #4
0
ファイル: __init__.py プロジェクト: richard268/ydk-gen
    def _print_packages(self, pkgs, output_dir, bundle):
        """ Emit generated APIs.

        Args:
            pkgs (List[.api_model.Package]): List of api packages to print.
            output_dir (str): Output directory.
            bundle (Bundle): Bundle package
        """
        global classes_per_source_file
        factory = printer_factory.PrinterFactory()
        bundle_packages = _filter_bundle_from_packages(pkgs, bundle)
        ydk_printer = factory.get_printer(self.language)(
            output_dir, bundle, self.generate_tests, self.one_class_per_module)
        if self.language == 'python':
            ydk_printer.generate_meta = self.generate_meta
        generated_files = ydk_printer.emit(bundle_packages,
                                           classes_per_source_file)
        return generated_files