Beispiel #1
0
    def notebook_exists(self, notebook_id):
        """Does a Narrative with notebook_id exist?

        Returns True if a Narrative with id notebook_id (format = ws.XXX.obj.YYY) exists,
        and returns False otherwise.
        """
        user_id = self.get_userid()
        if user_id is None:
            raise web.HTTPError(400, u'Cannot determine valid user identity!')
        # Look for it in the currently loaded map
        exists = super(KBaseWSNotebookManager, self).notebook_exists(notebook_id)
        self.log.debug("notebook_exists(%s) = %s"%(notebook_id,exists))
        if not exists:
            # The notebook doesn't exist among the notebooks we've loaded, lets see
            # if it exists at all in the workspace service
            self.log.debug("Checking other workspace")
            m = self.ws_regex.match(notebook_id)
            if not m:
                return False
            self.log.debug("Checking other workspace %s for %s"%(m.group('wsid'),m.group('objid')))
            objmeta = ws_util.get_wsobj_meta(self.wsclient(), ws_id=m.group('wsid'))
            if notebook_id in objmeta:
                self.mapping[notebook_id] = notebook_id
                return True
            else:
                return False
        return exists
Beispiel #2
0
    def list_notebooks(self):
        """List all notebooks in WSS
        For the ID field, we use "{ws_id}.{obj_id}"
        The obj_id field is sanitized version of document.ipynb.metadata.name

        Returns a list of dicts with two keys: 'name' and 'notebook_id'. 'name'
        should be of the format 'workspace name/Narrative name' and id should have
        the format 'ws.###.obj.###'
        """
        self.log.debug("Listing Narratives")
        self.log.debug("kbase_session = %s" % str(self.kbase_session))
        wsclient = self.wsclient()
        all = ws_util.get_wsobj_meta(wsclient)

        self.mapping = {
            ws_id: "%s/%s" % (all[ws_id]['workspace'], all[ws_id]['meta'].get(
                'name', "undefined"))
            for ws_id in all.keys()
        }
        self.rev_mapping = {
            self.mapping[ws_id]: ws_id
            for ws_id in self.mapping.keys()
        }
        data = [
            dict(notebook_id=it[0], name=it[1]) for it in self.mapping.items()
        ]
        data = sorted(data, key=lambda item: item['name'])
        return data
Beispiel #3
0
    def list_notebooks(self):
        """List all notebooks in WSS
        For the ID field, we use "{ws_id}.{obj_id}"
        The obj_id field is sanitized version of document.ipynb.metadata.name

        Returns a list of dicts with two keys: 'name' and 'notebook_id'. 'name'
        should be of the format 'workspace name/Narrative name' and id should have
        the format 'ws.###.obj.###'
        """
        self.log.debug("Listing Narratives")
        self.log.debug("kbase_session = %s" % str(self.kbase_session))
        wsclient = self.wsclient()
        try:
            all = ws_util.get_wsobj_meta(wsclient)
        except Exception, e:
            # Raising the exception here will cause the server to
            # shut down, so don't crash, just return nothing.
            return []
Beispiel #4
0
    def list_notebooks(self):
        """List all notebooks in WSS
        For the ID field, we use "{ws_id}.{obj_id}"
        The obj_id field is sanitized version of document.ipynb.metadata.name
        """
        self.log.debug("listing Narratives.")
        self.log.debug("kbase_session = %s" % str(self.kbase_session))
        wsclient = self.wsclient()
        all = ws_util.get_wsobj_meta( wsclient)

        self.mapping = {
            ws_id: "%s/%s" % (all[ws_id]['workspace'],all[ws_id]['meta'].get('name',"undefined"))
            for ws_id in all.keys()
        }
        self.rev_mapping = { self.mapping[ws_id] : ws_id for ws_id in self.mapping.keys() }
        data = [ dict(notebook_id = it[0], name = it[1]) for it in self.mapping.items()]
        data = sorted(data, key=lambda item: item['name'])
        return data
Beispiel #5
0
 def notebook_exists(self, notebook_id):
     """Does a notebook exist?"""
     wsclient = self.wsclient()
     user_id = self.kbase_session.get('user_id', ws_util.get_user_id(wsclient))
     if user_id is None:
         raise web.HTTPError(400, u'Cannot determine valid user identity!')
     exists = super(KBaseWSNotebookManager, self).notebook_exists(notebook_id)
     self.log.debug("notebook_exists(%s) = %s"%(notebook_id,exists))
     if not exists:
         # The notebook doesn't exist among the notebooks we've loaded, lets see
         # if it exists at all in the workspace service
         self.log.debug("Checking other workspace")
         m = self.ws_regex.match(notebook_id)
         if not m:
             return False
         self.log.debug("Checking other workspace %s for %s"%(m.group('wsid'),m.group('objid')))
         objmeta = ws_util.get_wsobj_meta( self.wsclient(), ws_id=m.group('wsid'))
         self.log.debug("Checking other workspace %s for %s"%(m.group('wsid'),m.group('objid')))
         if notebook_id in objmeta:
             self.mapping[notebook_id] = notebook_id
             return True
         else:
             return False
     return exists