Remove ruamel.yaml dependency, use pyyaml instead 70/10070/2
authorgarciadeblas <gerardo.garciadeblas@telefonica.com>
Wed, 2 Dec 2020 14:18:32 +0000 (14:18 +0000)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Thu, 3 Dec 2020 14:29:38 +0000 (14:29 +0000)
Change-Id: Ifb51246e4f920f4e1ef98e1d8393ea93cf4e64e0
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
osmclient/sol005/osmrepo.py
requirements.txt
setup.py

index efd2207..3aa3720 100644 (file)
@@ -31,7 +31,7 @@ from osmclient.common.package_tool import PackageTool
 from osmclient.sol005.repo import Repo
 from packaging import version as versioning
 import requests
-import ruamel.yaml
+import yaml
 
 
 class OSMRepo(Repo):
@@ -64,7 +64,7 @@ class OSMRepo(Repo):
                 r = requests.get('{}/index.yaml'.format(repository.get('url')))
 
                 if r.status_code == 200:
-                    repo_list = ruamel.yaml.safe_load(r.text)
+                    repo_list = yaml.safe_load(r.text)
                     vnf_packages = repo_list.get('{}_packages'.format(pkgtype))
                     for repo in vnf_packages:
                         versions = vnf_packages.get(repo)
@@ -137,7 +137,7 @@ class OSMRepo(Repo):
             raise ClientException('Package not found')
         folder, descriptor = self.zip_extraction(pkg_name)
         with open(descriptor) as pkg:
-            pkg_descriptor = ruamel.yaml.safe_load(pkg)
+            pkg_descriptor = yaml.safe_load(pkg)
         rmtree(folder, ignore_errors=False)
         if ((pkgtype == 'vnf' and (pkg_descriptor.get('vnfd') or pkg_descriptor.get('vnfd:vnfd_catalog'))) or
                 (pkgtype == 'ns' and (pkg_descriptor.get('nsd') or pkg_descriptor.get('nsd:nsd_catalog')))):
@@ -337,28 +337,31 @@ class OSMRepo(Repo):
                 mkdir(final_path)
                 copyfile(path,
                          final_path + '/' + fields.get('id') + "-" + fields.get('version') + '.tar.gz')
-                ruamel.yaml.dump(fields, open(final_path + '/' + 'metadata.yaml', 'w'),
-                                 Dumper=ruamel.yaml.RoundTripDumper)
-                index = ruamel.yaml.load(open(destination + '/index.yaml'), Loader=ruamel.yaml.Loader)
+                yaml.safe_dump(fields, open(final_path + '/' + 'metadata.yaml', 'w'),
+                               default_flow_style=False, width=80, indent=4)
+                index = yaml.safe_load(open(destination + '/index.yaml'))
 
                 index['{}_packages'.format(package_type)][fields.get('id')][fields.get('version')] = data_ind
                 if versioning.parse(index['{}_packages'.format(package_type)][fields.get('id')][
                                     'latest']) < versioning.parse(fields.get('version')):
                     index['{}_packages'.format(package_type)][fields.get('id')]['latest'] = fields.get(
                         'version')
-                ruamel.yaml.dump(index, open(destination + '/index.yaml', 'w'), Dumper=ruamel.yaml.RoundTripDumper)
+                yaml.safe_dump(index, open(destination + '/index.yaml', 'w'),
+                               default_flow_style=False, width=80, indent=4)
                 self._logger.info('{} {} added in the repository'.format(package_type.upper(), str(path)))
         else:
             mkdir(destination + '/{}/'.format(package_type) + fields.get('id'))
             mkdir(final_path)
             copyfile(path,
                      final_path + '/' + fields.get('id') + "-" + fields.get('version') + '.tar.gz')
-            ruamel.yaml.dump(fields, open(join(final_path, 'metadata.yaml'), 'w'), Dumper=ruamel.yaml.RoundTripDumper)
-            index = ruamel.yaml.load(open(destination + '/index.yaml'), Loader=ruamel.yaml.Loader)
+            yaml.safe_dump(fields, open(join(final_path, 'metadata.yaml'), 'w'),
+                           default_flow_style=False, width=80, indent=4)
+            index = yaml.safe_load(open(destination + '/index.yaml'))
 
             index['{}_packages'.format(package_type)][fields.get('id')] = {fields.get('version'): data_ind}
             index['{}_packages'.format(package_type)][fields.get('id')]['latest'] = fields.get('version')
-            ruamel.yaml.dump(index, open(join(destination, 'index.yaml'), 'w'), Dumper=ruamel.yaml.RoundTripDumper)
+            yaml.safe_dump(index, open(join(destination, 'index.yaml'), 'w'),
+                           default_flow_style=False, width=80, indent=4)
             self._logger.info('{} {} added in the repository'.format(package_type.upper(), str(path)))
 
     def current_datatime(self):
@@ -384,5 +387,5 @@ class OSMRepo(Repo):
             index_data = {'apiVersion': 'v1', 'generated': self.current_datatime(), 'vnf_packages': {},
                           'ns_packages': {}}
             with open(join(destination, 'index.yaml'), 'w') as outfile:
-                ruamel.yaml.dump(index_data, outfile, default_flow_style=False)
+                yaml.safe_dump(index_data, outfile, default_flow_style=False, width=80, indent=4)
 
index 26adb57..f3cb782 100644 (file)
@@ -22,6 +22,5 @@ python-magic
 jinja2
 verboselogs
 packaging
-ruamel.yaml
 requests
 git+https://osm.etsi.org/gerrit/osm/IM.git#egg=osm-im
index 2140468..7c6ad39 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -29,8 +29,7 @@ setup(
     license='Apache 2',
     install_requires=[
         'Click', 'prettytable', 'pyyaml', 'pycurl', 'python-magic',
-        'jinja2', 'osm-im', 'verboselogs', 'packaging', 'ruamel.yaml',
-        'requests',
+        'jinja2', 'osm-im', 'verboselogs', 'packaging', 'requests',
         'osm-im @ git+https://osm.etsi.org/gerrit/osm/IM.git#egg=osm-im',
     ],
     setup_requires=['setuptools-version-command'],