Module: Pwrake::GfarmPath

Defined in:
lib/pwrake/gfarm_feature.rb

Constant Summary collapse

@@local_mountpoint =
mountpoint_of_cwd
@@fs_subdir =
Pathname.new('/')

Class Method Summary collapse

Class Method Details

.from_fs(x) ⇒ Object



66
67
68
# File 'lib/pwrake/gfarm_feature.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_feature.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_feature.rb', line 84

def fs_to_local(x)
  x = from_fs(x)
  x = to_local(x)
  x.to_s
end

.gfarm2fs?(d = nil) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/pwrake/gfarm_feature.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_feature.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

.gfwhere(list) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/pwrake/gfarm_feature.rb', line 102

def gfwhere(list)
  system "sync"
  result = {}
  count = 0
  cmd = "gfwhere"
  parse_proc = proc{|x|
    if count==1
      result[cmd[8..-1]] = x.split
    else
      x.scan(/^(?:gfarm:\/\/[^\/]+)?([^\n]+):\n([^\n]*)$/m) do |file,hosts|
        h = hosts.split
        result[file] = h if !h.empty?
      end
    end
  }

  list.each do |a|
    if a
      path = local_to_fs(a)
      if cmd.size + path.size + 1 > 20480 # 131000
        x = `#{cmd} 2> /dev/null`
        parse_proc.call(x)
        cmd = "gfwhere"
        count = 0
      end
      cmd << " "
      cmd << path
      count += 1
    end
  end
  if count > 0
    x = `#{cmd} 2> /dev/null`
    parse_proc.call(x)
  end
  result
end

.local_to_fs(x) ⇒ Object



78
79
80
81
82
# File 'lib/pwrake/gfarm_feature.rb', line 78

def local_to_fs(x)
  x = from_local(x)
  x = to_fs(x)
  x.to_s
end

.mountpointObject



22
23
24
# File 'lib/pwrake/gfarm_feature.rb', line 22

def mountpoint
  @@local_mountpoint
end

.mountpoint=(d) ⇒ Object



18
19
20
# File 'lib/pwrake/gfarm_feature.rb', line 18

def mountpoint=(d)
  @@local_mountpoint = Pathname.new(d)
end

.mountpoint_of_cwdObject



7
8
9
10
11
12
13
# File 'lib/pwrake/gfarm_feature.rb', line 7

def mountpoint_of_cwd
  path = Pathname.pwd
  while !path.mountpoint?
    path = path.parent
  end
  path
end

.pwdObject



39
40
41
# File 'lib/pwrake/gfarm_feature.rb', line 39

def pwd
  Pathname.pwd.relative_path_from(@@local_mountpoint)
end

.subdirObject



35
36
37
# File 'lib/pwrake/gfarm_feature.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_feature.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_feature.rb', line 70

def to_fs(x)
  @@fs_subdir + Pathname(x)
end

.to_local(x) ⇒ Object



74
75
76
# File 'lib/pwrake/gfarm_feature.rb', line 74

def to_local(x)
  @@local_mountpoint + Pathname(x)
end