Module: IRODS4r::ICommands
- Defined in:
- lib/irods4r/icommands.rb
Overview
This module interfaces directly with the IRODS system
Defined Under Namespace
Classes: ICommandException
Class Method Summary collapse
- .exist?(path, ticket = nil) ⇒ Boolean
-
.export(path, file_path, create_parent_path = true, ticket = nil) ⇒ Object
Copy the resource at ‘path’ in iRODS to ‘file_path’ in the local file system.
-
.ls(path, ticket = nil) ⇒ Object
Return the list of files found at ‘path’.
- .mkpath(dirname) ⇒ Object
-
.read(path, ticket = nil) ⇒ Object
Return content of resource at ‘path’.
-
.write(path, content, ticket = nil) ⇒ Object
Return content of resource at ‘path’.
Class Method Details
.exist?(path, ticket = nil) ⇒ Boolean
49 50 51 52 |
# File 'lib/irods4r/icommands.rb', line 49 def self.exist?(path, ticket = nil) `ils #{"-t #{ticket}" if ticket} #{path}` $?.exitstatus == 0 end |
.export(path, file_path, create_parent_path = true, ticket = nil) ⇒ Object
Copy the resource at ‘path’ in iRODS to ‘file_path’ in the local file system.
57 58 59 60 61 62 63 64 65 |
# File 'lib/irods4r/icommands.rb', line 57 def self.export(path, file_path, create_parent_path = true, ticket = nil) #puts ">>>> #{path} -> #{file_path}" if create_parent_path require 'fileutils' FileUtils.mkpath ::File.dirname(file_path) end `iget -f #{"-t #{ticket}" if ticket} #{path} #{file_path}` raise ICommandException.new($?) unless $?.exitstatus == 0 end |
.ls(path, ticket = nil) ⇒ Object
Return the list of files found at ‘path’.
12 13 14 15 16 17 18 19 |
# File 'lib/irods4r/icommands.rb', line 12 def self.ls(path, ticket = nil) r = `ils #{"-t #{ticket}" if ticket} #{path}` #raise ICommandException.new($?) unless $?.exitstatus == 0 if r.empty? raise NotFoundException.new("Can't find resource '#{path}'") end r.lines end |
.mkpath(dirname) ⇒ Object
44 45 46 47 |
# File 'lib/irods4r/icommands.rb', line 44 def self.mkpath(dirname) cmd_out = `imkdir -p #{dirname} 2>&1` raise ICommandException.new(cmd_out) unless $?.exitstatus == 0 end |
.read(path, ticket = nil) ⇒ Object
Return content of resource at ‘path’
23 24 25 26 27 28 29 30 31 |
# File 'lib/irods4r/icommands.rb', line 23 def self.read(path, ticket = nil) f = Tempfile.new('irods4r') `iget -f #{"-t #{ticket}" if ticket} #{path} #{f.path}` raise ICommandException.new($?) unless $?.exitstatus == 0 content = f.read f.close f.unlink content end |
.write(path, content, ticket = nil) ⇒ Object
Return content of resource at ‘path’
35 36 37 38 39 40 41 42 |
# File 'lib/irods4r/icommands.rb', line 35 def self.write(path, content, ticket = nil) f = Tempfile.new('irods4r') f.write(content) f.close `iput -f #{"-t #{ticket}" if ticket} #{f.path} #{path}` raise ICommandException.new($?) unless $?.exitstatus == 0 f.unlink end |