Skip to content

Commit

Permalink
Resolved issue CiscoDevNet#978, implemented enhancement 894
Browse files Browse the repository at this point in the history
  • Loading branch information
ygorelik committed Dec 20, 2019
1 parent a6dc1da commit af672f2
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#### Resolved GitHub issues
* gNMI set RPC fails when JSON payload is formatted string
* Enhance generator to indicate how a YANG modules was processed ([#894](https://github.com/CiscoDevNet/ydk-gen/issues/894))
* YDK fails create bundle package when package name contains '.' ([#978](https://github.com/CiscoDevNet/ydk-gen/issues/978))

#### Documentation improvements
* Bundle profile description is not accurate ([#971](https://github.com/CiscoDevNet/ydk-gen/issues/971))
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -438,13 +438,13 @@ The first step in using ydk-gen is either using one of the already built [bundle

Construct a bundle profile file, such as [```ietf_0_1_1.json```](profiles/bundles/ietf_0_1_1.json) and specify its dependencies.

A sample bundle profile file is described below. The file is in a JSON format. Specify the `"name"` of your bundle, the `"version"` of the bundle and the `"ydk_version"`, which refers to [the version](https://github.com/CiscoDevNet/ydk-gen/releases) of the ydk core package you want to use with this bundle. The `"name"` of the bundle here is especially important as this will form part of the installation path of the bundle.
A sample bundle profile file is described below. The file is in a JSON format. Specify the `"name"` of your bundle, the `"version"` of the bundle and the `"core_version"`, which refers to [the version](https://github.com/CiscoDevNet/ydk-gen/releases) of the ydk core package you want to use with this bundle. The `"name"` of the bundle here is especially important as this will form part of the installation path of the bundle.

```
{
"name":"cisco-ios-xr",
"version": "6.5.3",
"ydk_version": "0.8.4",
"core_version": "0.8.4",
"Author": "Cisco",
"Copyright": "Cisco",
"Description": "Cisco IOS-XR Native Models From Git",
Expand Down
4 changes: 2 additions & 2 deletions profiles/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ In order to generate model bundle, as it is described in the root directory READ
This part must include:
- `"name"` of the bundle; the name also used to form part of the installation path of the bundle
- `"version"` of the bundle
- `"ydk_version"`, which refers to the [version](https://github.com/CiscoDevNet/ydk-gen/releases) of the YDK core package.
- `"core_version"`, which refers to the [version](https://github.com/CiscoDevNet/ydk-gen/releases) of the YDK core package.

Other components of description part are optional. Here is simple example of description part:

```
{
"name":"cisco-ios-xr",
"version": "6.5.3",
"ydk_version": "0.8.4",
"core_version": "0.8.4",
"Author": "Cisco",
"Copyright": "Cisco",
"Description": "Cisco IOS-XR Native Models From Git",
Expand Down
2 changes: 1 addition & 1 deletion profiles/test/ydktest-cpp.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ydktest",
"version":"0.1.0",
"ydk_version":"0.5.0",
"core_version":"0.8.1",
"author": "Cisco",
"copyright": "Cisco",
"description": "YDK Test Profile",
Expand Down
2 changes: 1 addition & 1 deletion profiles/test/ydktest-oc-nis.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ydktest-oc-nis",
"version": "0.1.0",
"ydk_version":"0.8.1",
"core_version":"0.8.1",
"author": "Cisco",
"copyright": "Cisco",
"description": "YDK openconfig-network-instance test profile",
Expand Down
2 changes: 1 addition & 1 deletion profiles/test/ydktest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ydktest",
"version": "0.5.1",
"ydk_version":"0.5.1",
"ydk_version":"0.5.5",
"author": "Cisco",
"copyright": "Cisco",
"description": "YDK Test Profile",
Expand Down
5 changes: 5 additions & 0 deletions ydkgen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ def _generate_bundle(self, profile_file):
if self.package_name is None or self.version is None:
raise YdkGenException("Attribute 'name' and/or 'version' is not defined in the profile")

if '.' in self.package_name:
self.package_name = self.package_name.replace('.', '_')
print("WARNING. Replacing package name from '%s' to '%s'" % (profile['name'], self.package_name))
profile['name'] = self.package_name

tmp_file = tempfile.mkstemp(suffix='.bundle')[-1]
bundle_translator.translate(profile_file, tmp_file, self.ydk_root)

Expand Down
9 changes: 8 additions & 1 deletion ydkgen/printer/python/python_bindings_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
from ..tests import TestPrinter
from ydkgen.printer.language_bindings_printer import LanguageBindingsPrinter, _EmitArgs

import logging

logger = logging.getLogger('ydkgen')


class PythonBindingsPrinter(LanguageBindingsPrinter):

Expand Down Expand Up @@ -80,6 +84,7 @@ def _print_module(self, index, package, size):

# Skip generating module for empty modules
if len(package.owned_elements) == 0:
logger.debug(" Skipping module, because it does not contain top level containers")
return

sub = package.sub_name
Expand Down Expand Up @@ -155,7 +160,9 @@ def _print_python_module(self, package, index, path, size, sub):
'generate_meta': self.generate_meta,
'identity_subclasses': self.identity_subclasses,
'module_namespace_lookup' : self.module_namespace_lookup}
self.print_file(get_python_module_file_name(path, package),
python_module_file_name = get_python_module_file_name(path, package)
logger.debug(" Printing python module %s" % python_module_file_name)
self.print_file(python_module_file_name,
emit_module,
_EmitArgs(self.ypy_ctx, package, extra_args))

Expand Down
4 changes: 2 additions & 2 deletions ydkgen/resolver/bundle_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class Model(object):
__slots__ = ['_name', '_revision', '_kind', '_uri', 'iskeyword']

def __init__(self, data, iskeyword):
self._name = data['name']
self._name = data['name'].replace('.', '_')
if 'revision' in data:
self._revision = data['revision']
else:
Expand Down Expand Up @@ -228,6 +228,7 @@ def __init__(self, uri, resolved_models_root, iskeyword):
raise YdkGenException('Cannot open bundle file %s.' % uri)

try:
data['bundle']['name'] = data['bundle']['name'].replace('.', '_')
if sys.version_info > (3,):
super().__init__(data['bundle'])
else:
Expand All @@ -238,7 +239,6 @@ def __init__(self, uri, resolved_models_root, iskeyword):
if 'dependencies' in data['bundle']:
for d in data['bundle']['dependencies']:
self.dependencies.append(BundleDependency(d))

except KeyError:
raise YdkGenException('Bundle file is not well formatted.')

Expand Down

0 comments on commit af672f2

Please sign in to comment.