Project

General

Profile

pandora.rb

Ruby script used by "AllTheWayThrough" - Randolph Herber, 08/18/2011 02:42 PM

 
1
module Pandora
2

    
3
  # :stopdoc:
4
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
5
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
6
  # :startdoc:
7

    
8
  # Returns the version string for the library.
9
  #
10
  def self.version
11
    @version ||= File.read(path('version.txt')).strip
12
  end
13

    
14
  # Returns the library path for the module. If any arguments are given,
15
  # they will be joined to the end of the libray path using
16
  # <tt>File.join</tt>.
17
  #
18
  def self.libpath( *args, &block )
19
    rv =  args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten)
20
    if block
21
      begin
22
        $LOAD_PATH.unshift LIBPATH
23
        rv = block.call
24
      ensure
25
        $LOAD_PATH.shift
26
      end
27
    end
28
    return rv
29
  end
30

    
31
  # Returns the lpath for the module. If any arguments are given,
32
  # they will be joined to the end of the path using
33
  # <tt>File.join</tt>.
34
  #
35
  def self.path( *args, &block )
36
    rv = args.empty? ? PATH : ::File.join(PATH, args.flatten)
37
    if block
38
      begin
39
        $LOAD_PATH.unshift PATH
40
        rv = block.call
41
      ensure
42
        $LOAD_PATH.shift
43
      end
44
    end
45
    return rv
46
  end
47

    
48
  # Utility method used to require all files ending in .rb that lie in the
49
  # directory below this file that has the same name as the filename passed
50
  # in. Optionally, a specific _directory_ name can be passed in such that
51
  # the _filename_ does not have to be equivalent to the directory.
52
  #
53
  def self.require_all_libs_relative_to( fname, dir = nil )
54
    dir ||= ::File.basename(fname, '.*')
55
    search_me = ::File.expand_path(
56
        ::File.join(::File.dirname(fname), dir, '**', '*.rb'))
57

    
58
    Dir.glob(search_me).sort.each {|rb| require rb}
59
  end
60

    
61
end  # module Pandora
62

    
63
Pandora.require_all_libs_relative_to(__FILE__)
64

    
65
def isNumeric(string)
66
  begin
67
    Kernel.Float(string)
68
  rescue
69
    return false
70
  end
71
  return true
72
end
73
def enquote(value)
74
  if value.nil? then "" else '"'+value.to_s.gsub(/["\\]/,'\\\\\&')+'"' end
75
end
76
def Enquote(value)
77
  isNumeric(value) ? value : enquote(value)
78
end
79
def ol(data,tag,start)
80
  return_value = ""
81
  for value in data
82
    return_value << tag << start.to_s << " " << Enquote(value) << "\n"
83
    start += 1
84
  end
85
  return_value
86
end
87
def generate_PBS
88
  return_value = ""
89
  if @pbs
90
    if @pbs.has_key?("after")
91
      return_value << "#PBS -a " << @pbs["after"].to_s << "\n"
92
    end
93
    if @pbs.has_key?("account")
94
      return_value << "#PBS -A " << @pbs["account"].to_s << "\n"
95
    end
96
    if @pbs.has_key?("wait_for_server")
97
      return_value << "#PBS -b " << @pbs["wait_for_server"].to_s << "\n"
98
    end
99
    if @pbs.has_key?("checkpoint")
100
      return_value << "#PBS -c " << @pbs["checkpoint"].to_s << "\n"
101
    end
102
    if @pbs.has_key?("directive_prefix")
103
      return_value << "#PBS -C " << @pbs["directive_prefix"].to_s << "\n"
104
    end
105
    if @pbs.has_key?("working_directory")
106
      return_value << "#PBS -d " << @pbs["working_directory"].to_s << "\n"
107
    end
108
    if @pbs.has_key?("root_directory")
109
      return_value << "#PBS -D " << @pbs["root_directory"].to_s << "\n"
110
    end
111
    if @pbs.has_key?("error_stream")
112
      return_value << "#PBS -e " << @pbs["error_stream"].to_s << "\n"
113
    end
114
    if @pbs.has_key?("hold")
115
      return_value << "#PBS -h\n"
116
    end
117
    if @pbs.has_key?("join")
118
      return_value << "#PBS -j " << @pbs["join"].to_s << "\n"
119
    end
120
    if @pbs.has_key?("keep")
121
      return_value << "#PBS -k " << @pbs["keep"].to_s << "\n"
122
    end
123
    if @pbs.has_key?("mail")
124
      return_value << "#PBS -m " << @pbs["mail"].to_s << "\n"
125
    end
126
    if @pbs.has_key?("mail_to")
127
      return_value << "#PBS -M " << @pbs["mail_to"].to_s << "\n"
128
    end
129
    if @pbs.has_key?("jobname")
130
      return_value << "#PBS -N " << @pbs["jobname"].to_s << "\n"
131
    end
132
    if @pbs.has_key?("output")
133
      return_value << "#PBS -o " << @pbs["output"].to_s << "\n"
134
    end
135
    if @pbs.has_key?("priority ")
136
      return_value << "#PBS -p " << @pbs["priority"].to_s << "\n"
137
    end
138
    if @pbs.has_key?("destination")
139
      return_value << "#PBS -q " << @pbs["destination"].to_s << "\n"
140
    end
141
    if @pbs.has_key?("rerunable")
142
      return_value << "#PBS -r " << @pbs["rerunable"].to_s << "\n"
143
    end
144
    if @pbs.has_key?("shell")
145
      return_value << "#PBS -S " << @pbs["shell"].to_s << "\n"
146
    end
147
    if @pbs.has_key?("job_array")
148
      return_value << "#PBS -t " << @pbs["job_array"].to_s << "\n"
149
    end
150
    if @pbs.has_key?("wrapper_name")
151
      return_value << "#PBS -T " << @pbs["wrapper_name"].to_s << "\n"
152
    end
153
    if @pbs.has_key?("user_list")
154
      return_value << "#PBS -u " << @pbs["user_list"].to_s << "\n"
155
    end
156
    if @pbs.has_key?("export_list")
157
      return_value << "#PBS -v " << @pbs["export_list"].to_s << "\n"
158
    end
159
    if @pbs.has_key?("export_all")
160
      return_value << "#PBS -v\n"
161
    end
162
    if @pbs.has_key?("X11_forwarding")
163
      return_value << "#PBS -X\n"
164
    end
165
    if @pbs.has_key?("silent")
166
      return_value << "#PBS -z\n"
167
    end
168
    if  @pbs.has_key?("resources")
169
      @pbs["resources"].each{|key,value|
170
        return_value << "#PBS -l " << key.to_s << "=" << Enquote(value) << "\n"
171
      }
172
    end
173
  end
174
  return_value
175
end