Placing Files in iRODS using python irods client

189 views
Skip to first unread message

Katherine Beaulieu

unread,
May 27, 2016, 9:12:35 AM5/27/16
to iRODS-Chat
Hi everyone,
I am working on placing a file in the iRODS file system using a python script. I just want to place it in the users main collection but am not sure how to go about it following the user guide found here: https://github.com/irods/python-irodsclient.
Here is the script I have so far:
import sys
from irods.session import iRODSSession
sess = iRODSSesssion(host='localhost',port=1247,user='rods',password=XXXXXXXX, zone='tempZone')

with open(sys.argv[1], 'r') as fileToPlace:
     print fileToPlace.read()
     obj = sess.data_objects.create("tempZone/home/rods/" + fileToPlace)

This doesn't work as you can't concatenate a string a file but I don't know how else you would put an already existing file into irods using this API.
Thanks in advance!

de Torcy, Antoine

unread,
May 27, 2016, 11:05:13 AM5/27/16
to iRODS-Chat

Hi,


You will have to read your local file's content and write it to a new irods object, e.g:


obj = session.data_objects.create(obj_path)
with obj.open('w') as obj_desc:
    obj_desc.write(content)

# refresh object after write
return session.data_objects.get(obj_path) 


You might also want to take a look at the test code in https://github.com/irods/python-irodsclient/tree/master/irods/test for further examples.


AdT




From: irod...@googlegroups.com <irod...@googlegroups.com> on behalf of Katherine Beaulieu <katherine....@gmail.com>
Sent: Friday, May 27, 2016 9:12 AM
To: iRODS-Chat
Subject: [iROD-Chat:15147] Placing Files in iRODS using python irods client
 
--
--
"iRODS: the Integrated Rule-Oriented Data-management System; A community driven, open source, data grid software solution" https://www.irods.org
 
iROD-Chat: http://groups.google.com/group/iROD-Chat

---
You received this message because you are subscribed to the Google Groups "iRODS-Chat" group.
To unsubscribe from this group and stop receiving emails from it, send an email to irod-chat+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sune Andersen

unread,
May 30, 2016, 4:14:28 AM5/30/16
to iRODS-Chat
Hi !
Have look at my Python script at GitHub : https://github.com/sunadtudk/irods_2_figshare

Just a note : you can use the iCommand to upload/download files - info : https://docs.irods.org/master/icommands/user/
And just do the Python-call:

import os
cmd = 'bin/bar --option'
os.system(cmd) # returns the exit status

-Sune , Denmark
Reply all
Reply to author
Forward
0 new messages