Module: Pwrake::GfarmPath
- Defined in:
- lib/pwrake/gfarm/gfarm_path.rb
Constant Summary collapse
- @@local_mountpoint =
mountpoint_of_cwd
- @@fs_subdir =
Pathname.new('/')
Class Method Summary collapse
- .from_fs(x) ⇒ Object
- .from_local(x) ⇒ Object
- .fs_to_local(x) ⇒ Object
- .gfarm2fs?(d = nil) ⇒ Boolean
- .gfpath(file = '.') ⇒ Object
- .local_to_fs(x) ⇒ Object
- .mountpoint ⇒ Object
- .mountpoint=(d) ⇒ Object
- .mountpoint_of_cwd ⇒ Object
- .pwd ⇒ Object
- .subdir ⇒ Object
- .subdir=(d) ⇒ Object
- .to_fs(x) ⇒ Object
- .to_local(x) ⇒ Object
Class Method Details
.from_fs(x) ⇒ Object
66 67 68 |
# File 'lib/pwrake/gfarm/gfarm_path.rb', line 66 def from_fs(x) Pathname(x).relative_path_from(@@fs_subdir) end |
.from_local(x) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/pwrake/gfarm/gfarm_path.rb', line 57 def from_local(x) pn = Pathname(x) if pn.absolute? pn.relative_path_from(@@local_mountpoint) else Pathname.pwd.relative_path_from(@@local_mountpoint) + pn end end |
.fs_to_local(x) ⇒ Object
84 85 86 87 88 |
# File 'lib/pwrake/gfarm/gfarm_path.rb', line 84 def fs_to_local(x) x = from_fs(x) x = to_local(x) x.to_s end |
.gfarm2fs?(d = nil) ⇒ Boolean
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/pwrake/gfarm/gfarm_path.rb', line 43 def gfarm2fs?(d=nil) d ||= @@local_mountpoint mount_type = nil open('/etc/mtab','r') do |f| f.each_line do |l| if /#{d} (?:type )?(\S+)/o =~ l mount_type = $1 break end end end /gfarm2fs/ =~ mount_type end |
.gfpath(file = '.') ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/pwrake/gfarm/gfarm_path.rb', line 90 def gfpath(file='.') begin IO.popen("gfstat '#{file}'") do |f| if /File: "([^"]+)"/ =~ f.gets #" return $1 end end rescue end nil end |
.local_to_fs(x) ⇒ Object
78 79 80 81 82 |
# File 'lib/pwrake/gfarm/gfarm_path.rb', line 78 def local_to_fs(x) x = from_local(x) x = to_fs(x) x.to_s end |
.mountpoint ⇒ Object
22 23 24 |
# File 'lib/pwrake/gfarm/gfarm_path.rb', line 22 def mountpoint @@local_mountpoint end |
.mountpoint=(d) ⇒ Object
18 19 20 |
# File 'lib/pwrake/gfarm/gfarm_path.rb', line 18 def mountpoint=(d) @@local_mountpoint = Pathname.new(d) end |
.mountpoint_of_cwd ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/pwrake/gfarm/gfarm_path.rb', line 7 def mountpoint_of_cwd path = Pathname.pwd while !path.mountpoint? path = path.parent end path end |
.pwd ⇒ Object
39 40 41 |
# File 'lib/pwrake/gfarm/gfarm_path.rb', line 39 def pwd Pathname.pwd.relative_path_from(@@local_mountpoint) end |
.subdir ⇒ Object
35 36 37 |
# File 'lib/pwrake/gfarm/gfarm_path.rb', line 35 def subdir @@fs_subdir.to_s end |
.subdir=(d) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/pwrake/gfarm/gfarm_path.rb', line 26 def subdir=(d) if d @@fs_subdir = Pathname.new(d) if @@fs_subdir.relative? @@fs_subdir = Pathname.new('/') + @@fs_subdir end end end |
.to_fs(x) ⇒ Object
70 71 72 |
# File 'lib/pwrake/gfarm/gfarm_path.rb', line 70 def to_fs(x) @@fs_subdir + Pathname(x) end |
.to_local(x) ⇒ Object
74 75 76 |
# File 'lib/pwrake/gfarm/gfarm_path.rb', line 74 def to_local(x) @@local_mountpoint + Pathname(x) end |