def get(self, path): query = self.sess.query(Collection).filter(Collection.name == path) try: result = query.one() except NoResultFound: raise CollectionDoesNotExist() return iRODSCollection(self, result)
def test_set_inherit_acl_depth_test(self): DEPTH = 3 # But test is valid for any DEPTH > 1 for recursionTruth in (True, False): deepcoll = None try: test_coll_path = self.coll_path + "/test" deepcoll = helpers.make_deep_collection(self.sess, test_coll_path, depth=DEPTH, objects_per_level=2) acl1 = iRODSAccess('inherit', deepcoll.path) self.sess.permissions.set(acl1, recursive=recursionTruth) test_subcolls = set( iRODSCollection(self.sess.collections, _) for _ in self.sess.query(Collection).filter( Like(Collection.name, deepcoll.path + "/%"))) # assert top level collection affected test_coll = self.sess.collections.get(test_coll_path) self.assertTrue(test_coll.inheritance) # # assert lower level collections affected only for case when recursive = True subcoll_truths = [(_.inheritance == recursionTruth) for _ in test_subcolls] self.assertEqual(len(subcoll_truths), DEPTH - 1) self.assertTrue(all(subcoll_truths)) finally: if deepcoll: deepcoll.remove(force=True, recurse=True)
def get(self, request): name = request.GET['name'] value = request.GET['value'] query_result = self.irods_session.query(Collection).filter( CollectionMeta.name == name, CollectionMeta.value == value).all() results = [iRODSCollection(CollectionManager, row) for row in query_result] return JsonResponse(map(format_subcoll, results), safe=False)
def push_file(from_path: str, to_prefix: str, session: iRODSSession): if isfile(to_prefix): print(f"File {to_prefix} already exists, skipping download") return else: print(f"Uploading file '{from_path}' to '{to_prefix}'") try: c_result = session.query(Collection).one() c = iRODSCollection(session.collections, c_result) session.data_objects.put(from_path, to_prefix) except CAT_SQL_ERR: return
def get(self, path): path = iRODSCollection.normalize_path(path) filters = [Collection.name == path] # if a ticket is supplied for this session, try both without and with DataObject join repeats = (True,False) if hasattr(self.sess,'ticket__') \ else (False,) for rep in repeats: query = self.sess.query(Collection).filter(*filters) try: result = query.one() except NoResultFound: if rep: filters += [DataObject.id != 0] continue raise CollectionDoesNotExist() return iRODSCollection(self, result)
def test_upload_directory(remote_base_path): with TemporaryDirectory() as testdir: file1_name = 'f1.txt' file2_name = 'f2.txt' file1_path = join(testdir, file1_name) file2_path = join(testdir, file2_name) coll_name = str(uuid.uuid4()) remote_path = join(remote_base_path, coll_name) try: # prep collection create_collection(remote_path, token) # create files with open(file1_path, "w") as file1, open(file2_path, "w") as file2: file1.write('Hello, 1!') file2.write('Hello, 2!') # create iRODS session and get ticket with iRODSSession(host='data.cyverse.org', port=1247, user='******', password='', zone='iplant') as session: ticket = TerrainTicket.get([ join(remote_path, file1_name), join(remote_path, file2_name) ], 'write', False) Ticket(session, ticket).supply() # upload files irods_store.push_dir(testdir, remote_path, session=session, include_patterns=['.txt']) # check uploads coll = session.query(Collection).one() collection = iRODSCollection(session.collections, coll) file_names = [o.name for o in collection.data_objects] print(file_names) assert file1_name in file_names assert file2_name in file_names finally: delete_collection(remote_path, token)
def test_create_other_zone_user_227_228(self): usercolls = [] session = self.sess A_ZONE_NAME = 'otherZone' A_ZONE_USER = '******' try: zoneB = session.zones.create(A_ZONE_NAME,'remote') zBuser = session.users.create(A_ZONE_USER,'rodsuser', A_ZONE_NAME, '') usercolls = [ iRODSCollection(session.collections, result) for result in session.query(Collection).filter(Collection.owner_name == zBuser.name and Collection.owner_zone == zBuser.zone) ] self.assertEqual ([(u[User.name],u[User.zone]) for u in session.query(User).filter(User.zone == A_ZONE_NAME)], [(A_ZONE_USER,A_ZONE_NAME)]) zBuser.remove() zoneB.remove() finally: for p in usercolls: try: session.collections.get( p.path ) except CollectionDoesNotExist: continue perm = iRODSAccess( 'own', p.path, session.username, session.zone) session.permissions.set( perm, admin=True) p.remove(force=True)