831 |
831 |
r = self.object_post(obj, update=True, metadata=metapairs)
|
832 |
832 |
r.release()
|
833 |
833 |
|
834 |
|
def del_object_meta(self, metakey, obj):
|
|
834 |
def del_object_meta(self, obj, metakey):
|
835 |
835 |
"""
|
836 |
|
:param metakey: (str) metadatum key
|
837 |
|
|
838 |
836 |
:param obj: (str) remote object path
|
|
837 |
|
|
838 |
:param metakey: (str) metadatum key
|
839 |
839 |
"""
|
840 |
840 |
r = self.object_post(object, update=True, metadata={metakey: ''})
|
841 |
841 |
r.release()
|
842 |
842 |
|
843 |
|
def publish_object(self, object):
|
844 |
|
r = self.object_post(object, update=True, public=True)
|
|
843 |
def publish_object(self, obj):
|
|
844 |
"""
|
|
845 |
:param obj: (str) remote object path
|
|
846 |
"""
|
|
847 |
r = self.object_post(obj, update=True, public=True)
|
845 |
848 |
r.release()
|
846 |
849 |
|
847 |
|
def unpublish_object(self, object):
|
848 |
|
r = self.object_post(object, update=True, public=False)
|
|
850 |
def unpublish_object(self, obj):
|
|
851 |
"""
|
|
852 |
:param obj: (str) remote object path
|
|
853 |
"""
|
|
854 |
r = self.object_post(obj, update=True, public=False)
|
849 |
855 |
r.release()
|
850 |
856 |
|
851 |
857 |
def get_object_info(self, obj, version=None):
|
|
858 |
"""
|
|
859 |
:param obj: (str) remote object path
|
|
860 |
|
|
861 |
:param version: (str)
|
|
862 |
|
|
863 |
:returns: (dict)
|
|
864 |
"""
|
852 |
865 |
r = self.object_head(obj, version=version)
|
853 |
866 |
return r.headers
|
854 |
867 |
|
855 |
868 |
def get_object_meta(self, obj, version=None):
|
|
869 |
"""
|
|
870 |
:param obj: (str) remote object path
|
|
871 |
|
|
872 |
:param version: (str)
|
|
873 |
|
|
874 |
:returns: (dict)
|
|
875 |
"""
|
856 |
876 |
return filter_in(self.get_object_info(obj, version=version),
|
857 |
877 |
'X-Object-Meta')
|
858 |
878 |
|
859 |
|
def get_object_sharing(self, object):
|
860 |
|
r = filter_in(self.get_object_info(object),
|
|
879 |
def get_object_sharing(self, obj):
|
|
880 |
"""
|
|
881 |
:param obj: (str) remote object path
|
|
882 |
|
|
883 |
:returns: (dict)
|
|
884 |
"""
|
|
885 |
r = filter_in(self.get_object_info(obj),
|
861 |
886 |
'X-Object-Sharing',
|
862 |
887 |
exactMatch=True)
|
863 |
888 |
reply = {}
|
... | ... | |
872 |
897 |
reply[key] = val
|
873 |
898 |
return reply
|
874 |
899 |
|
875 |
|
def set_object_sharing(self, object,
|
|
900 |
def set_object_sharing(self, obj,
|
876 |
901 |
read_permition=False,
|
877 |
902 |
write_permition=False):
|
878 |
903 |
"""Give read/write permisions to an object.
|
879 |
|
@param object is the object to change sharing permissions onto
|
880 |
|
@param read_permition is a list of users and user groups that get
|
881 |
|
read permition for this object False means all previous read
|
882 |
|
permissions will be removed
|
883 |
|
@param write_perimition is a list of users and user groups to get
|
884 |
|
write permition for this object False means all previous read
|
|
904 |
|
|
905 |
:param obj: (str) remote object path
|
|
906 |
|
|
907 |
:param read_permition: (list - bool) users and user groups that get
|
|
908 |
read permition for this object - False means all previous read
|
|
909 |
permissions will be removed
|
|
910 |
|
|
911 |
:param write_perimition: (list - bool) of users and user groups to get
|
|
912 |
write permition for this object - False means all previous write
|
885 |
913 |
permissions will be removed
|
886 |
914 |
"""
|
887 |
915 |
|
888 |
916 |
perms = dict(read='' if not read_permition else read_permition,
|
889 |
917 |
write='' if not write_permition else write_permition)
|
890 |
|
r = self.object_post(object, update=True, permissions=perms)
|
|
918 |
r = self.object_post(obj, update=True, permissions=perms)
|
891 |
919 |
r.release()
|
892 |
920 |
|
893 |
|
def del_object_sharing(self, object):
|
894 |
|
self.set_object_sharing(object)
|
|
921 |
def del_object_sharing(self, obj):
|
|
922 |
"""
|
|
923 |
:param obj: (str) remote object path
|
|
924 |
"""
|
|
925 |
self.set_object_sharing(obj)
|
|
926 |
|
|
927 |
def append_object(self, obj, source_file, upload_cb=None):
|
|
928 |
"""
|
|
929 |
:param obj: (str) remote object path
|
|
930 |
|
|
931 |
:param source_file: open file descriptor
|
895 |
932 |
|
896 |
|
def append_object(self, object, source_file, upload_cb=None):
|
897 |
|
"""@param upload_db is a generator for showing progress of upload
|
898 |
|
to caller application, e.g. a progress bar. Its next is called
|
899 |
|
whenever a block is uploaded
|
|
933 |
:param upload_db: progress.bar for uploading
|
900 |
934 |
"""
|
901 |
935 |
|
902 |
936 |
self.assert_container()
|
... | ... | |
910 |
944 |
for i in range(nblocks):
|
911 |
945 |
block = source_file.read(min(blocksize, filesize - offset))
|
912 |
946 |
offset += len(block)
|
913 |
|
r = self.object_post(object,
|
|
947 |
r = self.object_post(obj,
|
914 |
948 |
update=True,
|
915 |
949 |
content_range='bytes */*',
|
916 |
950 |
content_type='application/octet-stream',
|
... | ... | |
921 |
955 |
if upload_cb is not None:
|
922 |
956 |
upload_gen.next()
|
923 |
957 |
|
924 |
|
def truncate_object(self, object, upto_bytes):
|
925 |
|
r = self.object_post(object,
|
|
958 |
def truncate_object(self, obj, upto_bytes):
|
|
959 |
"""
|
|
960 |
:param obj: (str) remote object path
|
|
961 |
|
|
962 |
:param upto_bytes: max number of bytes to leave on file
|
|
963 |
"""
|
|
964 |
r = self.object_post(obj,
|
926 |
965 |
update=True,
|
927 |
966 |
content_range='bytes 0-%s/*' % upto_bytes,
|
928 |
967 |
content_type='application/octet-stream',
|
929 |
968 |
object_bytes=upto_bytes,
|
930 |
|
source_object=path4url(self.container, object))
|
|
969 |
source_object=path4url(self.container, obj))
|
931 |
970 |
r.release()
|
932 |
971 |
|
933 |
972 |
def overwrite_object(self,
|
934 |
|
object,
|
|
973 |
obj,
|
935 |
974 |
start,
|
936 |
975 |
end,
|
937 |
976 |
source_file,
|
938 |
977 |
upload_cb=None):
|
939 |
|
"""Overwrite a part of an object with given source file
|
940 |
|
@start the part of the remote object to start overwriting from, in
|
941 |
|
bytes
|
942 |
|
@end the part of the remote object to stop overwriting to, in bytes
|
|
978 |
"""Overwrite a part of an object from local source file
|
|
979 |
|
|
980 |
:param obj: (str) remote object path
|
|
981 |
|
|
982 |
:param start: (int) position in bytes to start overwriting from
|
|
983 |
|
|
984 |
:param end: (int) position in bytes to stop overwriting at
|
|
985 |
|
|
986 |
:param source_file: open file descriptor
|
|
987 |
|
|
988 |
:param upload_db: progress.bar for uploading
|
943 |
989 |
"""
|
944 |
990 |
|
945 |
991 |
self.assert_container()
|
... | ... | |
956 |
1002 |
filesize - offset,
|
957 |
1003 |
datasize - offset))
|
958 |
1004 |
offset += len(block)
|
959 |
|
r = self.object_post(object,
|
|
1005 |
r = self.object_post(obj,
|
960 |
1006 |
update=True,
|
961 |
1007 |
content_type='application/octet-stream',
|
962 |
1008 |
content_length=len(block),
|
... | ... | |
973 |
1019 |
public=False,
|
974 |
1020 |
content_type=None,
|
975 |
1021 |
delimiter=None):
|
|
1022 |
"""
|
|
1023 |
:param src_container: (str) source container
|
|
1024 |
|
|
1025 |
:param src_object: (str) source object path
|
|
1026 |
|
|
1027 |
:param dst_container: (str) destination container
|
|
1028 |
|
|
1029 |
:param dst_object: (str) destination object path
|
|
1030 |
|
|
1031 |
:param source_version: (str) source object version
|
|
1032 |
|
|
1033 |
:param public: (bool)
|
|
1034 |
|
|
1035 |
:param content_type: (str)
|
|
1036 |
|
|
1037 |
:param delimiter: (str)
|
|
1038 |
"""
|
976 |
1039 |
self.assert_account()
|
977 |
1040 |
self.container = dst_container
|
978 |
1041 |
dst_object = dst_object or src_object
|
... | ... | |
993 |
1056 |
public=False,
|
994 |
1057 |
content_type=None,
|
995 |
1058 |
delimiter=None):
|
|
1059 |
"""
|
|
1060 |
:param src_container: (str) source container
|
|
1061 |
|
|
1062 |
:param src_object: (str) source object path
|
|
1063 |
|
|
1064 |
:param dst_container: (str) destination container
|
|
1065 |
|
|
1066 |
:param dst_object: (str) destination object path
|
|
1067 |
|
|
1068 |
:param source_version: (str) source object version
|
|
1069 |
|
|
1070 |
:param public: (bool)
|
|
1071 |
|
|
1072 |
:param content_type: (str)
|
|
1073 |
|
|
1074 |
:param delimiter: (str)
|
|
1075 |
"""
|
996 |
1076 |
self.assert_account()
|
997 |
1077 |
self.container = dst_container
|
998 |
1078 |
dst_object = dst_object or src_object
|
... | ... | |
1008 |
1088 |
r.release()
|
1009 |
1089 |
|
1010 |
1090 |
def get_sharing_accounts(self, limit=None, marker=None, *args, **kwargs):
|
1011 |
|
"""Get accounts that share with self.account"""
|
|
1091 |
"""Get accounts that share with self.account
|
|
1092 |
|
|
1093 |
:param limit: (str)
|
|
1094 |
|
|
1095 |
:param marker: (str)
|
|
1096 |
|
|
1097 |
:returns: (dict)
|
|
1098 |
"""
|
1012 |
1099 |
self.assert_account()
|
1013 |
1100 |
|
1014 |
1101 |
self.set_param('format', 'json')
|
... | ... | |
1020 |
1107 |
r = self.get(path, *args, success=success, **kwargs)
|
1021 |
1108 |
return r.json
|
1022 |
1109 |
|
1023 |
|
def get_object_versionlist(self, path):
|
|
1110 |
def get_object_versionlist(self, obj):
|
|
1111 |
"""
|
|
1112 |
:param obj: (str) remote object path
|
|
1113 |
|
|
1114 |
:returns: (list)
|
|
1115 |
"""
|
1024 |
1116 |
self.assert_container()
|
1025 |
|
r = self.object_get(path, format='json', version='list')
|
|
1117 |
r = self.object_get(obj, format='json', version='list')
|
1026 |
1118 |
return r.json['versions']
|