Module: Nodesets

Defined in:
lib/nodesets.rb,
lib/nodesets/nodeset.rb,
lib/nodesets/version.rb,
lib/nodesets/human_sortable_array.rb

Defined Under Namespace

Classes: HumanSortableArray, Nodeset

Constant Summary collapse

SEPARATORS =
{
  '\n' => "\n",
  '\r' => "\r",
  '\t' => "\t",
  '\0' => "\0",
}
Nodeset_split =
/,(?=(?:[^\]]*\[[^\[]*\])*[^\]]*\z)/.freeze
Nodeset_single_split =
/\[(.+?)\]$/.freeze
SCONTROL_ALLOCGPU_REGEX =
/NodeName=(?<nodename>\S+)(?:.*)AllocTRES=\S+?gpu=(?<gpucount>\S+)/.freeze
VERSION =
"0.0.4"

Class Method Summary collapse

Class Method Details

.make_nodeset(node_arr) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/nodesets.rb', line 50

def make_nodeset(node_arr)
  # For speed, and because we only currently support a single prefix in a nodeset
  # we will assume that the first items prefix is the same as all the rest
  node_arr = node_arr.to_a
  node_prefix = node_arr[0].partition(/^([-_A-Za-z]+)/)[1]
  node_prefix_length = node_prefix.length
  num_w_ranges = node_arr.map do |x|
    x[node_prefix_length..-1].to_i
  end
  ## Old, less efficient method
  #node_prefix = ''
  #num_w_ranges = node_arr.map do |x|
  #  name_split = x.partition(/^([-_A-Za-z]+)/)
  #  node_prefix = name_split[1] if node_prefix.empty?
  #  name_split.last
  #end
  num_w_ranges = Nodesets::HumanSortableArray.new(num_w_ranges.sort).to_ranges.map do |x|
    ## Old, less efficient method
    #x.to_s.sub('..','-')
    begin
      y = x.to_s
      y[/\.\./] = '-'
      y
    rescue IndexError
      x
    end
  end.join(',')
  node_arr.length > 1 ? "#{node_prefix}[#{num_w_ranges}]" : "#{node_prefix}#{num_w_ranges}"
end

.parse_nodeset(nodeset) ⇒ Object

require “#__FILE__)/nodeset”



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/nodesets.rb', line 20

def parse_nodeset(nodeset)
  nodeset = nodeset.split(Nodeset_split).map do |set|
    set.strip!
    match = /(\d.*)/.match(set) if not set.include?('[')
    set = "#{match.pre_match}[#{match[0]}]" if match
    prefix, digits = set.split(Nodeset_single_split)
    post_digits = digits.split(',').map do |x|
      if x.include?('-')
        first, _, last = x.partition('-')
        (first.to_i..last.to_i).to_a.map do |y|
          name =  "#{prefix}#{y}"
          name = yield name if block_given?
          name
        end
      else
        name = "#{prefix}#{x}"
        name = yield name if block_given?
        name
      end
    end.flatten
  end.flatten.uniq
  ## FIXME: Probably not the parsers job to do the sorting, removed it for now
  ##   expensive call and breaks test predictability
  #Nodesets::HumanSortableArray.new(nodeset).human_sort
end

.parse_nodeset_arr(nodeset_arr) ⇒ Object

FIXME: Probably not the parsers job to do the sorting, removed it for now

expensive call and breaks test predictability

Nodesets::HumanSortableArray.new(nodeset).human_sort



45
46
47
48
49
# File 'lib/nodesets.rb', line 45

def parse_nodeset_arr(nodeset_arr)
  nodeset_arr.each_with_object([]) do |nodeset, node_arr|
    node_arr.concat(parse_nodeset(nodeset))
  end
end