def delete(self, request, context): """删除一个文件 """ file_name = os.path.join(self.ROOT_PATH, request.filename) result = True try: os.remove(file_name) except: result = False return file_pb2.Bool(isOK=result)
def upload(self, request, context): """上传一个文件,判断是否OK """ file_name = os.path.join(self.ROOT_PATH, request.filename) file_context = request.context result = False try: f = open(file_name, 'r') f.close() except: with open(file_name, 'w', encoding='utf-8') as f: f.write(file_context) result = True return file_pb2.Bool(isOK=result)
def create(self, request, context): """创建一个文件 """ file_name = os.path.join(self.ROOT_PATH, request.filename) result = False try: f = open(file_name, 'r') f.close() except: with open(file_name, 'w') as f: result = True finally: return file_pb2.Bool(isOK=result)