def install_napp(cls, mgr): """Install a NApp. Raises: KytosException: If a NApp hasn't been found. """ try: LOG.info(' Searching local NApp...') mgr.install_local() LOG.info(' Found and installed.') except FileNotFoundError: LOG.info(' Not found. Downloading from NApps Server...') try: mgr.remote_install() LOG.info(' Downloaded and installed.') return except HTTPError as exception: if exception.code == 404: LOG.error(' NApp not found.') else: LOG.error(' NApps Server error: %s', exception) except URLError as exception: LOG.error(' NApps Server error: %s', str(exception.reason)) raise KytosException("NApp not found.")
def parse_napp(napp_id): """Convert a napp_id in tuple with username, napp name and version. Args: napp_id: String with the form 'username/napp[:version]' (version is optional). If no version is found, it will be None. Returns: tuple: A tuple with (username, napp, version) Raises: KytosException: If a NApp has not the form _username/name_. """ # `napp_id` regex, composed by two mandatory parts (username, napp_name) # and one optional (version). # username and napp_name need to start with a letter, are composed of # letters, numbers and uderscores and must have at least three characters. # They are separated by a colon. # version is optional and can take any format. Is is separated by a hyphen, # if a version is defined. regex = r'([a-zA-Z][a-zA-Z0-9_]{2,})/([a-zA-Z][a-zA-Z0-9_]{2,}):?(.+)?' compiled_regex = re.compile(regex) matched = compiled_regex.fullmatch(napp_id) if not matched: msg = '"{}" NApp has not the form username/napp_name[:version].' raise KytosException(msg.format(napp_id)) return matched.groups()
def get_napp(self, username, name): """Return napp metadata or None if not found.""" endpoint = os.path.join(self._config.get('napps', 'api'), 'napps', username, name, '') res = self.make_request(endpoint) if res.status_code == 404: # We need to know if NApp is not found return None elif res.status_code != 200: raise KytosException('Error getting %s/%s from server: (%d) - %s', username, name, res.status_code, res.reason) return json.loads(res.content)
def install_napp(cls, mgr): """Install a NApp. Raises: KytosException: If a NApp hasn't been found. """ LOG.info(' Downloading from NApps Server...') try: mgr.remote_install() LOG.info(' Downloaded and installed.') return except HTTPError as exception: if exception.code == 404: LOG.error(' NApp not found.') LOG.info(" If you are trying to install a local NApp, " "use the command 'python setup.py develop' " "inside the 'user/napp' directory.") elif exception.code == 400: LOG.error(' NApps Server error: %s', exception) except URLError as exception: LOG.error(' NApps Server error: %s', str(exception.reason)) raise KytosException("NApp not found.")