tools/cpee in cpee-2.1.39 vs tools/cpee in cpee-2.1.41
- old
+ new
@@ -7,11 +7,11 @@
require 'typhoeus'
require 'xml/smart'
require 'zip'
require 'pp'
-def wrap(s, width=78, indent=18)
+def wrap(s, width=78, indent=23)
lines = []
line, s = s[0..indent-2], s[indent..-1]
s.split(/\n/).each do |ss|
ss.split(/[ \t]+/).each do |word|
if line.size + word.size >= width
@@ -27,36 +27,38 @@
return lines.join "\n"
end
ARGV.options { |opt|
opt.summary_indent = ' ' * 2
- opt.summary_width = 15
- opt.banner = "Usage:\n#{opt.summary_indent}#{File.basename($0)} [options] convert | ui | cpui DIR | new DIR | archive DIR URL | start URL | delete! URL | abandon URL\n"
+ opt.summary_width = 20
+ opt.banner = "Usage:\n#{opt.summary_indent}#{File.basename($0)} [options] convert | ui | cpui DIR | new DIR | archive DIR URL | start URL | delete! URL | abandon URL | a_by_name URL STRING\n"
opt.on("Options:")
opt.on("--help", "-h", "This text") { puts opt; exit }
opt.on("")
- opt.on(wrap("[archive DIR URL] save properties from all finished instances listed at URL into DIR. Examples:\ncpee archive ./archive http://localhost:9298/1/\ncpee archive ./archive http://localhost:9298/1-200\ncpee archive ./archive http://localhost:9298/*"))
+ opt.on(wrap("[archive DIR URL] save properties from all finished instances listed at URL into DIR. Examples:\ncpee archive ./archive http://localhost:9298/1/\ncpee archive ./archive http://localhost:9298/1-200\ncpee archive ./archive http://localhost:9298/*"))
opt.on("")
- opt.on(wrap("[abandon URL] running processes are stopped; ready or stopped processes are abandoned. Examples:\ncpee abandon http://localhost:9298/1/\ncpee abandon http://localhost:9298/1-200\ncpee abandon http://localhost:9298/*"))
+ opt.on(wrap("[abandon URL] running processes are stopped; ready or stopped processes are abandoned. Examples:\ncpee abandon http://localhost:9298/1/\ncpee abandon http://localhost:9298/1-200\ncpee abandon http://localhost:9298/*"))
opt.on("")
- opt.on(wrap("[start URL] stopped processes are started; all others are not touched. Examples:\ncpee start http://localhost:9298/1\ncpee start http://localhost:9298/1-200\ncpee start http://localhost:9298/*"))
+ opt.on(wrap("[a_by_name URL STRING] ready or stopped processes are abandoned by regex on attributes/info. Examples:\ncpee abandon http://localhost:9298/1/ \"aa.a\"\ncpee abandon http://localhost:9298/1-200 aaa"))
opt.on("")
- opt.on(wrap("[delete! URL] DANGER ZONE. Vanishes forever. Not in archive. Examples:\ncpee delete! http://localhost:9298/1/"))
+ opt.on(wrap("[start URL] stopped processes are started; all others are not touched. Examples:\ncpee start http://localhost:9298/1\ncpee start http://localhost:9298/1-200\ncpee start http://localhost:9298/*"))
opt.on("")
- opt.on(wrap("[new DIR] scaffolds a sample execution engine. Everything except instances can be removed for default behaviour."))
+ opt.on(wrap("[delete! URL] DANGER ZONE. Vanishes forever. Not in archive. Examples:\ncpee delete! http://localhost:9298/1/"))
opt.on("")
- opt.on(wrap("[cpui DIR] scaffolds a sample html client. New versions might require manual merging if you changed something."))
+ opt.on(wrap("[new DIR] scaffolds a sample execution engine. Everything except instances can be removed for default behaviour."))
opt.on("")
- opt.on(wrap("[ui] starts a simple static web server with the ui on http://localhost:8080. Use [cpui DIR] if you want stuff in apache or nginx."))
+ opt.on(wrap("[cpui DIR] scaffolds a sample html client. New versions might require manual merging if you changed something."))
opt.on("")
- opt.on(wrap("[convert] converts all testsets in the current directory to cpee2"))
+ opt.on(wrap("[ui] starts a simple static web server with the ui on http://localhost:8080. Use [cpui DIR] if you want stuff in apache or nginx."))
+ opt.on("")
+ opt.on(wrap("[convert] converts all testsets in the current directory to the newest format"))
opt.parse!
}
if (ARGV.length == 0) ||
(ARGV.length == 1 && !(%w(ui convert).include?(ARGV[0]))) ||
(ARGV.length == 2 && !(%w(abandon start delete! cpui new).include?(ARGV[0]))) ||
- (ARGV.length == 3 && ARGV[0] != 'archive') ||
+ (ARGV.length == 3 && !(%w(archive a_by_name).include?(ARGV[0]))) ||
(ARGV.length > 3)
puts ARGV.options
exit
end
command = ARGV[0]
@@ -203,9 +205,47 @@
File.write(File.join(p1,uuid + '.xml'),prop.response_body) if prop.headers['Content-Type'] =~ /^(text|application)\/xml/
Typhoeus.delete(File.join(base,name.to_s,'/'))
end
end
end
+ end
+ end
+ end
+ end
+ puts
+elsif command == 'a_by_name'
+ p1 = File.join(p1,'*') if p1 =~ /([a-zA-Z]|\/)$/
+ base = File.dirname(p1)
+ names = []
+ if File.basename(p1) =~ /(\d+)-(\d+)/
+ names = ($1.to_i..$2.to_i).to_a
+ elsif File.basename(p1) == '*'
+ res = Typhoeus.get(File.join(base,'/'), headers: { 'see-instances' => 'true' })
+ if res.success?
+ XML::Smart.string(res.response_body) do |doc|
+ doc.find('//instance/@id').each do |ele|
+ names << ele.value
+ end
+ end
+ names.reverse!
+ else
+ exit
+ end
+ else
+ names << File.basename(p1)
+ end
+ names.each do |name|
+ print "Working on: " + name.to_s + "\r"
+ res1 = Typhoeus.get(File.join(base,name.to_s,'properties','state','/'))
+ res2 = Typhoeus.get(File.join(base,name.to_s,'properties','attributes','info','/'))
+ if res1.success?
+ if res1.response_body == 'stopping'
+ if res2.success? && res2.response_body =~ /#{p2}/
+ Typhoeus.put(File.join(base,name.to_s,'properties','state','/'), headers: {'Content-Type' => 'application/x-www-form-urlencoded'}, body: "value=stopping")
+ end
+ elsif res1.response_body == 'ready' || res1.response_body == 'stopped'
+ if res2.success? && res2.response_body =~ /#{p2}/
+ Typhoeus.put(File.join(base,name.to_s,'properties','state','/'), headers: {'Content-Type' => 'application/x-www-form-urlencoded'}, body: "value=abandoned")
end
end
end
end
puts