def file_exists(self, path): with fileManager.session_scope() as session: if path=='': path='/' if path[0]!='/': path='/'+path return self.fm.file_exists(path,session)
def _delete_directory(self, path): with fileManager.session_scope() as session: try: deleted_count = self.fm.delete_directory( path,session) except DirectoryNotEmpty: self.not_empty(path) if not deleted_count: self.no_such_entity(path)
def _save_file(self, model, path): """ Save a non-notebook file. """ with fileManager.session_scope() as session: self.fm.save_file(path, to_b64(model['content'], model.get('format', None),session) ) return None
def _get_file(self, path, content, format): with fileManager.session_scope() as session: try: record = self.fm.get_file(path, session,content=content) except NoSuchFile: if self.dir_exists(path): raise HTTPError (400,u"Wrong type: %s" % path) else: raise HTTPError (400,u"Not found: %s" % path) return self._file_model_from_db(record, content, format)
def _get_notebook(self, path, content, format): """ Get a notebook from the database. """ with fileManager.session_scope() as session: try: record = self.fm.get_file(path, session,content=content) except NoSuchFile: self.no_such_entity(path) return self._notebook_model_from_db(record, content)
def _save_notebook(self, model, path): """ Save a notebook. Returns a validation message. """ with fileManager.session_scope() as session: nb_contents = nbformat.from_dict(model['content']) self.check_and_sign(nb_contents, path) self.fm.save_file(path, writes_base64(nb_contents),session) # It's awkward that this writes to the model instead of returning. self.validate_notebook_model(model) return model.get('message')
def _get_directory(self, path, content, format): """ Get a directory from the database. """ with fileManager.session_scope() as session: try: record = self.fm.get_directory(path, content,session) except NoSuchDirectory: if self.file_exists(path): raise HTTPError(400, "Wrong type: %s" % path) else: self.no_such_entity(path) return self._directory_model_from_db(record, content,session)
def rename_file(self, old_path, path): """ Rename object from old_path to path. NOTE: This method is unfortunately named on the base class. It actually moves a file or a directory. """ with fileManager.session_scope() as session: try: if self.file_exists(old_path): self.fm.rename_file( old_path, path,session) elif self.dir_exists(old_path): self.fm.rename_directory(old_path, path,session) else: print "it does not work!" except (FileExists, DirectoryExists): self.already_exists(path)
def _delete_non_directory(self, path): with fileManager.session_scope() as session: deleted_count = self.fm.delete_file(path,session) if not deleted_count: print "Problem with deleting"
def _save_directory(self, path): """ 'Save' a directory. """ with fileManager.session_scope() as session: self.fm.save_directory(path,session)