-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
88 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,70 @@ | ||
=begin | ||
-------------------------------------------------------------------------------- | ||
Create a sub-list sample from a session list file. | ||
You provide the session list file, and how many sessions you want to put into | ||
the sub-list, and the tool will extract that many session lines from the original | ||
list, evenly spaced, and put them into the new file. | ||
-------------------------------------------------------------------------------- | ||
vivosnap.rb prepare sub-list [session_list_file] [count] [sub_list_file] | ||
-------------------------------------------------------------------------------- | ||
=end | ||
|
||
class CmdPrepareSubList | ||
include ::ArgsChecker | ||
|
||
USAGE = "prepare sub-list [session_list_file] [count] {sub_list_file {REPLACE}}" | ||
def initialize(args) | ||
bogus "CmdPrepareSubList.initialize NOT IMPLEMENTED" | ||
@args = args | ||
@replace = args.delete('REPLACE') | ||
|
||
complain("usage: #{USAGE}") unless (2..3).include? args.size | ||
|
||
@session_list_file = confirm_file_exists(args[0]) | ||
@line_count = confirm_positive_integer(args[1]) | ||
@output = set_output_io(args[2], @replace) | ||
end | ||
|
||
def run() | ||
bogus "CmdPrepareSubList.run NOT IMPLEMENTED" | ||
read_lines_and_remove_comments | ||
complain("#{@session_list_file} only contains #{@lines.size} effective lines.") if @lines.size < @line_count | ||
|
||
write_heading() | ||
write_selected_lines() | ||
write_report() | ||
end | ||
|
||
def write_heading() | ||
@output.puts "#" | ||
@output.puts "# prepare sub-list #{@args.join(' ')}" | ||
@output.puts "# #{Time.now.strftime('%Y-%m-%d %H:%M:%S')}" | ||
@output.puts "#" | ||
end | ||
|
||
def read_lines_and_remove_comments() | ||
@lines = File.readlines(@session_list_file) | ||
@lines.reject! do |line| | ||
line.start_with?('#') || line.strip.empty? | ||
end | ||
end | ||
|
||
def write_selected_lines() | ||
interval = (@lines.size / @line_count).to_i | ||
(1..@line_count).each do |i| | ||
@output.puts @lines[(i - 1) * interval] | ||
end | ||
end | ||
|
||
def write_report() | ||
report = "#\n# Wrote #{@line_count} lines.\n#\n" | ||
|
||
@output.print(report) | ||
print(report) if @output != $stdout | ||
end | ||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters