module Nodesets

Constants

Nodeset_single_split
Nodeset_split
SCONTROL_ALLOCGPU_REGEX
SEPARATORS
VERSION

Public Class Methods

make_nodeset(node_arr) click to toggle source
# 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) { |name| ... } click to toggle source

require “#{File.expand_path('../nodeset_gem', __FILE__)}/human_sortable_array” require “#{File.expand_path('../nodeset_gem', __FILE__)}/nodeset”

# 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) click to toggle source
# 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