def modDataObjMeta(self, data_obj_info, meta_dict, **options): if "rescHier" not in data_obj_info and "rescName" not in data_obj_info and "replNum" not in data_obj_info: meta_dict["all"] = "" message_body = ModDataObjMeta( dataObjInfo=DataObjInfo( objPath=data_obj_info["objPath"], rescName=data_obj_info.get("rescName", ""), rescHier=data_obj_info.get("rescHier", ""), dataType="", dataSize=0, chksum="", version="", filePath="", dataOwnerName="", dataOwnerZone="", replNum=data_obj_info.get("replNum", 0), replStatus=0, statusString="", dataId=0, collId=0, dataMapId=0, flags=0, dataComments="", dataMode="", dataExpiry="", dataCreate="", dataModify="", dataAccess="", dataAccessInx=0, writeFlag=0, destRescName="", backupRescName="", subPath="", specColl=0, regUid=0, otherFlags=0, KeyValPair_PI=StringStringMap(options), in_pdmo="", next=0, rescId=0 ), regParam=StringStringMap(meta_dict) ) message = iRODSMessage('RODS_API_REQ', msg=message_body, int_info=api_number['MOD_DATA_OBJ_META_AN']) with self.sess.pool.get_connection() as conn: conn.send(message) response = conn.recv()
def test_gen_query_inp(self): gq = GenQueryRequest() gq.maxRows = 4 gq.continueInx = 3 gq.partialStartIndex = 2 gq.options = 1 kvp = StringStringMap() kvp.ssLen = 2 kvp.keyWord = ['one', 'two'] kvp.svalue = ['three', 'four'] iip = IntegerIntegerMap() iip.iiLen = 2 iip.inx = [4, 5] iip.ivalue = [1, 2] ivp = IntegerStringMap() ivp.isLen = 2 ivp.inx = [1, 2] ivp.svalue = ['five', 'six'] gq.KeyValPair_PI = kvp gq.InxIvalPair_PI = iip gq.InxValPair_PI = ivp expected = "<GenQueryInp_PI><maxRows>4</maxRows><continueInx>3</continueInx><partialStartIndex>2</partialStartIndex><options>1</options><KeyValPair_PI><ssLen>2</ssLen><keyWord>one</keyWord><keyWord>two</keyWord><svalue>three</svalue><svalue>four</svalue></KeyValPair_PI><InxIvalPair_PI><iiLen>2</iiLen><inx>4</inx><inx>5</inx><ivalue>1</ivalue><ivalue>2</ivalue></InxIvalPair_PI><InxValPair_PI><isLen>2</isLen><inx>1</inx><inx>2</inx><svalue>five</svalue><svalue>six</svalue></InxValPair_PI></GenQueryInp_PI>" self.assertEqual(gq.pack(), expected) gq2 = GenQueryRequest() gq2.unpack(ET.fromstring(expected)) self.assertEqual(gq2.maxRows, 4) self.assertEqual(gq2.continueInx, 3) self.assertEqual(gq2.partialStartIndex, 2) self.assertEqual(gq2.options, 1) self.assertEqual(gq2.KeyValPair_PI.ssLen, 2) self.assertEqual(gq2.KeyValPair_PI.keyWord, ["one", "two"]) self.assertEqual(gq2.KeyValPair_PI.svalue, ["three", "four"]) self.assertEqual(gq2.InxIvalPair_PI.iiLen, 2) self.assertEqual(gq2.InxIvalPair_PI.inx, [4, 5]) self.assertEqual(gq2.InxIvalPair_PI.ivalue, [1, 2]) self.assertEqual(gq2.InxValPair_PI.isLen, 2) self.assertEqual(gq2.InxValPair_PI.inx, [1, 2]) self.assertEqual(gq2.InxValPair_PI.svalue, ["five", "six"]) self.assertEqual(gq2.pack(), expected)
def test_gen_query_inp(self): gq = GenQueryRequest() gq.maxRows = 4 gq.continueInx = 3 gq.partialStartIndex = 2 gq.options = 1 kvp = StringStringMap() kvp.ssLen = 2 kvp.keyWord = ['one', 'two'] kvp.svalue = ['three', 'four'] iip = IntegerIntegerMap() iip.iiLen = 2 iip.inx = [4, 5] iip.ivalue = [1, 2] ivp = IntegerStringMap() ivp.isLen = 2 ivp.inx = [1, 2] ivp.svalue = ['five', 'six'] gq.KeyValPair_PI = kvp gq.InxIvalPair_PI = iip gq.InxValPair_PI = ivp expected = "<GenQueryInp_PI><maxRows>4</maxRows><continueInx>3</continueInx><partialStartIndex>2</partialStartIndex><options>1</options><KeyValPair_PI><ssLen>2</ssLen><keyWord>one</keyWord><keyWord>two</keyWord><svalue>three</svalue><svalue>four</svalue></KeyValPair_PI><InxIvalPair_PI><iiLen>2</iiLen><inx>4</inx><inx>5</inx><ivalue>1</ivalue><ivalue>2</ivalue></InxIvalPair_PI><InxValPair_PI><isLen>2</isLen><inx>1</inx><inx>2</inx><svalue>five</svalue><svalue>six</svalue></InxValPair_PI></GenQueryInp_PI>" self.assertEqual(gq.pack(), expected) gq2 = GenQueryRequest() gq2.unpack(ET().fromstring(expected)) self.assertEqual(gq2.maxRows, 4) self.assertEqual(gq2.continueInx, 3) self.assertEqual(gq2.partialStartIndex, 2) self.assertEqual(gq2.options, 1) self.assertEqual(gq2.KeyValPair_PI.ssLen, 2) self.assertEqual(gq2.KeyValPair_PI.keyWord, ["one", "two"]) self.assertEqual(gq2.KeyValPair_PI.svalue, ["three", "four"]) self.assertEqual(gq2.InxIvalPair_PI.iiLen, 2) self.assertEqual(gq2.InxIvalPair_PI.inx, [4, 5]) self.assertEqual(gq2.InxIvalPair_PI.ivalue, [1, 2]) self.assertEqual(gq2.InxValPair_PI.isLen, 2) self.assertEqual(gq2.InxValPair_PI.inx, [1, 2]) self.assertEqual(gq2.InxValPair_PI.svalue, ["five", "six"]) self.assertEqual(gq2.pack(), expected)
def create(self, path, resource=None, options=None): if options is None: options = {} kvp = {kw.DATA_TYPE_KW: 'generic'} if resource: kvp[kw.DEST_RESC_NAME_KW] = resource kvp.update(options) message_body = FileOpenRequest( objPath=path, createMode=0644, openFlags=0, offset=0, dataSize=-1, numThreads=0, oprType=0, KeyValPair_PI=StringStringMap(kvp), ) message = iRODSMessage('RODS_API_REQ', msg=message_body, int_info=api_number['DATA_OBJ_CREATE_AN']) with self.sess.pool.get_connection() as conn: conn.send(message) response = conn.recv() desc = response.int_info conn.close_file(desc) return self.get(path)
def open(self, path, mode, options=None): flags, seek_to_end = { 'r': (O_RDONLY, False), 'r+': (O_RDWR, False), 'w': (O_WRONLY | O_CREAT, False), 'w+': (O_RDWR | O_CREAT, False), 'a': (O_WRONLY | O_CREAT, True), 'a+': (O_RDWR | O_CREAT, True), }[mode] # TODO: Use seek_to_end message_body = FileOpenRequest( objPath=path, createMode=0, openFlags=flags, offset=0, dataSize=-1, numThreads=0, oprType=0, KeyValPair_PI=StringStringMap(options), ) message = iRODSMessage('RODS_API_REQ', msg=message_body, int_info=api_number['DATA_OBJ_OPEN_AN']) conn = self.sess.pool.get_connection() conn.send(message) desc = conn.recv().int_info return BufferedRandom(iRODSDataObjectFileRaw(conn, desc, options))
def unlink(self, path, force=False, **options): if force: options[kw.FORCE_FLAG_KW] = '' try: oprType = options[kw.OPR_TYPE_KW] except KeyError: oprType = 0 message_body = FileOpenRequest( objPath=path, createMode=0, openFlags=0, offset=0, dataSize=-1, numThreads=self.sess.numThreads, oprType=oprType, KeyValPair_PI=StringStringMap(options), ) message = iRODSMessage('RODS_API_REQ', msg=message_body, int_info=api_number['DATA_OBJ_UNLINK_AN']) with self.sess.pool.get_connection() as conn: conn.send(message) response = conn.recv()
def _kw_message(self): dct = dict([ (criterion.query_key.icat_key, criterion.op + ' ' + criterion.value) for criterion in self.criteria if isinstance(criterion.query_key, Keyword) ]) return StringStringMap(dct)
def execute(self, limit=MAX_SQL_ROWS, offset=0, options=0, conditions=None): target = self._alias or self._sql if conditions is None: conditions = StringStringMap({}) sql_args = {} for i, arg in enumerate(self._args[:10], start=1): sql_args['arg{}'.format(i)] = arg message_body = SpecificQueryRequest(sql=target, maxRows=limit, continueInx=self._continue_index, rowOffset=offset, options=0, KeyValPair_PI=conditions, **sql_args) request = iRODSMessage("RODS_API_REQ", msg=message_body, int_info=api_number['SPECIFIC_QUERY_AN']) with self.session.pool.get_connection() as conn: conn.send(request) response = conn.recv() results = response.get_main_message(GenQueryResponse) return SpecificQueryResultSet(results, self._columns)
def remove(self, path, recurse=True, force=False, **options): if recurse: options[kw.RECURSIVE_OPR__KW] = '' if force: options[kw.FORCE_FLAG_KW] = '' try: oprType = options[kw.OPR_TYPE_KW] except KeyError: oprType = 0 message_body = CollectionRequest( collName=path, flags=0, oprType=oprType, KeyValPair_PI=StringStringMap(options)) message = iRODSMessage('RODS_API_REQ', msg=message_body, int_info=api_number['RM_COLL_AN']) with self.sess.pool.get_connection() as conn: conn.send(message) response = conn.recv() while response.int_info == SYS_SVR_TO_CLI_COLL_STAT: conn.reply(SYS_CLI_TO_SVR_COLL_STAT_REPLY) response = conn.recv()
def read_file(self, desc, size=-1, buffer=None): if size < 0: size = len(buffer) elif buffer is not None: size = min(size, len(buffer)) message_body = OpenedDataObjRequest(l1descInx=desc, len=size, whence=0, oprType=0, offset=0, bytesWritten=0, KeyValPair_PI=StringStringMap()) message = iRODSMessage('RODS_API_REQ', msg=message_body, int_info=api_number['DATA_OBJ_READ_AN']) logger.debug(desc) self.send(message) if buffer is None: response = self.recv() else: response = self.recv_into(buffer) return response.bs
def create(self, path, resource=None, **options): options[kw.DATA_TYPE_KW] = 'generic' if resource: options[kw.DEST_RESC_NAME_KW] = resource else: # Use client-side default resource if available try: options[kw.DEST_RESC_NAME_KW] = self.sess.default_resource except AttributeError: pass message_body = FileOpenRequest( objPath=path, createMode=0o644, openFlags=0, offset=0, dataSize=-1, numThreads=self.sess.numThreads, oprType=0, KeyValPair_PI=StringStringMap(options), ) message = iRODSMessage('RODS_API_REQ', msg=message_body, int_info=api_number['DATA_OBJ_CREATE_AN']) with self.sess.pool.get_connection() as conn: conn.send(message) response = conn.recv() desc = response.int_info conn.close_file(desc) return self.get(path)
def execute(self): # rule input param_array = [] for label, value in self.params.items(): inOutStruct = STR_PI(myStr=value) param_array.append( MsParam(label=label, type='STR_PI', inOutStruct=inOutStruct)) inpParamArray = MsParamArray(paramLen=len(param_array), oprType=0, MsParam_PI=param_array) # rule body addr = RodsHostAddress(hostAddr='', rodsZone='', port=0, dummyInt=0) condInput = StringStringMap({}) message_body = RuleExecutionRequest(myRule=self.body, addr=addr, condInput=condInput, outParamDesc=self.output, inpParamArray=inpParamArray) request = iRODSMessage("RODS_API_REQ", msg=message_body, int_info=api_number['EXEC_MY_RULE_AN']) with self.session.pool.get_connection() as conn: conn.send(request) response = conn.recv() out_param_array = response.get_main_message(MsParamArray) self.session.cleanup() return out_param_array
def create(self, path): message_body = CollectionRequest(collName=path, KeyValPair_PI=StringStringMap()) message = iRODSMessage('RODS_API_REQ', msg=message_body, int_info=api_number['COLL_CREATE201_AN']) with self.sess.pool.get_connection() as conn: conn.send(message) response = conn.recv() return self.get(path)
def test_key_val_pair(self): kvp = StringStringMap() kvp.ssLen = 2 kvp.keyWord = ["one", "two"] kvp.svalue = ["three", "four"] expected = "<KeyValPair_PI>\ <ssLen>2</ssLen>\ <keyWord>one</keyWord>\ <keyWord>two</keyWord>\ <svalue>three</svalue>\ <svalue>four</svalue>\ </KeyValPair_PI>" self.assertEqual(kvp.pack(), expected) kvp2 = StringStringMap() kvp2.unpack(ET.fromstring(expected)) self.assertEqual(kvp2.ssLen, 2) self.assertEqual(kvp2.keyWord, ["one", "two"]) self.assertEqual(kvp2.svalue, ["three", "four"])
def copy(self, src_path, dest_path, options=None): if options is None: options = {} # check if dest is a collection # if so append filename to it if self.sess.collections.exists(dest_path): filename = src_path.rsplit('/', 1)[1] target_path = dest_path + '/' + filename else: target_path = dest_path src = FileOpenRequest( objPath=src_path, createMode=0, openFlags=0, offset=0, dataSize=0, numThreads=self.sess.numThreads, oprType=10, # COPY_SRC KeyValPair_PI=StringStringMap(), ) dest = FileOpenRequest( objPath=target_path, createMode=0, openFlags=0, offset=0, dataSize=0, numThreads=self.sess.numThreads, oprType=9, # COPY_DEST KeyValPair_PI=StringStringMap(options), ) message_body = ObjCopyRequest(srcDataObjInp_PI=src, destDataObjInp_PI=dest) message = iRODSMessage('RODS_API_REQ', msg=message_body, int_info=api_number['DATA_OBJ_COPY_AN']) with self.sess.pool.get_connection() as conn: conn.send(message) response = conn.recv()
def create(self, path, recurse=True, **options): if recurse: options[kw.RECURSIVE_OPR__KW] = '' message_body = CollectionRequest( collName=path, KeyValPair_PI=StringStringMap(options)) message = iRODSMessage('RODS_API_REQ', msg=message_body, int_info=api_number['COLL_CREATE_AN']) with self.sess.pool.get_connection() as conn: conn.send(message) response = conn.recv() return self.get(path)
def execute(self, session_cleanup=True, acceptable_errors=(ex.FAIL_ACTION_ENCOUNTERED_ERR, ), r_error=None, return_message=()): try: # rule input param_array = [] for label, value in self.params.items(): inOutStruct = STR_PI(myStr=value) param_array.append( MsParam(label=label, type='STR_PI', inOutStruct=inOutStruct)) inpParamArray = MsParamArray(paramLen=len(param_array), oprType=0, MsParam_PI=param_array) # rule body addr = RodsHostAddress(hostAddr='', rodsZone='', port=0, dummyInt=0) condInput = StringStringMap({} if self.instance_name is None else {'instance_name': self.instance_name}) message_body = RuleExecutionRequest(myRule=self.body, addr=addr, condInput=condInput, outParamDesc=self.output, inpParamArray=inpParamArray) request = iRODSMessage("RODS_API_REQ", msg=message_body, int_info=api_number['EXEC_MY_RULE_AN']) with self.session.pool.get_connection() as conn: conn.send(request) response = conn.recv(acceptable_errors=acceptable_errors, return_message=return_message) try: out_param_array = response.get_main_message( MsParamArray, r_error=r_error) except iRODSMessage.ResponseNotParseable: return MsParamArray( ) # Ergo, no useful return value - but the RError stack will be accessible finally: if session_cleanup: self.session.cleanup() return out_param_array
def move(self, src_path, dest_path): # check if dest is an existing collection # if so append collection name to it if self.sess.collections.exists(dest_path): coll_name = src_path.rsplit('/', 1)[1] target_path = dest_path + '/' + coll_name else: target_path = dest_path src = FileOpenRequest( objPath=src_path, createMode=0, openFlags=0, offset=0, dataSize=0, numThreads=0, oprType=12, # RENAME_COLL KeyValPair_PI=StringStringMap(), ) dest = FileOpenRequest( objPath=target_path, createMode=0, openFlags=0, offset=0, dataSize=0, numThreads=0, oprType=12, # RENAME_COLL KeyValPair_PI=StringStringMap(), ) message_body = ObjCopyRequest(srcDataObjInp_PI=src, destDataObjInp_PI=dest) message = iRODSMessage('RODS_API_REQ', msg=message_body, int_info=api_number['DATA_OBJ_RENAME_AN']) with self.sess.pool.get_connection() as conn: conn.send(message) response = conn.recv()
def close_file(self, desc): message_body = OpenedDataObjRequest(l1descInx=desc, len=0, whence=0, oprType=0, offset=0, bytesWritten=0, KeyValPair_PI=StringStringMap()) message = iRODSMessage('RODS_API_REQ', msg=message_body, int_info=api_number['DATA_OBJ_CLOSE_AN']) self.send(message) response = self.recv()
def remove(self, path, recurse=True, force=False, additional_flags={}): options = {} if recurse: options['recursiveOpr'] = '' if force: options['forceFlag'] = '' options = dict(options.items() + additional_flags.items()) message_body = CollectionRequest( collName=path, KeyValPair_PI=StringStringMap(options)) message = iRODSMessage('RODS_API_REQ', msg=message_body, int_info=api_number['RM_COLL_OLD201_AN']) with self.sess.pool.get_connection() as conn: conn.send(message) response = conn.recv()
def write_file(self, desc, string): message_body = OpenedDataObjRequest(l1descInx=desc, len=len(string), whence=0, oprType=0, offset=0, bytesWritten=0, KeyValPair_PI=StringStringMap()) message = iRODSMessage('RODS_API_REQ', msg=message_body, bs=string, int_info=api_number['DATA_OBJ_WRITE_AN']) self.send(message) response = self.recv() return response.int_info
def open(self, path, mode, create=True, finalize_on_close=True, **options): _raw_fd_holder = options.get('_raw_fd_holder', []) if kw.DEST_RESC_NAME_KW not in options: # Use client-side default resource if available try: options[kw.DEST_RESC_NAME_KW] = self.sess.default_resource except AttributeError: pass createFlag = self.O_CREAT if create else 0 flags, seek_to_end = { 'r': (self.O_RDONLY, False), 'r+': (self.O_RDWR, False), 'w': (self.O_WRONLY | createFlag | self.O_TRUNC, False), 'w+': (self.O_RDWR | createFlag | self.O_TRUNC, False), 'a': (self.O_WRONLY | createFlag, True), 'a+': (self.O_RDWR | createFlag, True), }[mode] # TODO: Use seek_to_end try: oprType = options[kw.OPR_TYPE_KW] except KeyError: oprType = 0 message_body = FileOpenRequest( objPath=path, createMode=0, openFlags=flags, offset=0, dataSize=-1, numThreads=self.sess.numThreads, oprType=oprType, KeyValPair_PI=StringStringMap(options), ) message = iRODSMessage('RODS_API_REQ', msg=message_body, int_info=api_number['DATA_OBJ_OPEN_AN']) conn = self.sess.pool.get_connection() conn.send(message) desc = conn.recv().int_info raw = iRODSDataObjectFileRaw(conn, desc, finalize_on_close=finalize_on_close, **options) (_raw_fd_holder).append(raw) return io.BufferedRandom(raw)
def seek_file(self, desc, offset, whence): message_body = OpenedDataObjRequest(l1descInx=desc, len=0, whence=whence, oprType=0, offset=offset, bytesWritten=0, KeyValPair_PI=StringStringMap()) message = iRODSMessage('RODS_API_REQ', msg=message_body, int_info=api_number['DATA_OBJ_LSEEK_AN']) self.send(message) response = self.recv() offset = response.get_main_message(FileSeekResponse).offset return offset
def read_file(self, desc, size): message_body = OpenedDataObjRequest(l1descInx=desc, len=size, whence=0, oprType=0, offset=0, bytesWritten=0, KeyValPair_PI=StringStringMap()) message = iRODSMessage('RODS_API_REQ', msg=message_body, int_info=api_number['DATA_OBJ_READ_AN']) logger.debug(desc) self.send(message) response = self.recv() return response.bs
def truncate(self, path, size, **options): message_body = FileOpenRequest( objPath=path, createMode=0, openFlags=0, offset=0, dataSize=size, numThreads=self.sess.numThreads, oprType=0, KeyValPair_PI=StringStringMap(options), ) message = iRODSMessage('RODS_API_REQ', msg=message_body, int_info=api_number['DATA_OBJ_TRUNCATE_AN']) with self.sess.pool.get_connection() as conn: conn.send(message) response = conn.recv()
def unlink(self, path): message_body = FileOpenRequest( objPath=path, createMode=0, openFlags=0, offset=0, dataSize=-1, numThreads=0, oprType=0, KeyValPair_PI=StringStringMap(), ) message = iRODSMessage('RODS_API_REQ', msg=message_body, int_info=api_number['DATA_OBJ_UNLINK_AN']) with self.sess.pool.get_connection() as conn: conn.send(message) response = conn.recv()
def register(self, file_path, obj_path, **options): options[kw.FILE_PATH_KW] = file_path message_body = FileOpenRequest( objPath=obj_path, createMode=0, openFlags=0, offset=0, dataSize=0, numThreads=self.sess.numThreads, oprType=0, KeyValPair_PI=StringStringMap(options), ) message = iRODSMessage('RODS_API_REQ', msg=message_body, int_info=api_number['PHY_PATH_REG_AN']) with self.sess.pool.get_connection() as conn: conn.send(message) response = conn.recv()
def open(self, path, mode): message_body = FileOpenRequest( objPath=path, createMode=0, openFlags=mode, offset=0, dataSize=-1, numThreads=0, oprType=0, KeyValPair_PI=StringStringMap(), ) message = iRODSMessage('RODS_API_REQ', msg=message_body, int_info=api_number['DATA_OBJ_OPEN_AN']) conn = self.sess.pool.get_connection() conn.send(message) response = conn.recv() return (conn, response.int_info)
def replicate(self, path, options=None): if options is None: options = {} message_body = FileOpenRequest( objPath=path, createMode=0, openFlags=0, offset=0, dataSize=-1, numThreads=0, oprType=6, KeyValPair_PI=StringStringMap(options), ) message = iRODSMessage('RODS_API_REQ', msg=message_body, int_info=api_number['DATA_OBJ_REPL_AN']) with self.sess.pool.get_connection() as conn: conn.send(message) response = conn.recv()
def open(self, path, mode, options=None): if options is None: options = {} flags, seek_to_end = { 'r': (O_RDONLY, False), 'r+': (O_RDWR, False), 'w': (O_WRONLY | O_CREAT, False), 'w+': (O_RDWR | O_CREAT, False), 'a': (O_WRONLY | O_CREAT, True), 'a+': (O_RDWR | O_CREAT, True), }[mode] # TODO: Use seek_to_end try: oprType = options[kw.OPR_TYPE_KW] except KeyError: oprType = 0 # sanitize options before packing options = {str(key): str(value) for key, value in options.items()} message_body = FileOpenRequest( objPath=path, createMode=0, openFlags=flags, offset=0, dataSize=-1, numThreads=self.sess.numThreads, oprType=oprType, KeyValPair_PI=StringStringMap(options), ) message = iRODSMessage('RODS_API_REQ', msg=message_body, int_info=api_number['DATA_OBJ_OPEN_AN']) conn = self.sess.pool.get_connection() conn.send(message) desc = conn.recv().int_info return BufferedRandom(iRODSDataObjectFileRaw(conn, desc, options))
def remove(self, path, recurse=True, force=False, additional_flags=None): if additional_flags is None: additional_flags = {} options = {} if recurse: options['recursiveOpr'] = '' if force: options['forceFlag'] = '' options = dict(options.items() + additional_flags.items()) message_body = CollectionRequest( collName=path, KeyValPair_PI=StringStringMap(options)) message = iRODSMessage('RODS_API_REQ', msg=message_body, int_info=api_number['RM_COLL_AN']) with self.sess.pool.get_connection() as conn: conn.send(message) response = conn.recv() while response.int_info == SYS_SVR_TO_CLI_COLL_STAT: conn.reply(SYS_CLI_TO_SVR_COLL_STAT_REPLY) response = conn.recv()