| 1037 | |
| 1038 | |
| 1039 | class Resource(object): |
| 1040 | |
| 1041 | def __init__(self, client, urn): |
| 1042 | self.client = client |
| 1043 | self.urn = urn |
| 1044 | |
| 1045 | def __str__(self): |
| 1046 | return "resource {path}".format(path=self.urn.path()) |
| 1047 | |
| 1048 | def is_dir(self): |
| 1049 | return self.client.is_dir(self.urn.path()) |
| 1050 | |
| 1051 | def rename(self, new_name): |
| 1052 | |
| 1053 | old_path = self.urn.path() |
| 1054 | parent_path = self.urn.parent() |
| 1055 | new_name = Urn(new_name).filename() |
| 1056 | new_path = "{directory}{filename}".format(directory=parent_path, filename=new_name) |
| 1057 | |
| 1058 | self.client.move(remote_path_from=old_path, remote_path_to=new_path) |
| 1059 | self.urn = Urn(new_path) |
| 1060 | |
| 1061 | def move(self, remote_path): |
| 1062 | |
| 1063 | new_urn = Urn(remote_path) |
| 1064 | self.client.move(remote_path_from=self.urn.path(), remote_path_to=new_urn.path()) |
| 1065 | self.urn = new_urn |
| 1066 | |
| 1067 | def copy(self, remote_path): |
| 1068 | |
| 1069 | urn = Urn(remote_path) |
| 1070 | self.client.copy(remote_path_from=self.urn.path(), remote_path_to=remote_path) |
| 1071 | return Resource(self.client, urn) |
| 1072 | |
| 1073 | def info(self, params=None): |
| 1074 | |
| 1075 | info = self.client.info(self.urn.path()) |
| 1076 | if not params: |
| 1077 | return info |
| 1078 | |
| 1079 | return {key: value for (key, value) in info.items() if key in params} |
| 1080 | |
| 1081 | def clean(self): |
| 1082 | return self.client.clean(self.urn.path()) |
| 1083 | |
| 1084 | def check(self): |
| 1085 | return self.client.check(self.urn.path()) |
| 1086 | |
| 1087 | def read_from(self, buff): |
| 1088 | self.client.upload_from(buff=buff, remote_path=self.urn.path()) |
| 1089 | |
| 1090 | def read(self, local_path): |
| 1091 | return self.client.upload_sync(local_path=local_path, remote_path=self.urn.path()) |
| 1092 | |
| 1093 | def read_async(self, local_path, callback=None): |
| 1094 | return self.client.upload_async(local_path=local_path, remote_path=self.urn.path(), callback=callback) |
| 1095 | |
| 1096 | def write_to(self, buff): |