def get_napps_from_path(path: Path): """List all NApps found in ``napps_dir``.""" if not path.exists(): LOG.warning("NApps dir (%s) doesn't exist.", path) return [] jsons = path.glob('*/*/kytos.json') return [NApp.create_from_json(j) for j in jsons]
def _list_all(napps_dir): """List all NApps found in ``napps_dir``.""" if not napps_dir.exists(): log.warning("NApps dir (%s) doesn't exist.", napps_dir) return [] jsons = napps_dir.glob('*/*/kytos.json') return [NApp.create_from_json(j) for j in jsons]
def get_napps_from_path(path: Path): """List all NApps found in ``napps_dir``.""" if not path.exists(): LOG.warning("NApps dir (%s) doesn't exist.", path) return [] jsons = path.glob('*/*/kytos.json') return [NApp.create_from_json(j) for j in jsons]
def test_create_from_json(self, mock_open): """Test create_from_json method.""" data_file = MagicMock() data_file.read.return_value = '{"username": "******", \ "name": "napp", \ "version": "1.0", \ "repository": "any"}' mock_open.return_value.__enter__.return_value = data_file napp = NApp.create_from_json('filename') self.assertEqual(napp.username, 'kytos') self.assertEqual(napp.name, 'napp') self.assertEqual(napp.version, '1.0') self.assertEqual(napp.repository, 'any')
def install(self, napp_uri, enable=True): """Install and enable a NApp from its repository. By default, install procedure will also enable the NApp. If you only want to install and keep NApp disabled, please use enable=False. """ napp = NApp.create_from_uri(napp_uri) if napp in self.get_all_napps(): LOG.warning("Unable to install NApp %s. Already installed.", napp) return False if not napp.repository: napp.repository = self._controller.options.napps_repositories[0] pkg_folder = None try: pkg_folder = napp.download() napp_folder = self._find_napp(napp, pkg_folder) dst = self._installed_path / napp.username / napp.name self._create_module(dst.parent) shutil.move(str(napp_folder), str(dst)) finally: if pkg_folder and pkg_folder.exists(): shutil.rmtree(str(pkg_folder)) LOG.info("New NApp installed: %s", napp) napp = NApp.create_from_json(dst / 'kytos.json') for uri in napp.napp_dependencies: self.install(uri, enable) if enable: return self.enable(napp.username, napp.name) return True
def install(self, napp_uri, enable=True): """Install and enable a NApp from its repository. By default, install procedure will also enable the NApp. If you only want to install and keep NApp disabled, please use enable=False. """ napp = NApp.create_from_uri(napp_uri) if napp in self.get_all_napps(): LOG.warning("Unable to install NApp %s. Already installed.", napp) return False if not napp.repository: napp.repository = self._controller.options.napps_repositories[0] pkg_folder = None try: pkg_folder = napp.download() napp_folder = self._find_napp(napp, pkg_folder) dst = self._installed_path / napp.username / napp.name self._create_module(dst.parent) shutil.move(str(napp_folder), str(dst)) finally: if pkg_folder and pkg_folder.exists(): shutil.rmtree(str(pkg_folder)) LOG.info("New NApp installed: %s", napp) napp = NApp.create_from_json(dst/'kytos.json') for uri in napp.napp_dependencies: self.install(uri, enable) if enable: return self.enable(napp.username, napp.name) return True